@taufik-nurrohman/text-editor.source 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -146,7 +146,6 @@
146
146
  var name = 'TextEditor.Source';
147
147
 
148
148
  function onKeyDown(e) {
149
- var _$$state$source, _$$state$source2;
150
149
  var $ = this,
151
150
  key = $.k(false).pop(),
152
151
  // Capture the last key
@@ -157,8 +156,8 @@
157
156
  }
158
157
  var charAfter,
159
158
  charBefore,
160
- charIndent = ((_$$state$source = $.state.source) == null ? void 0 : _$$state$source.tab) || $.state.tab || '\t',
161
- charPairs = ((_$$state$source2 = $.state.source) == null ? void 0 : _$$state$source2.pairs) || {},
159
+ charIndent = $.state.tab || '\t',
160
+ charPairs = $.state.pairs || {},
162
161
  charPairsValues = toObjectValues(charPairs);
163
162
  if (isInteger(charIndent)) {
164
163
  charIndent = ' '.repeat(charIndent);
@@ -354,16 +353,14 @@
354
353
  var $ = this;
355
354
  var $$ = $.constructor.prototype;
356
355
  $.state = fromStates({
357
- source: {
358
- pairs: {
359
- '`': '`',
360
- '(': ')',
361
- '{': '}',
362
- '[': ']',
363
- '"': '"',
364
- "'": "'",
365
- '<': '>'
366
- }
356
+ pairs: {
357
+ '`': '`',
358
+ '(': ')',
359
+ '{': '}',
360
+ '[': ']',
361
+ '"': '"',
362
+ "'": "'",
363
+ '<': '>'
367
364
  }
368
365
  }, $.state);
369
366
  !isFunction($$.alert) && ($$.alert = function (hint, then) {
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){return"number"==typeof e},c=function(e,r){return void 0===r&&(r=!0),"object"==typeof e&&(!r||function(e,r){return e&&l(r)&&e instanceof r}(e,Object))},l=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},f=function(e){return e.length},u=function e(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];for(var s=t.shift(),u=0,a=f(t);u<a;++u)for(var p in t[u])if(l(s[p]))if(i(s[p])&&i(t[u][p])){s[p]=[].concat(s[p]);for(var d=0,h=f(t[u][p]);d<h;++d)n(t[u][p][d],s[p])||s[p].push(t[u][p][d])}else c(s[p])&&c(t[u][p])?s[p]=e({},s[p],t[u][p]):s[p]=t[u][p];else s[p]=t[u][p];return s},a=window,p=function(e){return e&&e.preventDefault()},d=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},h=function(e){return t=RegExp,(r=e)&&d(t)&&r instanceof t;var r,t},v=function(e,r){return h(e)?e:RegExp(e,d(r)?r:"g")},w="Control-",k="Shift-",$=(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,t,i=this,o=i.k(!1).pop(),c=i.k();if($(i),!e.defaultPrevented&&!i.keys[c]){var l,u,a=(null==(r=i.state.source)?void 0:r.tab)||i.state.tab||"\t",d=(null==(t=i.state.source)?void 0:t.pairs)||{},h=Object.values(d);(function(e){return s(e)&&0==e%1})(a)&&(a=" ".repeat(a));var b=i.$(),m=b.after,g=b.before,x=b.end,y=b.start,B=b.value,E=m.split("\n").shift(),A=g.split("\n").pop(),T=/^\s+/.exec(A),W=T&&T[0]||"";if(w+k+"Enter"===c)return g||m?(p(e),i.select(y-f(A)).wrap(W,"\n").insert(B).record(),!1):void 0;if(w+"Enter"===c&&(g||m))return p(e),i.select(x+f(E)).wrap("\n"+W,"").insert(B).record(),!1;if("Alt-"!=c+"-"&&w!==c+"-"){if(" "===c)return l=d[u=g.slice(-1)],!B&&l&&u&&l===m[0]?(p(e),i.wrap(" "," ")):void 0;if("Backspace"===c||"Delete"===c){if(l=d[u=g.slice(-1)],"\\"===u)return;return B?m&&g&&l&&l===m[0]&&!g.endsWith("\\"+u)?(p(e),i.record().peel(u,l).record()):void 0:(l=d[u=g.trim().slice(-1)])&&u&&(m.startsWith(" "+l)&&g.endsWith(u+" ")||m.startsWith("\n"+W+l)&&g.endsWith(u+"\n"+W))?(p(e),i.trim("","").record()):"Delete"!==c&&A.endsWith(a)?(p(e),i.pull(a).record()):m&&g&&!g.endsWith("\\"+u)&&l===m[0]&&u===g.slice(-1)?(p(e),i.peel(u,l).record()):void 0}if("Enter"!==c&&k+"Enter"!==c){if("\\"!==(u=g.slice(-1))){if(l=n(m[0],h)?m[0]:d[u],!B&&m&&g&&l&&o===l)return p(e),i.select(y+1).record();for(u in d){if(l=d[u],o===u&&l)return p(e),i.wrap(u,l).record();if(o===l){if(B)return p(e),i.record().wrap(u,l).record();break}}var j,S,D,O=[];if(B){for(j in d)(S=d[j])&&O.push("(?:\\"+j+"(?:\\\\.|[^\\"+j+(S!==j?"\\"+S:"")+"])*\\"+S+")");if(O.push("\\w+"),O.push("\\s+"),O.push("[\\s\\S]"),w+"ArrowLeft"===c)return p(e),(D=v("("+O.join("|")+")$","").exec(g))?i.insert("").select(y-f(D[0])).insert(B).record():i.select();if(w+"ArrowRight"===c)return p(e),(D=m.match(v("^("+O.join("|")+")","")))?i.insert("").select(x+f(D[0])-f(B)).insert(B).record():i.select()}if(x+=f(E),y-=f(A),B=A+B+E,w+"ArrowUp"===c){if(p(e),!n("\n",g))return i.select();i.insert(""),i.replace(/^([^\n]*?)(\n|$)/,"$2",1),i.replace(/(^|\n)([^\n]*?)$/,"",-1);var R=i.$();return g=R.before,y=R.start,A=g.split("\n").pop(),i.select(y-=f(A)).wrap(B,"\n"),i.select(y,y+f(B)),i.record()}if(w+"ArrowDown"===c){if(p(e),!n("\n",m))return i.select();i.insert(""),i.replace(/^([^\n]*?)(\n|$)/,"",1),i.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var C=i.$();return m=C.after,x=C.end,E=m.split("\n").shift(),i.select(x+=f(E)).wrap("\n",B),x+=1,i.select(x,x+f(B)),i.record()}}}else if(!B){if(m&&g&&(l=d[u=g.slice(-1)])&&l===m[0])return p(e),i.wrap("\n"+W+(u!==l?a:""),"\n"+W).record();if(W)return p(e),i.insert("\n"+W,-1).record()}}else p(e)}}var m={attach:function(){var e=this,r=e.constructor.prototype;return e.state=u({source:{pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"}}},e.state),!o(r.alert)&&(r.alert=function(e,r){return a.alert&&a.alert(e),o(r)&&r.call(this,!0)}),!o(r.confirm)&&(r.confirm=function(e,r){return o(r)&&r.call(this,a.confirm&&a.confirm(e))}),!o(r.insertBlock)&&(r.insertBlock=function(e,r){var t=this,n=t.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(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.peelBlock)&&(r.peelBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.end,l=i.start,u=i.value,a=f(r),p=o.split("\n").shift(),d=f(p),h=s.split("\n").pop(),v=f(h),w=f(e);return t&&r===u.slice(-a)&&e===u.slice(0,w)||r===p.slice(-a)&&e===h.slice(0,w)?n.select(l-v+(t?0:w),c+d-(t?0:a)).peel(e,r,t):n.select(l,c)}),!o(r.prompt)&&(r.prompt=function(e,r,t){return o(t)&&t.call(this,!!a.prompt&&a.prompt(e,r))}),!o(r.selectBlock)&&(r.selectBlock=function(e){void 0===e&&(e=!0);var r=this,t=r.$(),n=t.after,i=t.before,o=t.end,s=t.start,c=t.value,l=n.split("\n").shift(),u=f(l),a=i.split("\n").pop(),p=f(a);if(!e){var d=/\s+$/.exec(l),h=/^\s+/.exec(a);d&&(u-=f(d[0])),h&&(p-=f(h[0]))}if(r.select(s-p,o+u),!e){var v,w=r.$();if(o=w.end,s=w.start,c=w.value,v=/^(\s+)?[\s\S]+?(\s+)?$/.exec(c))return r.select(s+f(v[1]||""),o-f(v[2]||""))}return r}),!o(r.toggle)&&(r.toggle=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,u)||r===o.slice(0,l)&&e===s.slice(-u)?n.peel(e,r,t):n.wrap(e,r,t)}),!o(r.toggleBlock)&&(r.toggleBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=o.split("\n").shift(),a=s.split("\n").pop(),p=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,p)||r===u.slice(-l)&&e===a.slice(0,p)?n.peelBlock(e,r,t):n.wrapBlock(e,r,t)}),!o(r.wrapBlock)&&(r.wrapBlock=function(e,r,t){var n=this.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(a);return this.select(c-p,s+u).wrap(e,r,t)}),e.on("key.down",b).record()},detach:function(){return this.off("key.down",b)},name:"TextEditor.Source"};return m}));
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){return"number"==typeof e},c=function(e,r){return void 0===r&&(r=!0),"object"==typeof e&&(!r||function(e,r){return e&&l(r)&&e instanceof r}(e,Object))},l=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},f=function(e){return e.length},u=function e(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];for(var s=t.shift(),u=0,a=f(t);u<a;++u)for(var p in t[u])if(l(s[p]))if(i(s[p])&&i(t[u][p])){s[p]=[].concat(s[p]);for(var d=0,h=f(t[u][p]);d<h;++d)n(t[u][p][d],s[p])||s[p].push(t[u][p][d])}else c(s[p])&&c(t[u][p])?s[p]=e({},s[p],t[u][p]):s[p]=t[u][p];else s[p]=t[u][p];return s},a=window,p=function(e){return e&&e.preventDefault()},d=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},h=function(e){return t=RegExp,(r=e)&&d(t)&&r instanceof t;var r,t},v=function(e,r){return h(e)?e:RegExp(e,d(r)?r:"g")},w="Control-",k="Shift-",$=(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 m(e){var r=this,t=r.k(!1).pop(),i=r.k();if($(r),!e.defaultPrevented&&!r.keys[i]){var o,c,l=r.state.tab||"\t",u=r.state.pairs||{},a=Object.values(u);(function(e){return s(e)&&0==e%1})(l)&&(l=" ".repeat(l));var d=r.$(),h=d.after,m=d.before,b=d.end,g=d.start,x=d.value,y=h.split("\n").shift(),B=m.split("\n").pop(),E=/^\s+/.exec(B),A=E&&E[0]||"";if(w+k+"Enter"===i)return m||h?(p(e),r.select(g-f(B)).wrap(A,"\n").insert(x).record(),!1):void 0;if(w+"Enter"===i&&(m||h))return p(e),r.select(b+f(y)).wrap("\n"+A,"").insert(x).record(),!1;if("Alt-"!=i+"-"&&w!==i+"-"){if(" "===i)return o=u[c=m.slice(-1)],!x&&o&&c&&o===h[0]?(p(e),r.wrap(" "," ")):void 0;if("Backspace"===i||"Delete"===i){if(o=u[c=m.slice(-1)],"\\"===c)return;return x?h&&m&&o&&o===h[0]&&!m.endsWith("\\"+c)?(p(e),r.record().peel(c,o).record()):void 0:(o=u[c=m.trim().slice(-1)])&&c&&(h.startsWith(" "+o)&&m.endsWith(c+" ")||h.startsWith("\n"+A+o)&&m.endsWith(c+"\n"+A))?(p(e),r.trim("","").record()):"Delete"!==i&&B.endsWith(l)?(p(e),r.pull(l).record()):h&&m&&!m.endsWith("\\"+c)&&o===h[0]&&c===m.slice(-1)?(p(e),r.peel(c,o).record()):void 0}if("Enter"!==i&&k+"Enter"!==i){if("\\"!==(c=m.slice(-1))){if(o=n(h[0],a)?h[0]:u[c],!x&&h&&m&&o&&t===o)return p(e),r.select(g+1).record();for(c in u){if(o=u[c],t===c&&o)return p(e),r.wrap(c,o).record();if(t===o){if(x)return p(e),r.record().wrap(c,o).record();break}}var T,W,j,S=[];if(x){for(T in u)(W=u[T])&&S.push("(?:\\"+T+"(?:\\\\.|[^\\"+T+(W!==T?"\\"+W:"")+"])*\\"+W+")");if(S.push("\\w+"),S.push("\\s+"),S.push("[\\s\\S]"),w+"ArrowLeft"===i)return p(e),(j=v("("+S.join("|")+")$","").exec(m))?r.insert("").select(g-f(j[0])).insert(x).record():r.select();if(w+"ArrowRight"===i)return p(e),(j=h.match(v("^("+S.join("|")+")","")))?r.insert("").select(b+f(j[0])-f(x)).insert(x).record():r.select()}if(b+=f(y),g-=f(B),x=B+x+y,w+"ArrowUp"===i){if(p(e),!n("\n",m))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"$2",1),r.replace(/(^|\n)([^\n]*?)$/,"",-1);var D=r.$();return m=D.before,g=D.start,B=m.split("\n").pop(),r.select(g-=f(B)).wrap(x,"\n"),r.select(g,g+f(x)),r.record()}if(w+"ArrowDown"===i){if(p(e),!n("\n",h))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"",1),r.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var O=r.$();return h=O.after,b=O.end,y=h.split("\n").shift(),r.select(b+=f(y)).wrap("\n",x),b+=1,r.select(b,b+f(x)),r.record()}}}else if(!x){if(h&&m&&(o=u[c=m.slice(-1)])&&o===h[0])return p(e),r.wrap("\n"+A+(c!==o?l:""),"\n"+A).record();if(A)return p(e),r.insert("\n"+A,-1).record()}}else p(e)}}var b={attach:function(){var e=this,r=e.constructor.prototype;return e.state=u({pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"}},e.state),!o(r.alert)&&(r.alert=function(e,r){return a.alert&&a.alert(e),o(r)&&r.call(this,!0)}),!o(r.confirm)&&(r.confirm=function(e,r){return o(r)&&r.call(this,a.confirm&&a.confirm(e))}),!o(r.insertBlock)&&(r.insertBlock=function(e,r){var t=this,n=t.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(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.peelBlock)&&(r.peelBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.end,l=i.start,u=i.value,a=f(r),p=o.split("\n").shift(),d=f(p),h=s.split("\n").pop(),v=f(h),w=f(e);return t&&r===u.slice(-a)&&e===u.slice(0,w)||r===p.slice(-a)&&e===h.slice(0,w)?n.select(l-v+(t?0:w),c+d-(t?0:a)).peel(e,r,t):n.select(l,c)}),!o(r.prompt)&&(r.prompt=function(e,r,t){return o(t)&&t.call(this,!!a.prompt&&a.prompt(e,r))}),!o(r.selectBlock)&&(r.selectBlock=function(e){void 0===e&&(e=!0);var r=this,t=r.$(),n=t.after,i=t.before,o=t.end,s=t.start,c=t.value,l=n.split("\n").shift(),u=f(l),a=i.split("\n").pop(),p=f(a);if(!e){var d=/\s+$/.exec(l),h=/^\s+/.exec(a);d&&(u-=f(d[0])),h&&(p-=f(h[0]))}if(r.select(s-p,o+u),!e){var v,w=r.$();if(o=w.end,s=w.start,c=w.value,v=/^(\s+)?[\s\S]+?(\s+)?$/.exec(c))return r.select(s+f(v[1]||""),o-f(v[2]||""))}return r}),!o(r.toggle)&&(r.toggle=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,u)||r===o.slice(0,l)&&e===s.slice(-u)?n.peel(e,r,t):n.wrap(e,r,t)}),!o(r.toggleBlock)&&(r.toggleBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=o.split("\n").shift(),a=s.split("\n").pop(),p=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,p)||r===u.slice(-l)&&e===a.slice(0,p)?n.peelBlock(e,r,t):n.wrapBlock(e,r,t)}),!o(r.wrapBlock)&&(r.wrapBlock=function(e,r,t){var n=this.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(a);return this.select(c-p,s+u).wrap(e,r,t)}),e.on("key.down",m).record()},detach:function(){return this.off("key.down",m)},name:"TextEditor.Source"};return b}));
package/index.mjs CHANGED
@@ -24,8 +24,8 @@ function onKeyDown(e) {
24
24
  }
25
25
  let charAfter,
26
26
  charBefore,
27
- charIndent = $.state.source?.tab || $.state.tab || '\t',
28
- charPairs = $.state.source?.pairs || {},
27
+ charIndent = $.state.tab || '\t',
28
+ charPairs = $.state.pairs || {},
29
29
  charPairsValues = toObjectValues(charPairs);
30
30
  if (isInteger(charIndent)) {
31
31
  charIndent = ' '.repeat(charIndent);
@@ -218,16 +218,14 @@ function attach() {
218
218
  const $ = this;
219
219
  const $$ = $.constructor.prototype;
220
220
  $.state = fromStates({
221
- source: {
222
- pairs: {
223
- '`': '`',
224
- '(': ')',
225
- '{': '}',
226
- '[': ']',
227
- '"': '"',
228
- "'": "'",
229
- '<': '>'
230
- }
221
+ pairs: {
222
+ '`': '`',
223
+ '(': ')',
224
+ '{': '}',
225
+ '[': ']',
226
+ '"': '"',
227
+ "'": "'",
228
+ '<': '>'
231
229
  }
232
230
  }, $.state);
233
231
  !isFunction($$.alert) && ($$.alert = function (hint, then) {
package/package.json CHANGED
@@ -53,5 +53,5 @@
53
53
  "scripts": {
54
54
  "pack": "pack --clean=false --from=.factory --js-format=umd --js-name=TextEditor.Source --js-top='%(js.license)' --mjs=true --to=."
55
55
  },
56
- "version": "3.0.2"
56
+ "version": "3.0.3"
57
57
  }