UNPKG

3.05 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9var _slate = require('slate');
10
11var _immutable = require('immutable');
12
13function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
15function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
16
17function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
18
19var DEFAULTS = {
20 containerType: 'code_block',
21 lineType: 'code_line',
22 exitBlockType: 'paragraph',
23 selectAll: true,
24 allowMarks: false,
25 getIndent: null,
26 onExit: null
27};
28
29/**
30 * The plugin options container
31 */
32
33var Options = function (_Record) {
34 _inherits(Options, _Record);
35
36 function Options() {
37 _classCallCheck(this, Options);
38
39 return _possibleConstructorReturn(this, (Options.__proto__ || Object.getPrototypeOf(Options)).apply(this, arguments));
40 }
41
42 _createClass(Options, [{
43 key: 'resolvedOnExit',
44 value: function resolvedOnExit(change) {
45 if (this.onExit) {
46 // Custom onExit option
47 return this.onExit(change);
48 }
49 // Default behavior: insert an exit block
50 var range = change.value.selection;
51
52 var exitBlock = _slate.Block.create({
53 type: this.exitBlockType,
54 nodes: [_slate.Text.create()]
55 });
56
57 change.deleteAtRange(range, { normalize: false });
58 change.insertBlockAtRange(change.value.selection, exitBlock, {
59 normalize: false
60 });
61 // Exit the code block
62 change.unwrapNodeByKey(exitBlock.key);
63
64 return change.collapseToStartOf(exitBlock);
65 }
66 }]);
67
68 return Options;
69}((0, _immutable.Record)(DEFAULTS));
70
71exports.default = Options;
\No newline at end of file