mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
favor imperative programming
This commit is contained in:
parent
a390dd8ecf
commit
24f8cf89f3
File diff suppressed because one or more lines are too long
@ -16073,7 +16073,7 @@ var Action = function () {
|
|||||||
exports.default = Action;
|
exports.default = Action;
|
||||||
|
|
||||||
},{"./base":21}],21:[function(require,module,exports){
|
},{"./base":21}],21:[function(require,module,exports){
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
@ -16081,6 +16081,8 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
|
|
||||||
var _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; }; }();
|
var _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; }; }();
|
||||||
|
|
||||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16093,50 +16095,54 @@ exports.default = new (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Base, [{
|
_createClass(Base, [{
|
||||||
key: "getState",
|
key: 'getState',
|
||||||
value: function getState(cm) {
|
value: function getState(cm) {
|
||||||
var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : cm.getCursor("start");
|
var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : cm.getCursor("start");
|
||||||
|
|
||||||
var stat = cm.getTokenAt(pos);
|
var stat = cm.getTokenAt(pos);
|
||||||
if (!stat.type) return {};
|
if (!stat.type) return {};
|
||||||
var types = stat.type.split(" ");
|
var typeMap = {
|
||||||
|
'strong': function strong() {
|
||||||
var ret = {},
|
return { bold: true };
|
||||||
data = void 0,
|
},
|
||||||
text = void 0;
|
'variable-2': function variable2() {
|
||||||
for (var i = 0; i < types.length; i++) {
|
return _defineProperty({}, /^\s*\d+\.\s/.test(cm.getLine(pos.line)) ? 'ordered-list' : 'unordered-list', true);
|
||||||
data = types[i];
|
},
|
||||||
if (data === "strong") {
|
'atom': function atom() {
|
||||||
ret.bold = true;
|
return { quote: true };
|
||||||
} else if (data === "variable-2") {
|
},
|
||||||
text = cm.getLine(pos.line);
|
'em': function em() {
|
||||||
if (/^\s*\d+\.\s/.test(text)) {
|
return { italic: true };
|
||||||
ret["ordered-list"] = true;
|
},
|
||||||
} else {
|
'quote': function quote() {
|
||||||
ret["unordered-list"] = true;
|
return { quote: true };
|
||||||
}
|
},
|
||||||
} else if (data === "atom") {
|
'strikethrough': function strikethrough() {
|
||||||
ret.quote = true;
|
return { strikethrough: true };
|
||||||
} else if (data === "em") {
|
},
|
||||||
ret.italic = true;
|
'comment': function comment() {
|
||||||
} else if (data === "quote") {
|
return { code: true };
|
||||||
ret.quote = true;
|
},
|
||||||
} else if (data === "strikethrough") {
|
'link': function link() {
|
||||||
ret.strikethrough = true;
|
return { link: true };
|
||||||
} else if (data === "comment") {
|
},
|
||||||
ret.code = true;
|
'tag': function tag() {
|
||||||
} else if (data === "link") {
|
return { image: true };
|
||||||
ret.link = true;
|
},
|
||||||
} else if (data === "tag") {
|
'_other': function _other(v) {
|
||||||
ret.image = true;
|
return v.match(/^header(\-[1-6])?$/) ? _defineProperty({}, v.replace("header", "heading"), true) : {};
|
||||||
} else if (data.match(/^header(\-[1-6])?$/)) {
|
|
||||||
ret[data.replace("header", "heading")] = true;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
return ret;
|
var objectResult = stat.type.split(" ").map(function (v) {
|
||||||
|
return typeMap[v] ? typeMap[v]() : typeMap['_other'](v);
|
||||||
|
}).reduce(function (pv, cv) {
|
||||||
|
return Object.assign(pv, cv);
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return objectResult;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "toggleBlock",
|
key: 'toggleBlock',
|
||||||
value: function toggleBlock(editor, type, start_chars, end_chars) {
|
value: function toggleBlock(editor, type, start_chars, end_chars) {
|
||||||
if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className)) return;
|
if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className)) return;
|
||||||
|
|
||||||
@ -16205,7 +16211,7 @@ exports.default = new (function () {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "replaceSelection",
|
key: 'replaceSelection',
|
||||||
value: function replaceSelection(cm, active, startEnd, url) {
|
value: function replaceSelection(cm, active, startEnd, url) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
||||||
|
|
||||||
@ -16238,7 +16244,7 @@ exports.default = new (function () {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "toggleHeading",
|
key: 'toggleHeading',
|
||||||
value: function toggleHeading(cm, direction, size) {
|
value: function toggleHeading(cm, direction, size) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
||||||
|
|
||||||
@ -16307,7 +16313,7 @@ exports.default = new (function () {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "toggleLine",
|
key: 'toggleLine',
|
||||||
value: function toggleLine(cm, name) {
|
value: function toggleLine(cm, name) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
||||||
|
|
||||||
@ -16344,7 +16350,7 @@ exports.default = new (function () {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "cleanBlock",
|
key: 'cleanBlock',
|
||||||
value: function cleanBlock(cm) {
|
value: function cleanBlock(cm) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return;
|
||||||
|
|
||||||
|
4
dist/simplemde.min.js
vendored
4
dist/simplemde.min.js
vendored
File diff suppressed because one or more lines are too long
@ -8,40 +8,23 @@ export default new class Base {
|
|||||||
getState (cm, pos = cm.getCursor("start")){
|
getState (cm, pos = cm.getCursor("start")){
|
||||||
let stat = cm.getTokenAt(pos);
|
let stat = cm.getTokenAt(pos);
|
||||||
if(!stat.type) return {};
|
if(!stat.type) return {};
|
||||||
const types = stat.type.split(" ");
|
const typeMap = {
|
||||||
|
'strong': () => ({bold: true}),
|
||||||
let ret = {},
|
'variable-2': () => ({[/^\s*\d+\.\s/.test(cm.getLine(pos.line))? 'ordered-list': 'unordered-list']: true}),
|
||||||
data, text;
|
'atom': () => ({quote: true}),
|
||||||
for(let i = 0; i < types.length; i++) {
|
'em': () => ({italic: true}),
|
||||||
data = types[i];
|
'quote': () => ({quote: true}),
|
||||||
if(data === "strong") {
|
'strikethrough': () => ({strikethrough: true}),
|
||||||
ret.bold = true;
|
'comment': () => ({code: true}),
|
||||||
} else if(data === "variable-2") {
|
'link': () => ({link: true}),
|
||||||
text = cm.getLine(pos.line);
|
'tag': () => ({image: true}),
|
||||||
if(/^\s*\d+\.\s/.test(text)) {
|
'_other': v => v.match(/^header(\-[1-6])?$/)? ({[v.replace("header", "heading")]: true}): ({})
|
||||||
ret["ordered-list"] = true;
|
|
||||||
} else {
|
|
||||||
ret["unordered-list"] = true;
|
|
||||||
}
|
|
||||||
} else if(data === "atom") {
|
|
||||||
ret.quote = true;
|
|
||||||
} else if(data === "em") {
|
|
||||||
ret.italic = true;
|
|
||||||
} else if(data === "quote") {
|
|
||||||
ret.quote = true;
|
|
||||||
} else if(data === "strikethrough") {
|
|
||||||
ret.strikethrough = true;
|
|
||||||
} else if(data === "comment") {
|
|
||||||
ret.code = true;
|
|
||||||
} else if(data === "link") {
|
|
||||||
ret.link = true;
|
|
||||||
} else if(data === "tag") {
|
|
||||||
ret.image = true;
|
|
||||||
} else if(data.match(/^header(\-[1-6])?$/)) {
|
|
||||||
ret[data.replace("header", "heading")] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
const objectResult = stat.type.split(" ")
|
||||||
|
.map(v => typeMap[v]? typeMap[v](): typeMap['_other'](v))
|
||||||
|
.reduce((pv, cv) => Object.assign(pv, cv), {})
|
||||||
|
|
||||||
|
return objectResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleBlock (editor, type, start_chars, end_chars){
|
toggleBlock (editor, type, start_chars, end_chars){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user