@taufik-nurrohman/text-editor.source 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +6 -2
- package/index.min.js +1 -1
- package/index.mjs +7 -2
- package/package.json +1 -1
package/index.js
CHANGED
@@ -349,6 +349,10 @@
|
|
349
349
|
}
|
350
350
|
return;
|
351
351
|
}
|
352
|
+
// Partial mobile support
|
353
|
+
function onPutDown(e) {
|
354
|
+
onKeyDown.call(this, e);
|
355
|
+
}
|
352
356
|
|
353
357
|
function attach() {
|
354
358
|
var $ = this;
|
@@ -466,11 +470,11 @@
|
|
466
470
|
}
|
467
471
|
return this.selectLine(withSpaces).wrap(open, close, wrap);
|
468
472
|
});
|
469
|
-
return $.on('key.down', onKeyDown).record();
|
473
|
+
return $.on('key.down', onKeyDown).on('put.down', onPutDown).record();
|
470
474
|
}
|
471
475
|
|
472
476
|
function detach() {
|
473
|
-
return this.off('key.down', onKeyDown);
|
477
|
+
return this.off('key.down', onKeyDown).off('put.down', onPutDown);
|
474
478
|
}
|
475
479
|
var index_js = {
|
476
480
|
attach: attach,
|
package/index.min.js
CHANGED
@@ -23,4 +23,4 @@
|
|
23
23
|
* SOFTWARE.
|
24
24
|
*
|
25
25
|
*/
|
26
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):((e="undefined"!=typeof globalThis?globalThis:e||self).TextEditor=e.TextEditor||{},e.TextEditor.Source=r())}(this,(function(){"use strict";var e,r,t,n=function(e,r){return-1!==r.indexOf(e)},i=function(e){return Array.isArray(e)},o=function(e){return"function"==typeof e},s=function(e,r,t){return!(!e||"object"!=typeof e)&&(t?u(r)&&u(e.constructor)&&r===e.constructor:u(r)&&e instanceof r)},c=function(e){return"number"==typeof e},f=function(e,r){return void 0===r&&(r=!0),!(!e||"object"!=typeof e)&&(!r||s(e,Object,1))},u=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},l=function(e){return e.length},a=function e(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];for(var s=t.shift(),c=0,a=l(t);c<a;++c)for(var p in t[c])if(u(s[p]))if(i(s[p])&&i(t[c][p])){s[p]=[].concat(s[p]);for(var d=0,h=l(t[c][p]);d<h;++d)n(t[c][p][d],s[p])||s[p].push(t[c][p][d])}else f(s[p])&&f(t[c][p])?s[p]=e({},s[p],t[c][p]):s[p]=t[c][p];else s[p]=t[c][p];return s},p=window,d=function(e){return e&&e.preventDefault()},h=function(e,r){return function(e){return s(e,RegExp)}(e)?e:RegExp(e,u(r)?r:"g")},v="Control-",w="Shift-",g="Delete",m="Enter",$=(e=function(e){return e.record()},r=10,function(){var n=arguments,i=this;t&&clearTimeout(t),t=setTimeout((function(){return e.apply(i,n)}),r)});function b(e){var r=this,t=r.k(!1).pop(),i=r.k();if($(r),!e.defaultPrevented&&!r.keys[i]){var o,s,f=r.state.tab||"\t",u=r.state.pairs||{},a=Object.values(u);(function(e){return c(e)&&0==e%1})(f)&&(f=" ".repeat(f));var p=r.$(),b=p.after,y=p.before,L=p.end,x=p.start,A=p.value,T=b.split("\n").shift(),j=y.split("\n").pop(),k=/^\s+/.exec(j),E=k&&k[0]||"";if(v+w+m===i)return y||b?(d(e),r.select(x-l(j)).wrap(E,"\n").insert(A).record(),!1):void 0;if(v+m===i&&(y||b))return d(e),r.select(L+l(T)).wrap("\n"+E,"").insert(A).record(),!1;if("Alt-"!=i+"-"&&v!==i+"-"){if(" "===i)return o=u[s=y.slice(-1)],!A&&o&&s&&o===b[0]?(d(e),r.wrap(" "," ")):void 0;if("Backspace"===i||g===i){if(o=u[s=y.slice(-1)],"\\"===s)return;return A?b&&y&&o&&o===b[0]&&!y.endsWith("\\"+s)?(d(e),r.record().peel(s,o).record()):void 0:(o=u[s=y.trim().slice(-1)])&&s&&(b.startsWith(" "+o)&&y.endsWith(s+" ")||b.startsWith("\n"+E+o)&&y.endsWith(s+"\n"+E))?(d(e),r.trim("","").record()):g!==i&&j.endsWith(f)?(d(e),r.pull(f).record()):b&&y&&!y.endsWith("\\"+s)&&o===b[0]&&s===y.slice(-1)?(d(e),r.peel(s,o).record()):void 0}if(m!==i&&w+m!==i){if("\\"!==(s=y.slice(-1))){if(o=n(b[0],a)?b[0]:u[s],!A&&b&&y&&o&&t===o)return d(e),r.select(x+1).record();for(s in u){if(o=u[s],t===s&&o)return d(e),r.wrap(s,o).record();if(t===o){if(A)return d(e),r.record().wrap(s,o).record();break}}var W,S,D,O=[];if(A){for(W in u)(S=u[W])&&O.push("(?:\\"+W+"(?:\\\\.|[^\\"+W+(S!==W?"\\"+S:"")+"])*\\"+S+")");if(O.push("\\w+"),O.push("\\s+"),O.push("[\\s\\S]"),v+"ArrowLeft"===i)return d(e),(D=h("("+O.join("|")+")$","").exec(y))?r.insert("").select(x-l(D[0])).insert(A).record():r.select();if(v+"ArrowRight"===i)return d(e),(D=b.match(h("^("+O.join("|")+")","")))?r.insert("").select(L+l(D[0])-l(A)).insert(A).record():r.select()}if(L+=l(T),x-=l(j),A=j+A+T,v+"ArrowUp"===i){if(d(e),!n("\n",y))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"$2",1),r.replace(/(^|\n)([^\n]*?)$/,"",-1);var R=r.$();return y=R.before,x=R.start,j=y.split("\n").pop(),r.select(x-=l(j)).wrap(A,"\n"),r.select(x,x+l(A)),r.record()}if(v+"ArrowDown"===i){if(d(e),!n("\n",b))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"",1),r.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var B=r.$();return b=B.after,L=B.end,T=b.split("\n").shift(),r.select(L+=l(T)).wrap("\n",A),L+=1,r.select(L,L+l(A)),r.record()}}}else if(!A){if(b&&y&&(o=u[s=y.slice(-1)])&&o===b[0])return d(e),r.wrap("\n"+E+(s!==o?f:""),"\n"+E).record();if(E)return d(e),r.insert("\n"+E,-1).record()}}else d(e)}}var
|
26
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):((e="undefined"!=typeof globalThis?globalThis:e||self).TextEditor=e.TextEditor||{},e.TextEditor.Source=r())}(this,(function(){"use strict";var e,r,t,n=function(e,r){return-1!==r.indexOf(e)},i=function(e){return Array.isArray(e)},o=function(e){return"function"==typeof e},s=function(e,r,t){return!(!e||"object"!=typeof e)&&(t?u(r)&&u(e.constructor)&&r===e.constructor:u(r)&&e instanceof r)},c=function(e){return"number"==typeof e},f=function(e,r){return void 0===r&&(r=!0),!(!e||"object"!=typeof e)&&(!r||s(e,Object,1))},u=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},l=function(e){return e.length},a=function e(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];for(var s=t.shift(),c=0,a=l(t);c<a;++c)for(var p in t[c])if(u(s[p]))if(i(s[p])&&i(t[c][p])){s[p]=[].concat(s[p]);for(var d=0,h=l(t[c][p]);d<h;++d)n(t[c][p][d],s[p])||s[p].push(t[c][p][d])}else f(s[p])&&f(t[c][p])?s[p]=e({},s[p],t[c][p]):s[p]=t[c][p];else s[p]=t[c][p];return s},p=window,d=function(e){return e&&e.preventDefault()},h=function(e,r){return function(e){return s(e,RegExp)}(e)?e:RegExp(e,u(r)?r:"g")},v="Control-",w="Shift-",g="Delete",m="Enter",$=(e=function(e){return e.record()},r=10,function(){var n=arguments,i=this;t&&clearTimeout(t),t=setTimeout((function(){return e.apply(i,n)}),r)});function b(e){var r=this,t=r.k(!1).pop(),i=r.k();if($(r),!e.defaultPrevented&&!r.keys[i]){var o,s,f=r.state.tab||"\t",u=r.state.pairs||{},a=Object.values(u);(function(e){return c(e)&&0==e%1})(f)&&(f=" ".repeat(f));var p=r.$(),b=p.after,y=p.before,L=p.end,x=p.start,A=p.value,T=b.split("\n").shift(),j=y.split("\n").pop(),k=/^\s+/.exec(j),E=k&&k[0]||"";if(v+w+m===i)return y||b?(d(e),r.select(x-l(j)).wrap(E,"\n").insert(A).record(),!1):void 0;if(v+m===i&&(y||b))return d(e),r.select(L+l(T)).wrap("\n"+E,"").insert(A).record(),!1;if("Alt-"!=i+"-"&&v!==i+"-"){if(" "===i)return o=u[s=y.slice(-1)],!A&&o&&s&&o===b[0]?(d(e),r.wrap(" "," ")):void 0;if("Backspace"===i||g===i){if(o=u[s=y.slice(-1)],"\\"===s)return;return A?b&&y&&o&&o===b[0]&&!y.endsWith("\\"+s)?(d(e),r.record().peel(s,o).record()):void 0:(o=u[s=y.trim().slice(-1)])&&s&&(b.startsWith(" "+o)&&y.endsWith(s+" ")||b.startsWith("\n"+E+o)&&y.endsWith(s+"\n"+E))?(d(e),r.trim("","").record()):g!==i&&j.endsWith(f)?(d(e),r.pull(f).record()):b&&y&&!y.endsWith("\\"+s)&&o===b[0]&&s===y.slice(-1)?(d(e),r.peel(s,o).record()):void 0}if(m!==i&&w+m!==i){if("\\"!==(s=y.slice(-1))){if(o=n(b[0],a)?b[0]:u[s],!A&&b&&y&&o&&t===o)return d(e),r.select(x+1).record();for(s in u){if(o=u[s],t===s&&o)return d(e),r.wrap(s,o).record();if(t===o){if(A)return d(e),r.record().wrap(s,o).record();break}}var W,S,D,O=[];if(A){for(W in u)(S=u[W])&&O.push("(?:\\"+W+"(?:\\\\.|[^\\"+W+(S!==W?"\\"+S:"")+"])*\\"+S+")");if(O.push("\\w+"),O.push("\\s+"),O.push("[\\s\\S]"),v+"ArrowLeft"===i)return d(e),(D=h("("+O.join("|")+")$","").exec(y))?r.insert("").select(x-l(D[0])).insert(A).record():r.select();if(v+"ArrowRight"===i)return d(e),(D=b.match(h("^("+O.join("|")+")","")))?r.insert("").select(L+l(D[0])-l(A)).insert(A).record():r.select()}if(L+=l(T),x-=l(j),A=j+A+T,v+"ArrowUp"===i){if(d(e),!n("\n",y))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"$2",1),r.replace(/(^|\n)([^\n]*?)$/,"",-1);var R=r.$();return y=R.before,x=R.start,j=y.split("\n").pop(),r.select(x-=l(j)).wrap(A,"\n"),r.select(x,x+l(A)),r.record()}if(v+"ArrowDown"===i){if(d(e),!n("\n",b))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"",1),r.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var B=r.$();return b=B.after,L=B.end,T=b.split("\n").shift(),r.select(L+=l(T)).wrap("\n",A),L+=1,r.select(L,L+l(A)),r.record()}}}else if(!A){if(b&&y&&(o=u[s=y.slice(-1)])&&o===b[0])return d(e),r.wrap("\n"+E+(s!==o?f:""),"\n"+E).record();if(E)return d(e),r.insert("\n"+E,-1).record()}}else d(e)}}function y(e){b.call(this,e)}var L={attach:function(){var e=this,r=e.constructor._;return e.state=a({pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"}},e.state),!o(r.alert)&&(r.alert=function(e,r){return p.alert&&p.alert(e),o(r)&&r.call(this,!0)}),!o(r.confirm)&&(r.confirm=function(e,r){return o(r)&&r.call(this,p.confirm&&p.confirm(e))}),!o(r.insertLine)&&(r.insertLine=function(e,r){var t=this,n=t.$(),i=n.after,o=n.before,s=n.end,c=n.start,f=i.split("\n").shift(),u=l(f),a=o.split("\n").pop(),p=l(a),d=/^\s+/.exec(a),h=d&&d[0]||"";return-1===r?t.select(c-p).insert("\n",1).push(h).insert(e,1,!1):1===r?t.select(s+u).insert("\n",-1).push(h).insert(e,1,!1):t.select(c-p,s+u).insert(e,r,!0).wrap(h,"")}),!o(r.peelLine)&&(r.peelLine=function(e,r,t,n){return void 0===n&&(n=!1),this.selectLine(n).peel(e,r,t)}),!o(r.prompt)&&(r.prompt=function(e,r,t){return o(t)&&t.call(this,!!p.prompt&&p.prompt(e,r))}),!o(r.selectLine)&&(r.selectLine=function(e){void 0===e&&(e=!0);var r,t=this,n=t.$(),i=n.after,o=n.before,s=n.end,c=n.start,f=i.split("\n").shift(),u=l(f),a=o.split("\n").pop(),p=l(a);if(t.select(c-p,s+u),!e){var d=t.$(),h=d.end,v=d.start,w=d.value;if(r=/^(\s+)?[\s\S]*?(\s+)?$/.exec(w))return t.select(v+l(r[1]||""),h-l(r[2]||""))}return t}),!o(r.toggle)&&(r.toggle=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,f=l(r),u=l(e);return t&&r===c.slice(-f)&&e===c.slice(0,u)||r===o.slice(0,f)&&e===s.slice(-u)?n.peel(e,r,t):n.wrap(e,r,t)}),!o(r.toggleLine)&&(r.toggleLine=function(e,r,t,n){void 0===n&&(n=!1);var i=this.selectLine(n),o=i.$();o.after,o.before;var s=o.value,c=l(r),f=l(e);if(!t&&r===s.slice(-c)&&e===s.slice(0,f)){var u=i.$(),a=u.end,p=u.start;i.select(p+f,a-c)}return i.toggle(e,r,t)}),!o(r.wrapLine)&&(r.wrapLine=function(e,r,t,n){return void 0===n&&(n=!1),this.selectLine(n).wrap(e,r,t)}),e.on("key.down",b).on("put.down",y).record()},detach:function(){return this.off("key.down",b).off("put.down",y)},name:"TextEditor.Source"};return L}));
|
package/index.mjs
CHANGED
@@ -222,6 +222,11 @@ function onKeyDown(e) {
|
|
222
222
|
return;
|
223
223
|
}
|
224
224
|
|
225
|
+
// Partial mobile support
|
226
|
+
function onPutDown(e) {
|
227
|
+
onKeyDown.call(this, e);
|
228
|
+
}
|
229
|
+
|
225
230
|
function attach() {
|
226
231
|
const $ = this;
|
227
232
|
const $$ = $.constructor._;
|
@@ -309,11 +314,11 @@ function attach() {
|
|
309
314
|
!isFunction($$.wrapLine) && ($$.wrapLine = function (open, close, wrap, withSpaces = false) {
|
310
315
|
return this.selectLine(withSpaces).wrap(open, close, wrap);
|
311
316
|
});
|
312
|
-
return $.on('key.down', onKeyDown).record();
|
317
|
+
return $.on('key.down', onKeyDown).on('put.down', onPutDown).record();
|
313
318
|
}
|
314
319
|
|
315
320
|
function detach() {
|
316
|
-
return this.off('key.down', onKeyDown);
|
321
|
+
return this.off('key.down', onKeyDown).off('put.down', onPutDown);
|
317
322
|
}
|
318
323
|
|
319
324
|
export default {attach, detach, name};
|
package/package.json
CHANGED