simplemde-markdown-editor/dist/simplemde.min.js

16 lines
248 KiB
JavaScript
Raw Normal View History

/**
2016-06-14 12:48:07 -05:00
* simplemde v1.11.2
* Copyright Next Step Webs, Inc.
* @link https://github.com/NextStepWebs/simplemde-markdown-editor
* @license MIT
*/
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).SimpleMDE=e()}(function(){return function i(r,o,l){function a(t,e){if(!o[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(s)return s(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}n=o[t]={exports:{}},r[t][0].call(n.exports,function(e){return a(r[t][1][e]||e)},n,n.exports,i,r,o,l)}return o[t].exports}for(var s="function"==typeof require&&require,e=0;e<l.length;e++)a(l[e]);return a}({1:[function(e,t,n){},{}],2:[function(e,t,n){"use strict";var l=e("typo-js");function a(o){"function"!=typeof(o=o||{}).codeMirrorInstance||"function"!=typeof o.codeMirrorInstance.defineMode?console.log("CodeMirror Spell Checker: You must provide an instance of CodeMirror via the option `codeMirrorInstance`"):(String.prototype.includes||(String.prototype.includes=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),o.codeMirrorInstance.defineMode("spell-checker",function(e){a.aff_loading||(a.aff_loading=!0,(t=new XMLHttpRequest).open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff",!0),t.onload=function(){4===t.readyState&&200===t.status&&(a.aff_data=t.responseText,a.num_loaded++,2==a.num_loaded)&&(a.typo=new l("en_US",a.aff_data,a.dic_data,{platform:"any"}))},t.send(null)),a.dic_loading||(a.dic_loading=!0,(n=new XMLHttpRequest).open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic",!0),n.onload=function(){4===n.readyState&&200===n.status&&(a.dic_data=n.responseText,a.num_loaded++,2==a.num_loaded)&&(a.typo=new l("en_US",a.aff_data,a.dic_data,{platform:"any"}))},n.send(null));var t,n,i='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ',r={token:function(e){var t=e.peek(),n="";if(i.includes(t))return e.next(),null;for(;null!=(t=e.peek())&&!i.includes(t);)n+=t,e.next();return a.typo&&!a.typo.check(n)?"spell-error":null}},e=o.codeMirrorInstance.getMode(e,e.backdrop||"text/plain");return o.codeMirrorInstance.overlayMode(e,r,!0)}))}a.num_loaded=0,a.aff_loading=!1,a.dic_loading=!1,a.aff_data="",a.dic_data="",t.exports=a},{"typo-js":13}],3:[function(e,t,n){(function(i){"use strict";i.defineOption("fullScreen",!1,function(e,t,n){!(n=n==i.Init?!1:n)!=!t&&(t?(t=(n=e).getWrapperElement(),n.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:t.style.width,height:t.style.height},t.style.width="",t.style.height="auto",t.className+=" CodeMirror-fullscreen",document.documentElement.style.overflow="hidden",n):((n=(t=e).getWrapperElement()).className=n.className.replace(/\s*CodeMirror-fullscreen\b/,""),document.documentElement.style.overflow="",e=t.state.fullScreenRestore,n.style.width=e.width,n.style.height=e.height,window.scrollTo(e.scrollLeft,e.scrollTop),t)).refresh()})})("object"==typeof n&&"object"==typeof t?e("../../lib/codemirror"):CodeMirror)},{"../../lib/codemirror":8}],4:[function(e,t,n){(function(i){function r(e){e.state.placeholder&&(e.state.placeholder.parentNode.removeChild(e.state.placeholder),e.state.placeholder=null)}function o(e){r(e);var t=e.state.placeholder=document.createElement("pre"),n=(t.style.cssText="height: 0; overflow: visible",t.style.direction=e.getOption("direction"),t.className="CodeMirror-placeholder CodeMirror-line-like",e.getOption("placeholder"));"string"==typeof n&&(n=document.createTextNode(n)),t.appendChild(n),e.display.lineSpace.insertBefore(t,e.display.lineSpace.firstChild)}function l(e){s(e)&&o(e)}function a(e){var t=e.getWrapperElement(),n=s(e);t.className=t.className.replace(" CodeMirror-empty","")+(n?" CodeMirror-empty":""),(n?o:r)(e)}function s(e){return 1===e.lineCount()&&""===e.getLine(0)}i.defineOption("placeholder","",function(e,t,n){var n=n&&n!=i.Init;t&&!n?(e.on("blur",l),e.on("change",a),e.on("swapDoc",a),i.on(e.getInputField(),"compositionupdate",e.state.placeholderCompose=function(){var n;n=e,setTimeout(function()
<div style="display: flex; justify-content: space-between; align-items: center;">
<input type="text" placeholder="Editing instructions... (↑ for history, @ for code / documentation)" style="width: 100%; border: none; background: transparent; color: white; font-size: 12px;" />
<button style="color: white; background: transparent; border: none; cursor: pointer; font-size: 14px;" id="close-button" data-line="${t}"></button>
</div>
<div style="margin-top: 5px; font-size: 12px; color: #aaa;">
<span>undefined to close</span>
<span style="float: right;">gpt-4.0 K to toggle</span>
</div>
2024-06-11 14:09:07 +09:00
`,r.style.padding="10px",r.style.width="520px",e.charCoords({line:t+4,ch:0},"window")),e=n.top-r.offsetHeight-10;e<0&&(e=n.bottom+10),r.style.left=n.left+"px",r.style.top=e+"px",r.style.display="block",document.getElementById("close-button").onclick=function(){this.getAttribute("data-line");i.codemirror.replaceRange("",{line:1,ch:0},{line:5,ch:0}),r.style.display="none"}},r.appendChild(n),document.body.appendChild(r),r);o.on("cursorActivity",function(){var e,t=o.getCursor(),t=o.cursorCoords(t,"window");o.somethingSelected()?(e=l.offsetHeight,(e=t.top-e-10)<0&&(e=t.bottom+10),l.style.left=t.left+"px",l.style.top=e+"px",l.style.display="block",t=o.getSelection(),console.log("Selected text:",t)):l.style.display="none"})}function D(e,t,n,i){var r,o,l,a;/editor-preview-active/.test(e.getWrapperElement().lastChild.className)||(o=n[0],n=n[1],l=e.getCursor("start"),a=e.getCursor("end"),i&&(n=n.replace("#url#",i)),t?(o=(r=e.getLine(l.line)).slice(0,l.ch),n=r.slice(l.ch),e.replaceRange(o+n,{line:l.line,ch:0})):(r=e.getSelection(),e.replaceSelection(o+r+n),l.ch+=o.length,l!==a&&(a.ch+=o.length)),e.setSelection(l,a),e.focus())}function A(e,t,n){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){for(var i,r,o,l=e.getCursor("start"),a=e.getCursor("end"),s=l.line;s<=a.line;s++)i=s,o=r=void 0,r=(o=e.getLine(i)).search(/[^#]/),o=void 0!==t?r<=0?"bigger"==t?"###### "+o:"# "+o:6==r&&"smaller"==t?o.substr(7):1==r&&"bigger"==t?o.substr(2):"bigger"==t?o.substr(1):"#"+o:1==n?r<=0?"# "+o:r==n?o.substr(r+1):"# "+o.substr(r+1):2==n?r<=0?"## "+o:r==n?o.substr(r+1):"## "+o.substr(r+1):r<=0?"### "+o:r==n?o.substr(r+1):"### "+o.substr(r+1),e.replaceRange(o,{line:i,ch:0},{line:i,ch:99999999999999});e.focus()}}function F(e,t){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){for(var n,i,r=h(e),o=e.getCursor("start"),l=e.getCursor("end"),a={quote:/^(\s*)\>\s+/,"unordered-list":/^(\s*)(\*|\-|\+)\s+/,"ordered-list":/^(\s*)\d+\.\s+/},s={quote:"> ","unordered-list":"* ","ordered-list":"1. "},c=o.line;c<=l.line;c++)n=c,i=void 0,i=e.getLine(n),i=r[t]?i.replace(a[t],"$1"):s[t]+i,e.replaceRange(i,{line:n,ch:0},{line:n,ch:99999999999999});e.focus()}}function E(e,t,n,i){var r,o,l,a,s;/editor-preview-active/.test(e.codemirror.getWrapperElement().lastChild.className)||(i=void 0===i?n:i,r=h(e=e.codemirror),l=n,i=i,a=e.getCursor("start"),s=e.getCursor("end"),r[t]?(l=(o=e.getLine(a.line)).slice(0,a.ch),i=o.slice(a.ch),"bold"==t?(l=l.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/,""),i=i.replace(/(\*\*|__)/,"")):"italic"==t?(l=l.replace(/(\*|_)(?![\s\S]*(\*|_))/,""),i=i.replace(/(\*|_)/,"")):"strikethrough"==t&&(l=l.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/,""),i=i.replace(/(\*\*|~~)/,"")),e.replaceRange(l+i,{line:a.line,ch:0},{line:a.line,ch:99999999999999}),"bold"==t||"strikethrough"==t?(a.ch-=2,a!==s&&(s.ch-=2)):"italic"==t&&(--a.ch,a!==s)&&--s.ch):(o=e.getSelection(),"bold"==t?o=(o=o.split("**").join("")).split("__").join(""):"italic"==t?o=(o=o.split("*").join("")).split("_").join(""):"strikethrough"==t&&(o=o.split("~~").join("")),e.replaceSelection(l+o+i),a.ch+=n.length,s.ch=a.ch+o.length),e.setSelection(a,s),e.focus())}function O(e){for(var t=1;t<arguments.length;t++)e=function e(t,n){for(var i in n)n.hasOwnProperty(i)&&(n[i]instanceof Array?t[i]=n[i].concat(t[i]instanceof Array?t[i]:[]):null!==n[i]&&"object"==typeof n[i]&&n[i].constructor===Object?t[i]=e(t[i]||{},n[i]):t[i]=n[i]);return t}(e,arguments[t]);return e}function _(e){var t=e.match(/[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g),n=0;if(null!==t)for(var i=0;i<t.length;i++)19968<=t[i].charCodeAt(0)?n+=t[i].length:n+=1;return n}var H={console:{name:"console",action:function(){console.log("test")},className:"fa fa-check-circle",title:"console",default:!0},bold:{name:"bold",action:t,className:"fa fa-bold",title:"Bold",default:!0},italic:{name:"italic",action:n,className:"fa fa-italic",title:"Italic",default:!0},strikethrough:{name:"strikethrough",action:o,className:"fa fa-strikethrough",title:"Str