Repository navigation
Expand file tree
/
Copy pathDante2.js
More file actions
2995 lines (2362 loc) · 88.3 KB
/
Copy pathDante2.js
File metadata and controls
2995 lines (2362 loc) · 88.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom"], factory);
else if(typeof exports === 'object')
exports["Dante2"] = factory(require("react"), require("react-dom"));
else
root["Dante2"] = factory(root["React"], root["ReactDOM"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_23__, __WEBPACK_EXTERNAL_MODULE_24__) {
return webpackJsonpDante2([0],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _dante = __webpack_require__(1);
var _dante2 = _interopRequireDefault(_dante);
var _dante_editor = __webpack_require__(26);
var _dante_editor2 = _interopRequireDefault(_dante_editor);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
module.exports = {
Dante: _dante2['default'],
DanteEditor: _dante_editor2['default']
};
/***/ },
/***/ 1:
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["Dante"] = __webpack_require__(2);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ },
/***/ 23:
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_23__;
/***/ },
/***/ 24:
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_24__;
/***/ },
/***/ 26:
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["DanteEditor"] = __webpack_require__(27);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ },
/***/ 396:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.addNewBlockAt = exports.updateTextOfBlock = exports.updateDataOfBlock = exports.resetBlockWithType = exports.addNewBlock = exports.getCurrentBlock = exports.getNode = exports.getDefaultBlockData = undefined;
var _immutable = __webpack_require__(25);
var _draftJs = __webpack_require__(94);
/*
Used from [react-rte](https://github.com/brijeshb42/medium-draft)
by [brijeshb42](https://github.com/brijeshb42/medium-draft)
*/
/*
Returns default block-level metadata for various block type. Empty object otherwise.
*/
var getDefaultBlockData = exports.getDefaultBlockData = function getDefaultBlockData(blockType) {
var initialData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
switch (blockType) {
//case Block.TODO: return { checked: false };
default:
return initialData;
}
};
var getNode = exports.getNode = function getNode() {
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
var t = null;
if (root.getSelection) {
t = root.getSelection();
} else if (root.document.getSelection) {
t = root.document.getSelection();
} else if (root.document.selection) {
t = root.document.selection.createRange().text;
}
return t;
};
/*
Get currentBlock in the editorState.
*/
var getCurrentBlock = exports.getCurrentBlock = function getCurrentBlock(editorState) {
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var block = contentState.getBlockForKey(selectionState.getStartKey());
return block;
};
/*
Adds a new block (currently replaces an empty block) at the current cursor position
of the given `newType`.
*/
var addNewBlock = exports.addNewBlock = function addNewBlock(editorState) {
var newType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unstyled";
var initialData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var selectionState = editorState.getSelection();
if (!selectionState.isCollapsed()) {
return editorState;
}
var contentState = editorState.getCurrentContent();
var key = selectionState.getStartKey();
var blockMap = contentState.getBlockMap();
var currentBlock = getCurrentBlock(editorState);
if (!currentBlock) {
return editorState;
}
if (currentBlock.getLength() === 0) {
if (currentBlock.getType() === newType) {
return editorState;
}
var newBlock = currentBlock.merge({
type: newType,
data: getDefaultBlockData(newType, initialData)
});
var newContentState = contentState.merge({
blockMap: blockMap.set(key, newBlock),
selectionAfter: selectionState
});
return _draftJs.EditorState.push(editorState, newContentState, 'change-block-type');
}
return editorState;
};
/*
Changes the block type of the current block.
*/
var resetBlockWithType = exports.resetBlockWithType = function resetBlockWithType(editorState) {
var newType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unstyled";
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
var key = selectionState.getStartKey();
var blockMap = contentState.getBlockMap();
var block = blockMap.get(key);
var newText = '';
console.log("DATA FOR PLACEHOLDER!", data);
var text = block.getText();
if (block.getLength() >= 2) {
newText = text.substr(1);
}
/*if(data.text){
newText = data.text
}*/
//let newText = data.text
var newBlock = block.merge({
text: newText,
type: newType,
data: getDefaultBlockData(newType, data)
});
var newContentState = contentState.merge({
blockMap: blockMap.set(key, newBlock),
selectionAfter: selectionState.merge({
anchorOffset: 0,
focusOffset: 0
})
});
return _draftJs.EditorState.push(editorState, newContentState, 'change-block-type');
};
/*
Update block-level metadata of the given `block` to the `newData`/
*/
var updateDataOfBlock = exports.updateDataOfBlock = function updateDataOfBlock(editorState, block, newData) {
var contentState = editorState.getCurrentContent();
var newBlock = block.merge({
data: newData
});
var newContentState = contentState.merge({
blockMap: contentState.getBlockMap().set(block.getKey(), newBlock)
});
return _draftJs.EditorState.push(editorState, newContentState, 'change-block-type');
// return editorState;
};
var updateTextOfBlock = exports.updateTextOfBlock = function updateTextOfBlock(editorState, block, text) {
var contentState = editorState.getCurrentContent();
var newBlock = block.merge({
text: text
});
var newContentState = contentState.merge({
blockMap: contentState.getBlockMap().set(block.getKey(), newBlock)
});
return _draftJs.EditorState.push(editorState, newContentState, 'change-block-type');
// return editorState;
};
// const BEFORE = -1;
// const AFTER = 1;
/*
Used from [react-rte](https://github.com/sstur/react-rte/blob/master/src/lib/insertBlockAfter.js)
by [sstur](https://github.com/sstur)
*/
var addNewBlockAt = exports.addNewBlockAt = function addNewBlockAt(editorState, pivotBlockKey) {
var newBlockType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unstyled";
var initialData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var content = editorState.getCurrentContent();
var blockMap = content.getBlockMap();
var block = blockMap.get(pivotBlockKey);
var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
return v === block;
});
var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
return v === block;
}).rest();
var newBlockKey = (0, _draftJs.genKey)();
var newBlock = new _draftJs.ContentBlock({
key: newBlockKey,
type: newBlockType,
text: '',
characterList: block.getCharacterList().slice(0, 0),
depth: 0,
data: (0, _immutable.Map)(getDefaultBlockData(newBlockType, initialData))
});
var newBlockMap = blocksBefore.concat([[pivotBlockKey, block], [newBlockKey, newBlock]], blocksAfter).toOrderedMap();
var selection = editorState.getSelection();
var newContent = content.merge({
blockMap: newBlockMap,
selectionBefore: selection,
selectionAfter: selection.merge({
anchorKey: newBlockKey,
anchorOffset: 0,
focusKey: newBlockKey,
focusOffset: 0,
isBackward: false
})
});
return _draftJs.EditorState.push(editorState, newContent, 'split-block');
};
/***/ },
/***/ 397:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _classCallCheck2 = __webpack_require__(3);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = __webpack_require__(39);
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = __webpack_require__(86);
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = __webpack_require__(23);
var _react2 = _interopRequireDefault(_react);
var _draftJs = __webpack_require__(94);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var Link = function (_React$Component) {
(0, _inherits3['default'])(Link, _React$Component);
function Link(props) {
(0, _classCallCheck3['default'])(this, Link);
var _this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call(this, props));
_this._validateLink = _this._validateLink.bind(_this);
_this._checkProtocol = _this._checkProtocol.bind(_this);
_this._showPopLinkOver = _this._showPopLinkOver.bind(_this);
_this._hidePopLinkOver = _this._hidePopLinkOver.bind(_this);
_this.isHover = false;
return _this;
}
Link.prototype._validateLink = function _validateLink() {
var pattern = new RegExp('^(https?:\/\/)?' + // protocol
'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|' + // domain name
'((\d{1,3}\.){3}\d{1,3}))' + // OR ip (v4) address
'(\:\d+)?(\/[-a-z\d%_.~+]*)*' + // port and path
'(\?[&a-z\d%_.~+=-]*)?' + // query string
'(\#[-a-z\d_]*)?$', 'i'); // fragment locater
if (!pattern.test(str)) {
alert("Please enter a valid URL.");
return false;
} else {
return true;
}
};
Link.prototype._checkProtocol = function _checkProtocol() {
return console.log("xcvd");
};
Link.prototype._showPopLinkOver = function _showPopLinkOver(e) {
if (!this.data.showPopLinkOver) {
return;
}
return this.data.showPopLinkOver(this.refs.link);
};
Link.prototype._hidePopLinkOver = function _hidePopLinkOver(e) {
if (!this.data.hidePopLinkOver) {
return;
}
return this.data.hidePopLinkOver();
};
Link.prototype.render = function render() {
this.data = _draftJs.Entity.get(this.props.entityKey).getData();
return _react2['default'].createElement(
'a',
{
ref: 'link',
href: this.data.url,
className: 'markup--anchor',
onMouseOver: this._showPopLinkOver,
onMouseOut: this._hidePopLinkOver
},
this.props.children
);
};
return Link;
}(_react2['default'].Component);
exports['default'] = Link;
module.exports = exports['default'];
/***/ },
/***/ 398:
/***/ function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _stringify = __webpack_require__(399);
var _stringify2 = _interopRequireDefault(_stringify);
var _classCallCheck2 = __webpack_require__(3);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = __webpack_require__(39);
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = __webpack_require__(86);
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = __webpack_require__(23);
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var Debug = function (_React$Component) {
(0, _inherits3["default"])(Debug, _React$Component);
function Debug() {
(0, _classCallCheck3["default"])(this, Debug);
var _this = (0, _possibleConstructorReturn3["default"])(this, _React$Component.call(this));
_this.handleToggleReadOnly = _this.handleToggleReadOnly.bind(_this);
_this.handleTestEmitAndDecode = _this.handleTestEmitAndDecode.bind(_this);
_this.handleTestEmitTEXT = _this.handleTestEmitTEXT.bind(_this);
_this.testEmitAndDecode = _this.testEmitAndDecode.bind(_this);
_this.testEmitTEXT = _this.testEmitTEXT.bind(_this);
_this.logState = _this.logState.bind(_this);
_this.toggleDisplay = _this.toggleDisplay.bind(_this);
_this.open = _this.open.bind(_this);
_this.render = _this.render.bind(_this);
_this.state = {
output: "",
display: "none"
};
return _this;
}
Debug.prototype.handleToggleReadOnly = function handleToggleReadOnly(e) {
e.preventDefault();
this.props.editor.toggleEditable();
return false;
};
Debug.prototype.handleTestEmitAndDecode = function handleTestEmitAndDecode(e) {
e.preventDefault();
return this.testEmitAndDecode();
};
Debug.prototype.handleTestEmitTEXT = function handleTestEmitTEXT(e) {
e.preventDefault();
return this.testEmitTEXT();
};
Debug.prototype.testEmitAndDecode = function testEmitAndDecode(e) {
var raw_as_json = this.props.editor.emitSerializedOutput();
this.props.editor.setState({
editorState: this.props.editor.decodeEditorContent(raw_as_json) }, this.logState((0, _stringify2["default"])(raw_as_json)));
return false;
};
Debug.prototype.testEmitTEXT = function testEmitTEXT() {
var text = this.props.editor.getTextFromEditor();
return this.logState(text);
};
Debug.prototype.logState = function logState(raw) {
return this.setState({ output: raw }, this.open);
};
Debug.prototype.toggleDisplay = function toggleDisplay(e) {
e.preventDefault();
var d = this.state.display === "block" ? "none" : this.state.display;
return this.setState({
display: d });
};
Debug.prototype.open = function open() {
return this.setState({
display: "block" });
};
Debug.prototype.render = function render() {
return _react2["default"].createElement(
"div",
null,
_react2["default"].createElement(
"div",
{ className: "debugControls" },
_react2["default"].createElement(
"ul",
null,
_react2["default"].createElement(
"li",
null,
" LOCKS: ",
this.props.editor.state.locks,
" "
),
_react2["default"].createElement(
"li",
null,
_react2["default"].createElement(
"a",
{ href: "#", onClick: this.handleToggleReadOnly },
"EDITABLE: ",
this.props.editor.state.read_only ? 'NO' : 'YES'
)
),
_react2["default"].createElement(
"li",
null,
_react2["default"].createElement(
"a",
{ href: "#", onClick: this.handleTestEmitTEXT },
"EDITOR TEXT"
)
),
_react2["default"].createElement(
"li",
null,
_react2["default"].createElement(
"a",
{ href: "#", onClick: this.handleTestEmitAndDecode },
"EDITOR STATE"
)
)
)
),
_react2["default"].createElement(
"div",
{ className: "debugZone", style: { display: this.state.display } },
_react2["default"].createElement("a", { href: "#", className: "dante-debug-close close", onClick: this.toggleDisplay }),
_react2["default"].createElement(
"div",
{ className: "debugOutput" },
_react2["default"].createElement(
"h2",
null,
"EDITOR OUTPUT"
),
this.state.output.length > 0 ? _react2["default"].createElement(
"pre",
null,
this.state.output
) : undefined
)
)
);
};
return Debug;
}(_react2["default"].Component);
exports["default"] = Debug;
module.exports = exports["default"];
/***/ },
/***/ 401:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _draftJs = __webpack_require__(94);
//TODO: what the f*ck is happening here? ;-;
var findEntities = function findEntities(entityType, instance, contentBlock, callback) {
return contentBlock.findEntityRanges(function (_this) {
return function (character) {
var entityKey, opts, res;
entityKey = character.getEntity();
return res = entityKey !== null && _draftJs.Entity.get(entityKey).getType() === entityType, res ? (opts = {
showPopLinkOver: instance.showPopLinkOver,
hidePopLinkOver: instance.hidePopLinkOver
}, _draftJs.Entity.mergeData(entityKey, opts)) : void 0, res;
};
}(undefined), callback);
};
exports['default'] = findEntities;
module.exports = exports['default'];
/***/ },
/***/ 402:
/***/ function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _stringify = __webpack_require__(399);
var _stringify2 = _interopRequireDefault(_stringify);
var _classCallCheck2 = __webpack_require__(3);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _axios = __webpack_require__(403);
var _axios2 = _interopRequireDefault(_axios);
var _immutable = __webpack_require__(25);
var _immutable2 = _interopRequireDefault(_immutable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var SaveBehavior = function () {
function SaveBehavior(options) {
(0, _classCallCheck3["default"])(this, SaveBehavior);
this.getLocks = options.getLocks;
this.config = options.config;
this.editorContent = options.editorContent;
this.editorState = options.editorState;
}
SaveBehavior.prototype.handleStore = function handleStore(ev) {
return this.store();
};
SaveBehavior.prototype.store = function store(content) {
var _this = this;
if (!this.config.data_storage.url) {
return;
}
if (this.getLocks() > 0) {
return;
}
clearTimeout(this.timeout);
return this.timeout = setTimeout(function () {
return _this.checkforStore(content);
}, this.config.data_storage.interval);
};
SaveBehavior.prototype.getTextFromEditor = function getTextFromEditor(content) {
return content.blocks.map(function (o) {
return o.text;
}).join("\n");
};
SaveBehavior.prototype.getUrl = function getUrl() {
var url = this.config.data_storage.url;
if (typeof url === "function") {
return url();
} else {
return url;
}
};
SaveBehavior.prototype.getMethod = function getMethod() {
var method = this.config.data_storage.method;
if (typeof method === "function") {
return method();
} else {
return method;
}
};
SaveBehavior.prototype.checkforStore = function checkforStore(content) {
var _this2 = this;
// ENTER DATA STORE
var isChanged = !_immutable2["default"].is(_immutable2["default"].fromJS(this.editorContent), _immutable2["default"].fromJS(content));
// console.log("CONTENT CHANGED:", isChanged)
if (!isChanged) {
return;
}
if (this.config.xhr.before_handler) {
this.config.xhr.before_handler();
}
// console.log "SAVING TO: #{@getMethod()} #{@getUrl()}"
return (0, _axios2["default"])({
method: this.getMethod(),
url: this.getUrl(),
data: {
editor_content: (0, _stringify2["default"])(content),
text_content: this.getTextFromEditor(content)
}
}).then(function (result) {
// console.log "STORING CONTENT", result
if (_this2.config.data_storage.success_handler) {
_this2.config.data_storage.success_handler(result);
}
if (_this2.config.xhr.success_handler) {
return _this2.config.xhr.success_handler(result);
}
})["catch"](function (error) {
// console.log("ERROR: got error saving content at #{@config.data_storage.url} - #{error}")
if (_this2.config.xhr.failure_handler) {
return _this2.config.xhr.failure_handler(error);
}
});
};
return SaveBehavior;
}();
exports["default"] = SaveBehavior;
module.exports = exports["default"];
/***/ },
/***/ 428:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _stringify = __webpack_require__(399);
var _stringify2 = _interopRequireDefault(_stringify);
var _draftJs = __webpack_require__(94);
var _immutable = __webpack_require__(25);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
// { compose
// } = require('underscore')
// underscore compose function
var compose = function compose() {
var args = arguments;
var start = args.length - 1;
return function () {
var i = start;
var result = args[start].apply(this, arguments);
while (i--) {
result = args[i].call(this, result);
}
return result;
};
};
// from https://gist.github.com/N1kto/6702e1c2d89a33a15a032c234fc4c34e
/*
* Helpers
*/
// Prepares img meta data object based on img attributes
var getBlockSpecForElement = function getBlockSpecForElement(imgElement) {
return {
contentType: 'image',
imgSrc: imgElement.getAttribute('src')
};
};
// Wraps meta data in HTML element which is 'understandable' by Draft, I used <blockquote />.
var wrapBlockSpec = function wrapBlockSpec(blockSpec) {
if (blockSpec === null) {
return null;
}
var tempEl = document.createElement('blockquote');
// stringify meta data and insert it as text content of temp HTML element. We will later extract
// and parse it.
tempEl.innerText = (0, _stringify2['default'])(blockSpec);
return tempEl;
};
// Replaces <img> element with our temp element
var replaceElement = function replaceElement(oldEl, newEl) {
if (!(newEl instanceof HTMLElement)) {
return;
}
var upEl = getUpEl(oldEl);
//parentNode = oldEl.parentNode
//return parentNode.replaceChild(newEl, oldEl)
return upEl.parentNode.insertBefore(newEl, upEl);
};
var getUpEl = function getUpEl(el) {
var original_el = el;
while (el.parentNode) {
if (el.parentNode.tagName !== 'BODY') {
el = el.parentNode;
}
if (el.parentNode.tagName === 'BODY') {
return el;
}
}
};
var elementToBlockSpecElement = compose(wrapBlockSpec, getBlockSpecForElement);
var imgReplacer = function imgReplacer(imgElement) {
return replaceElement(imgElement, elementToBlockSpecElement(imgElement));
};
/*
* Main function
*/
// takes HTML string and returns DraftJS ContentState
var customHTML2Content = function customHTML2Content(HTML, blockRn) {
var tempDoc = new DOMParser().parseFromString(HTML, 'text/html');
// replace all <img /> with <blockquote /> elements
var a = tempDoc.querySelectorAll('img').forEach(function (item) {
return imgReplacer(item);
});
// use DraftJS converter to do initial conversion. I don't provide DOMBuilder and
// blockRenderMap arguments here since it should fall back to its default ones, which are fine
console.log(tempDoc.body.innerHTML);
var contentBlocks = (0, _draftJs.convertFromHTML)(tempDoc.body.innerHTML, _draftJs.getSafeBodyFromHTML, blockRn);
// now replace <blockquote /> ContentBlocks with 'atomic' ones
contentBlocks = contentBlocks.map(function (block) {
var newBlock = void 0;
console.log("CHECK BLOCK", block.getType());
if (block.getType() !== 'blockquote') {
return block;
}
var json = "";
try {
json = JSON.parse(block.getText());
} catch (error) {
return block;
}
return newBlock = block.merge({
type: "image",
text: "",
data: {
url: json.imgSrc,
forceUpload: true
}
});
});
tempDoc = null;
return _draftJs.ContentState.createFromBlockArray(contentBlocks);
};
exports['default'] = customHTML2Content;
module.exports = exports['default'];
/***/ },
/***/ 429:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _classCallCheck2 = __webpack_require__(3);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = __webpack_require__(39);
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = __webpack_require__(86);
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = __webpack_require__(23);
var _react2 = _interopRequireDefault(_react);
var _reactDom = __webpack_require__(24);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _draftJs = __webpack_require__(94);
var _selection = __webpack_require__(430);
var _index = __webpack_require__(396);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var DanteImagePopover = function (_React$Component) {
(0, _inherits3['default'])(DanteImagePopover, _React$Component);
function DanteImagePopover(props) {
(0, _classCallCheck3['default'])(this, DanteImagePopover);
var _this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call(this, props));
_this.display = _this.display.bind(_this);
_this.show = _this.show.bind(_this);
_this.hide = _this.hide.bind(_this);
_this._toggleScaled = _this._toggleScaled.bind(_this);
_this.scale = _this.scale.bind(_this);
_this.collapse = _this.collapse.bind(_this);
_this.relocate = _this.relocate.bind(_this);
_this.componentWillReceiveProps = _this.componentWillReceiveProps.bind(_this);
_this.handleClick = _this.handleClick.bind(_this);
_this.state = {
position: {
top: 0,
left: 0
},
show: false,
scaled: false,
buttons: [{ type: "left" }, { type: "center" }, { type: "fill" }, { type: "wide" }]
};
return _this;
}
DanteImagePopover.prototype.display = function display(b) {
if (b) {
return this.show();
} else {
return this.hide();
}
};
DanteImagePopover.prototype.show = function show() {
return this.setState({
show: true });
};
DanteImagePopover.prototype.hide = function hide() {
return this.setState({
show: false });
};
DanteImagePopover.prototype.setPosition = function setPosition(coords) {
return this.setState({
position: coords });
};
DanteImagePopover.prototype._toggleScaled = function _toggleScaled(ev) {
if (this.state.scaled) {
return this.collapse();
} else {
return this.scale();
}
};
DanteImagePopover.prototype.scale = function scale() {
return this.setState({
scaled: true });
};
DanteImagePopover.prototype.collapse = function collapse() {
return this.setState({
scaled: false });
};
DanteImagePopover.prototype.relocate = function relocate() {
var editorState = this.props.editorState;
if (editorState.getSelection().isCollapsed()) {
var currentBlock = (0, _index.getCurrentBlock)(editorState);
var blockType = currentBlock.getType();
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
var block = contentState.getBlockForKey(selectionState.anchorKey);
var nativeSelection = (0, _selection.getSelection)(window);
if (!nativeSelection.rangeCount) {
return;
}
var node = (0, _index.getNode)();
var selectionBoundary = (0, _selection.getSelectionRect)(nativeSelection);
var coords = selectionBoundary;
var parent = _reactDom2['default'].findDOMNode(this.props.editor);
var parentBoundary = parent.getBoundingClientRect();
this.display(blockType === "image");
if (blockType === "image") {
selectionBoundary = node.anchorNode.parentNode.parentNode.parentNode.getBoundingClientRect();
var el = this.refs.image_popover;
var padd = el.offsetWidth / 2;
return this.setPosition({
top: selectionBoundary.top - parentBoundary.top + 60,
left: selectionBoundary.left + selectionBoundary.width / 2 - padd
});
}
} else {
return this.hide();
}
};