@taufik-nurrohman/text-editor.source 2.2.8 → 2.2.9
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +3 -3
- package/index.min.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
@@ -37,12 +37,12 @@
|
|
37
37
|
return 'undefined' !== typeof x;
|
38
38
|
};
|
39
39
|
var isInstance = function isInstance(x, of) {
|
40
|
-
return x && isSet
|
40
|
+
return x && isSet(of) && x instanceof of ;
|
41
41
|
};
|
42
42
|
var isNull = function isNull(x) {
|
43
43
|
return null === x;
|
44
44
|
};
|
45
|
-
var isSet
|
45
|
+
var isSet = function isSet(x) {
|
46
46
|
return isDefined(x) && !isNull(x);
|
47
47
|
};
|
48
48
|
var isString = function isString(x) {
|
@@ -75,7 +75,7 @@
|
|
75
75
|
}
|
76
76
|
// No need to escape `/` in the pattern string
|
77
77
|
pattern = pattern.replace(/\//g, '\\/');
|
78
|
-
return new RegExp(pattern, isSet
|
78
|
+
return new RegExp(pattern, isSet(opt) ? opt : 'g');
|
79
79
|
};
|
80
80
|
var pairs = {
|
81
81
|
'`': '`',
|
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?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).TE=e.TE||{},e.TE.Source={}))}(this,(function(e){"use strict";var r=function(e,r){return-1!==r.indexOf(e)},t=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},n=function(e){return e.length},i=window,o=function(e){return n=RegExp,(r=e)&&t(n)&&r instanceof n;var r,n},a=function(e,r){return o(e)?e:(e=e.replace(/\//g,"\\/"),RegExp(e,t(r)?r:"g"))};function
|
26
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).TE=e.TE||{},e.TE.Source={}))}(this,(function(e){"use strict";var r=function(e,r){return-1!==r.indexOf(e)},t=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},n=function(e){return e.length},i=window,o=function(e){return n=RegExp,(r=e)&&t(n)&&r instanceof n;var r,n},a=function(e,r){return o(e)?e:(e=e.replace(/\//g,"\\/"),RegExp(e,t(r)?r:"g"))};function u(e,r){return new Promise((function(t,n){var o=i[e].apply(i,r);return o?t(o):n(o)}))}var s={source:{pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"},type:null}};["alert","confirm","prompt"].forEach((function(e){s.source[e]=function(){for(var r=arguments.length,t=Array(r),n=0;n<r;n++)t[n]=arguments[n];return u(e,t)}}));var c={};c.toggle=function(e,r,i,o){void 0===o&&(o=!1),r||""===r||(r=e);var a=this,u=a.$(),s=u.after,c=u.before,f=u.value,l=n(r),p=n(e);return i&&r===f.slice(-l)&&e===f.slice(0,p)||r===s.slice(0,l)&&e===c.slice(-p)?a.peel(e,r,i):(!1!==o&&("string"==typeof o?o=[o,o]:function(e){return Array.isArray(e)}(o)||(o=["",""]),t(o[1])||(o[1]=o[0]),a.trim(o[0],o[1])),a.wrap(e,r,i))};var f="Control-";var l,p,d,v=(l=function(e){return e.record()},p=100,function(){var e=arguments,r=this;d&&clearTimeout(d),d=setTimeout((function(){return l.apply(r,e)}),p)});var h=s;e.canKeyDown=function(e,t){var n,i,o=t.state.source.tab||t.state.tab||"\t",a=t.state.source.pairs||{},u=Object.values(a),s=e.key,c=e.queue,f=e+"";if(c.Alt||c.Control)return!0;if(" "===f){var l=t.$(),p=l.after,d=l.before,v=l.value;return n=a[i=d.slice(-1)],!(!v&&n&&i&&n===p[0])||(t.wrap(" "," "),!1)}if("Enter"===f){var h=t.$(),y=h.after,w=h.before,b=h.value,m=w.split("\n").pop().match(/^(\s+)/),$=m&&m[1]||"";if(!b){if(y&&w&&(n=a[i=w.slice(-1)])&&n===y[0])return t.wrap("\n"+$+(i!==n?o:""),"\n"+$).record(),!1;if($)return t.insert("\n"+$,-1).record(),!1}return!0}if("Backspace"===f){var g=t.$(),T=g.after,E=g.before,A=g.value;T.split("\n")[0];var D=E.split("\n").pop(),K=D.match(/^(\s+)/),W=K&&K[1]||"";return n=a[i=E.slice(-1)],"\\"===i?!0:A?!(T&&E&&n&&n===T[0]&&!E.endsWith("\\"+i))||(t.record().peel(i,n).record(),!1):(n=a[i=E.trim().slice(-1)])&&i&&(T.startsWith(" "+n)&&E.endsWith(i+" ")||T.startsWith("\n"+W+n)&&E.endsWith(i+"\n"+W))?(t.trim("","").record(),!1):D.endsWith(o)?(t.pull(o).record(),!1):!(T&&E&&!E.endsWith("\\"+i)&&n===T[0]&&i===E.slice(-1))||(t.peel(i,n).record(),!1)}var k=t.$(),x=k.after,j=k.before,q=k.start,C=k.value;if("\\"===(i=j.slice(-1)))return!0;if(n=r(x[0],u)?x[0]:a[i],!C&&x&&j&&n&&s===n)return t.select(q+1).record(),!1;for(i in a){if(n=a[i],s===i&&n)return t.wrap(i,n).record(),!1;if(s===n){if(C)return t.record().wrap(i,n).record(),!1;break}}return!0},e.canKeyDownDent=function(e,r){var t=r.state.source.tab||r.state.tab||"\t";e.key,e.queue;var n=e+"";return f+"]"===n?(r.push(t).record(),!1):f+"["!==n||(r.pull(t).record(),!1)},e.canKeyDownEnter=function(e,r){e.key;var t=e.queue;if(t.Control&&t.Enter){var i=r.$(),o=i.after,a=i.before,u=i.end,s=i.start,c=i.value,f=o.split("\n").shift(),l=a.split("\n").pop(),p=l.match(/^(\s+)/),d=p&&p[1]||"";if(a||o)return t.Shift?(r.select(s-n(l)).wrap(d,"\n").insert(c).record(),!1):(r.select(u+n(f)).wrap("\n"+d,"").insert(c).record(),!1)}return!0},e.canKeyDownHistory=function(e,r){var t=e+"";return f+"y"===t?(r.redo(),!1):f+"z"!==t||(r.undo(),!1)},e.canKeyDownMove=function(e,t){e.key;var i=e+"";if(!e.queue.Control)return!0;var o,u,s,c=t.$(),l=c.after,p=c.before,d=c.end,v=c.start,h=c.value,y=t.state.source.pairs||{},w=[];if(h){for(o in y)(u=y[o])&&w.push("(?:\\"+o+"(?:\\\\.|[^\\"+o+(u!==o?"\\"+u:"")+"])*\\"+u+")");if(w.push("\\w+"),w.push("\\s+"),w.push("[\\s\\S]"),f+"ArrowLeft"===i)return(s=p.match(a("("+w.join("|")+")$","")))?(t.insert("").select(v-n(s[0])).insert(h),t.record(),!1):(t.select(),!1);if(f+"ArrowRight"===i)return(s=l.match(a("^("+w.join("|")+")","")))?(t.insert("").select(d+n(s[0])-n(h)).insert(h),t.record(),!1):(t.select(),!1)}var b=l.split("\n").shift(),m=p.split("\n").pop(),$=m.match(/^(\s+)/);if($&&$[1],d+=n(b),v-=n(m),h=m+h+b,f+"ArrowUp"===i){if(!r("\n",p))return t.select(),!1;t.insert(""),t.replace(/^([^\n]*?)(\n|$)/,"$2",1),t.replace(/(^|\n)([^\n]*?)$/,"",-1);var g=t.$();return p=g.before,v=g.start,m=p.split("\n").pop(),t.select(v-=n(m)).wrap(h,"\n"),t.select(v,v+n(h)),t.record(),!1}if(f+"ArrowDown"===i){if(!r("\n",l))return t.select(),!1;t.insert(""),t.replace(/^([^\n]*?)(\n|$)/,"",1),t.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var T=t.$();return l=T.after,d=T.end,b=l.split("\n").shift(),t.select(d+=n(b)).wrap("\n",h),d+=1,t.select(d,d+n(h)),t.record(),!1}return!0},e.canKeyDownTab=function(e,r){var t=r.state.source.tab||r.state.tab||"\t",n=e+"";return"Tab"===n?(r.push(t).record(),!1):"Shift-Tab"!==n||(r.pull(t).record(),!1)},e.canKeyUp=function(e,r){return v(r),!0},e.state=h,e.that=c,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/index.mjs
CHANGED
@@ -2,7 +2,7 @@ import {W} from '@taufik-nurrohman/document';
|
|
2
2
|
import {debounce} from '@taufik-nurrohman/tick';
|
3
3
|
import {esc, escChar, toPattern} from '@taufik-nurrohman/pattern';
|
4
4
|
import {hasValue} from '@taufik-nurrohman/has';
|
5
|
-
import {isArray, isString} from '@taufik-nurrohman/is';
|
5
|
+
import {isArray, isSet, isString} from '@taufik-nurrohman/is';
|
6
6
|
import {toCount, toObjectValues} from '@taufik-nurrohman/to';
|
7
7
|
|
8
8
|
const pairs = {
|
package/package.json
CHANGED