vue-prism-editor
Advanced tools
Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.1
# vue-prism-editor | ||
## 2.0.0-alpha.1 | ||
### Minor Changes | ||
- fix: linenumbers | ||
## 2.0.0-alpha.0 | ||
@@ -4,0 +10,0 @@ |
@@ -504,5 +504,3 @@ 'use strict'; | ||
return vue.h('div', { | ||
attrs: { | ||
"class": 'prism-editor__line-number token comment' | ||
} | ||
"class": 'prism-editor__line-number token comment' | ||
}, "" + ++index); | ||
@@ -509,0 +507,0 @@ })]); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vue");function e(){return(e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}var i="navigator"in global&&/Win/i.test(navigator.platform),s="navigator"in global&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),n=t.defineComponent({props:{lineNumbers:{type:Boolean,default:!1},autoStyleLineNumbers:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1},modelValue:{type:String,default:""},highlight:{type:Function,required:!0},tabSize:{type:Number,default:2},insertSpaces:{type:Boolean,default:!0},ignoreTabKey:{type:Boolean,default:!1},placeholder:{type:String,default:""}},data:function(){return{capture:!0,history:{stack:[],offset:-1},lineNumbersHeight:"20px",codeData:""}},watch:{modelValue:{immediate:!0,handler:function(t){this.codeData=t||""}},content:{immediate:!0,handler:function(){var t=this;this.lineNumbers&&this.$nextTick((function(){t.setLineNumbersHeight()}))}},lineNumbers:function(){var t=this;this.$nextTick((function(){t.styleLineNumbers(),t.setLineNumbersHeight()}))}},computed:{isEmpty:function(){return 0===this.codeData.length},content:function(){return this.highlight(this.codeData)+"<br />"},lineNumbersCount:function(){return this.codeData.split(/\r\n|\n/).length}},mounted:function(){this._recordCurrentState(),this.styleLineNumbers()},methods:{setLineNumbersHeight:function(){this.lineNumbersHeight=getComputedStyle(this.$refs.pre).height},styleLineNumbers:function(){if(this.lineNumbers&&this.autoStyleLineNumbers){var t=this.$refs.pre,e=this.$el.querySelector(".prism-editor__line-numbers"),i=window.getComputedStyle(t);this.$nextTick((function(){var s="border-top-left-radius",n="border-bottom-left-radius";e&&(e.style[s]=i[s],e.style[n]=i[n],t.style[s]="0",t.style[n]="0",["background-color","margin-top","padding-top","font-family","font-size","line-height"].forEach((function(t){e.style[t]=i[t]})),e.style["margin-bottom"]="-"+i["padding-top"])}))}},_recordCurrentState:function(){var t=this.$refs.textarea;t&&this._recordChange({value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})},_getLines:function(t,e){return t.substring(0,e).split("\n")},_applyEdits:function(t){var i=this.$refs.textarea,s=this.history.stack[this.history.offset];s&&i&&(this.history.stack[this.history.offset]=e({},s,{selectionStart:i.selectionStart,selectionEnd:i.selectionEnd})),this._recordChange(t),this._updateInput(t)},_recordChange:function(t,i){void 0===i&&(i=!1);var s=this.history,n=s.stack,r=s.offset;if(n.length&&r>-1){this.history.stack=n.slice(0,r+1);var a=this.history.stack.length;if(a>100){var o=a-100;this.history.stack=n.slice(o,a),this.history.offset=Math.max(this.history.offset-o,0)}}var l=Date.now();if(i){var h=this.history.stack[this.history.offset];if(h&&l-h.timestamp<3e3){var u,d,c=/[^a-z0-9]([a-z0-9]+)$/i,f=null===(u=this._getLines(h.value,h.selectionStart).pop())||void 0===u?void 0:u.match(c),p=null===(d=this._getLines(t.value,t.selectionStart).pop())||void 0===d?void 0:d.match(c);if(f&&p&&p[1].startsWith(f[1]))return void(this.history.stack[this.history.offset]=e({},t,{timestamp:l}))}}this.history.stack.push(e({},t,{timestamp:l})),this.history.offset++},_updateInput:function(t){var e=this.$refs.textarea;e&&(e.value=t.value,e.selectionStart=t.selectionStart,e.selectionEnd=t.selectionEnd,this.$emit("update:modelValue",t.value))},handleChange:function(t){var e=t.target,i=e.value;this._recordChange({value:i,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},!0),this.$emit("update:modelValue",i)},_undoEdit:function(){var t=this.history,e=t.offset,i=t.stack[e-1];i&&(this._updateInput(i),this.history.offset=Math.max(e-1,0))},_redoEdit:function(){var t=this.history,e=t.stack,i=t.offset,s=e[i+1];s&&(this._updateInput(s),this.history.offset=Math.min(i+1,e.length-1))},handleKeyDown:function(t){var e=this.tabSize,n=this.insertSpaces,r=this.ignoreTabKey;if(this.$emit("keydown",t),!t.defaultPrevented){27===t.keyCode&&(t.target.blur(),this.$emit("blur",t));var a=t.target,o=a.value,l=a.selectionStart,h=a.selectionEnd,u=(n?" ":"\t").repeat(e);if(9===t.keyCode&&!r&&this.capture)if(t.preventDefault(),t.shiftKey){var d=this._getLines(o,l),c=d.length-1,f=this._getLines(o,h).length-1,p=o.split("\n").map((function(t,e){return e>=c&&e<=f&&t.startsWith(u)?t.substring(u.length):t})).join("\n");o!==p&&this._applyEdits({value:p,selectionStart:d[c].startsWith(u)?l-u.length:l,selectionEnd:h-(o.length-p.length)})}else if(l!==h){var y=this._getLines(o,l),m=y.length-1,g=this._getLines(o,h).length-1,v=y[m];this._applyEdits({value:o.split("\n").map((function(t,e){return e>=m&&e<=g?u+t:t})).join("\n"),selectionStart:/\S/.test(v)?l+u.length:l,selectionEnd:h+u.length*(g-m+1)})}else{var b=l+u.length;this._applyEdits({value:o.substring(0,l)+u+o.substring(h),selectionStart:b,selectionEnd:b})}else if(8===t.keyCode){var _=l!==h;if(o.substring(0,l).endsWith(u)&&!_){t.preventDefault();var k=l-u.length;this._applyEdits({value:o.substring(0,l-u.length)+o.substring(h),selectionStart:k,selectionEnd:k})}}else if(13===t.keyCode){if(l===h){var C=this._getLines(o,l).pop(),S=null==C?void 0:C.match(/^\s+/);if(S&&S[0]){t.preventDefault();var E="\n"+S[0],K=l+E.length;this._applyEdits({value:o.substring(0,l)+E+o.substring(h),selectionStart:K,selectionEnd:K})}}}else if(57===t.keyCode||219===t.keyCode||222===t.keyCode||192===t.keyCode){var N;57===t.keyCode&&t.shiftKey?N=["(",")"]:219===t.keyCode?N=t.shiftKey?["{","}"]:["[","]"]:222===t.keyCode?N=t.shiftKey?['"','"']:["'","'"]:192!==t.keyCode||t.shiftKey||(N=["`","`"]),l!==h&&N&&(t.preventDefault(),this._applyEdits({value:o.substring(0,l)+N[0]+o.substring(l,h)+N[1]+o.substring(h),selectionStart:l,selectionEnd:h+2}))}else!(s?t.metaKey&&90===t.keyCode:t.ctrlKey&&90===t.keyCode)||t.shiftKey||t.altKey?(s?t.metaKey&&90===t.keyCode&&t.shiftKey:i?t.ctrlKey&&89===t.keyCode:t.ctrlKey&&90===t.keyCode&&t.shiftKey)&&!t.altKey?(t.preventDefault(),this._redoEdit()):77!==t.keyCode||!t.ctrlKey||s&&!t.shiftKey||(t.preventDefault(),this.capture=!this.capture):(t.preventDefault(),this._undoEdit())}}},render:function(){var e=this,i=t.h("div",{class:"prism-editor__line-width-calc",style:"height: 0px; visibility: hidden; pointer-events: none;"},"999"),s=t.h("div",{class:"prism-editor__line-numbers",style:{"min-height":this.lineNumbersHeight},"aria-hidden":"true"},[i,Array.from(Array(this.lineNumbersCount).keys()).map((function(e,i){return t.h("div",{attrs:{class:"prism-editor__line-number token comment"}},""+ ++i)}))]),n=t.h("textarea",{ref:"textarea",onInput:this.handleChange,onKeydown:this.handleKeyDown,onClick:function(t){e.$emit("click",t)},onKeyup:function(t){e.$emit("keyup",t)},onFocus:function(t){e.$emit("focus",t)},onBlur:function(t){e.$emit("blur",t)},class:{"prism-editor__textarea":!0,"prism-editor__textarea--empty":this.isEmpty},spellCheck:"false",autocapitalize:"off",autocomplete:"off",autocorrect:"off","data-gramm":"false",placeholder:this.placeholder,"data-testid":"textarea",readonly:this.readonly,value:this.codeData}),r=t.h("pre",{ref:"pre",class:"prism-editor__editor","data-testid":"preview",innerHTML:this.content}),a=t.h("div",{class:"prism-editor__container"},[n,r]);return t.h("div",{class:"prism-editor-wrapper"},[this.lineNumbers&&s,a])}});exports.PrismEditor=n; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vue");function e(){return(e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}var i="navigator"in global&&/Win/i.test(navigator.platform),s="navigator"in global&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),n=t.defineComponent({props:{lineNumbers:{type:Boolean,default:!1},autoStyleLineNumbers:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1},modelValue:{type:String,default:""},highlight:{type:Function,required:!0},tabSize:{type:Number,default:2},insertSpaces:{type:Boolean,default:!0},ignoreTabKey:{type:Boolean,default:!1},placeholder:{type:String,default:""}},data:function(){return{capture:!0,history:{stack:[],offset:-1},lineNumbersHeight:"20px",codeData:""}},watch:{modelValue:{immediate:!0,handler:function(t){this.codeData=t||""}},content:{immediate:!0,handler:function(){var t=this;this.lineNumbers&&this.$nextTick((function(){t.setLineNumbersHeight()}))}},lineNumbers:function(){var t=this;this.$nextTick((function(){t.styleLineNumbers(),t.setLineNumbersHeight()}))}},computed:{isEmpty:function(){return 0===this.codeData.length},content:function(){return this.highlight(this.codeData)+"<br />"},lineNumbersCount:function(){return this.codeData.split(/\r\n|\n/).length}},mounted:function(){this._recordCurrentState(),this.styleLineNumbers()},methods:{setLineNumbersHeight:function(){this.lineNumbersHeight=getComputedStyle(this.$refs.pre).height},styleLineNumbers:function(){if(this.lineNumbers&&this.autoStyleLineNumbers){var t=this.$refs.pre,e=this.$el.querySelector(".prism-editor__line-numbers"),i=window.getComputedStyle(t);this.$nextTick((function(){var s="border-top-left-radius",n="border-bottom-left-radius";e&&(e.style[s]=i[s],e.style[n]=i[n],t.style[s]="0",t.style[n]="0",["background-color","margin-top","padding-top","font-family","font-size","line-height"].forEach((function(t){e.style[t]=i[t]})),e.style["margin-bottom"]="-"+i["padding-top"])}))}},_recordCurrentState:function(){var t=this.$refs.textarea;t&&this._recordChange({value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})},_getLines:function(t,e){return t.substring(0,e).split("\n")},_applyEdits:function(t){var i=this.$refs.textarea,s=this.history.stack[this.history.offset];s&&i&&(this.history.stack[this.history.offset]=e({},s,{selectionStart:i.selectionStart,selectionEnd:i.selectionEnd})),this._recordChange(t),this._updateInput(t)},_recordChange:function(t,i){void 0===i&&(i=!1);var s=this.history,n=s.stack,r=s.offset;if(n.length&&r>-1){this.history.stack=n.slice(0,r+1);var a=this.history.stack.length;if(a>100){var o=a-100;this.history.stack=n.slice(o,a),this.history.offset=Math.max(this.history.offset-o,0)}}var l=Date.now();if(i){var h=this.history.stack[this.history.offset];if(h&&l-h.timestamp<3e3){var u,d,c=/[^a-z0-9]([a-z0-9]+)$/i,f=null===(u=this._getLines(h.value,h.selectionStart).pop())||void 0===u?void 0:u.match(c),p=null===(d=this._getLines(t.value,t.selectionStart).pop())||void 0===d?void 0:d.match(c);if(f&&p&&p[1].startsWith(f[1]))return void(this.history.stack[this.history.offset]=e({},t,{timestamp:l}))}}this.history.stack.push(e({},t,{timestamp:l})),this.history.offset++},_updateInput:function(t){var e=this.$refs.textarea;e&&(e.value=t.value,e.selectionStart=t.selectionStart,e.selectionEnd=t.selectionEnd,this.$emit("update:modelValue",t.value))},handleChange:function(t){var e=t.target,i=e.value;this._recordChange({value:i,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},!0),this.$emit("update:modelValue",i)},_undoEdit:function(){var t=this.history,e=t.offset,i=t.stack[e-1];i&&(this._updateInput(i),this.history.offset=Math.max(e-1,0))},_redoEdit:function(){var t=this.history,e=t.stack,i=t.offset,s=e[i+1];s&&(this._updateInput(s),this.history.offset=Math.min(i+1,e.length-1))},handleKeyDown:function(t){var e=this.tabSize,n=this.insertSpaces,r=this.ignoreTabKey;if(this.$emit("keydown",t),!t.defaultPrevented){27===t.keyCode&&(t.target.blur(),this.$emit("blur",t));var a=t.target,o=a.value,l=a.selectionStart,h=a.selectionEnd,u=(n?" ":"\t").repeat(e);if(9===t.keyCode&&!r&&this.capture)if(t.preventDefault(),t.shiftKey){var d=this._getLines(o,l),c=d.length-1,f=this._getLines(o,h).length-1,p=o.split("\n").map((function(t,e){return e>=c&&e<=f&&t.startsWith(u)?t.substring(u.length):t})).join("\n");o!==p&&this._applyEdits({value:p,selectionStart:d[c].startsWith(u)?l-u.length:l,selectionEnd:h-(o.length-p.length)})}else if(l!==h){var y=this._getLines(o,l),m=y.length-1,g=this._getLines(o,h).length-1,v=y[m];this._applyEdits({value:o.split("\n").map((function(t,e){return e>=m&&e<=g?u+t:t})).join("\n"),selectionStart:/\S/.test(v)?l+u.length:l,selectionEnd:h+u.length*(g-m+1)})}else{var b=l+u.length;this._applyEdits({value:o.substring(0,l)+u+o.substring(h),selectionStart:b,selectionEnd:b})}else if(8===t.keyCode){var _=l!==h;if(o.substring(0,l).endsWith(u)&&!_){t.preventDefault();var k=l-u.length;this._applyEdits({value:o.substring(0,l-u.length)+o.substring(h),selectionStart:k,selectionEnd:k})}}else if(13===t.keyCode){if(l===h){var C=this._getLines(o,l).pop(),S=null==C?void 0:C.match(/^\s+/);if(S&&S[0]){t.preventDefault();var E="\n"+S[0],K=l+E.length;this._applyEdits({value:o.substring(0,l)+E+o.substring(h),selectionStart:K,selectionEnd:K})}}}else if(57===t.keyCode||219===t.keyCode||222===t.keyCode||192===t.keyCode){var N;57===t.keyCode&&t.shiftKey?N=["(",")"]:219===t.keyCode?N=t.shiftKey?["{","}"]:["[","]"]:222===t.keyCode?N=t.shiftKey?['"','"']:["'","'"]:192!==t.keyCode||t.shiftKey||(N=["`","`"]),l!==h&&N&&(t.preventDefault(),this._applyEdits({value:o.substring(0,l)+N[0]+o.substring(l,h)+N[1]+o.substring(h),selectionStart:l,selectionEnd:h+2}))}else!(s?t.metaKey&&90===t.keyCode:t.ctrlKey&&90===t.keyCode)||t.shiftKey||t.altKey?(s?t.metaKey&&90===t.keyCode&&t.shiftKey:i?t.ctrlKey&&89===t.keyCode:t.ctrlKey&&90===t.keyCode&&t.shiftKey)&&!t.altKey?(t.preventDefault(),this._redoEdit()):77!==t.keyCode||!t.ctrlKey||s&&!t.shiftKey||(t.preventDefault(),this.capture=!this.capture):(t.preventDefault(),this._undoEdit())}}},render:function(){var e=this,i=t.h("div",{class:"prism-editor__line-width-calc",style:"height: 0px; visibility: hidden; pointer-events: none;"},"999"),s=t.h("div",{class:"prism-editor__line-numbers",style:{"min-height":this.lineNumbersHeight},"aria-hidden":"true"},[i,Array.from(Array(this.lineNumbersCount).keys()).map((function(e,i){return t.h("div",{class:"prism-editor__line-number token comment"},""+ ++i)}))]),n=t.h("textarea",{ref:"textarea",onInput:this.handleChange,onKeydown:this.handleKeyDown,onClick:function(t){e.$emit("click",t)},onKeyup:function(t){e.$emit("keyup",t)},onFocus:function(t){e.$emit("focus",t)},onBlur:function(t){e.$emit("blur",t)},class:{"prism-editor__textarea":!0,"prism-editor__textarea--empty":this.isEmpty},spellCheck:"false",autocapitalize:"off",autocomplete:"off",autocorrect:"off","data-gramm":"false",placeholder:this.placeholder,"data-testid":"textarea",readonly:this.readonly,value:this.codeData}),r=t.h("pre",{ref:"pre",class:"prism-editor__editor","data-testid":"preview",innerHTML:this.content}),a=t.h("div",{class:"prism-editor__container"},[n,r]);return t.h("div",{class:"prism-editor-wrapper"},[this.lineNumbers&&s,a])}});exports.PrismEditor=n; | ||
//# sourceMappingURL=prismeditor.cjs.production.min.js.map |
@@ -500,5 +500,3 @@ import { defineComponent, h } from 'vue'; | ||
return h('div', { | ||
attrs: { | ||
"class": 'prism-editor__line-number token comment' | ||
} | ||
"class": 'prism-editor__line-number token comment' | ||
}, "" + ++index); | ||
@@ -505,0 +503,0 @@ })]); |
@@ -506,5 +506,3 @@ (function (global, factory) { | ||
return vue.h('div', { | ||
attrs: { | ||
"class": 'prism-editor__line-number token comment' | ||
} | ||
"class": 'prism-editor__line-number token comment' | ||
}, "" + ++index); | ||
@@ -511,0 +509,0 @@ })]); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((t=t||self).PrismEditor={},t.vue)}(this,(function(t,e){"use strict";var i=void 0!==typeof self?self:this;function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}var n="navigator"in i&&/Win/i.test(navigator.platform),r="navigator"in i&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),o=e.defineComponent({props:{lineNumbers:{type:Boolean,default:!1},autoStyleLineNumbers:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1},modelValue:{type:String,default:""},highlight:{type:Function,required:!0},tabSize:{type:Number,default:2},insertSpaces:{type:Boolean,default:!0},ignoreTabKey:{type:Boolean,default:!1},placeholder:{type:String,default:""}},data:function(){return{capture:!0,history:{stack:[],offset:-1},lineNumbersHeight:"20px",codeData:""}},watch:{modelValue:{immediate:!0,handler:function(t){this.codeData=t||""}},content:{immediate:!0,handler:function(){var t=this;this.lineNumbers&&this.$nextTick((function(){t.setLineNumbersHeight()}))}},lineNumbers:function(){var t=this;this.$nextTick((function(){t.styleLineNumbers(),t.setLineNumbersHeight()}))}},computed:{isEmpty:function(){return 0===this.codeData.length},content:function(){return this.highlight(this.codeData)+"<br />"},lineNumbersCount:function(){return this.codeData.split(/\r\n|\n/).length}},mounted:function(){this._recordCurrentState(),this.styleLineNumbers()},methods:{setLineNumbersHeight:function(){this.lineNumbersHeight=getComputedStyle(this.$refs.pre).height},styleLineNumbers:function(){if(this.lineNumbers&&this.autoStyleLineNumbers){var t=this.$refs.pre,e=this.$el.querySelector(".prism-editor__line-numbers"),i=window.getComputedStyle(t);this.$nextTick((function(){var s="border-top-left-radius",n="border-bottom-left-radius";e&&(e.style[s]=i[s],e.style[n]=i[n],t.style[s]="0",t.style[n]="0",["background-color","margin-top","padding-top","font-family","font-size","line-height"].forEach((function(t){e.style[t]=i[t]})),e.style["margin-bottom"]="-"+i["padding-top"])}))}},_recordCurrentState:function(){var t=this.$refs.textarea;t&&this._recordChange({value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})},_getLines:function(t,e){return t.substring(0,e).split("\n")},_applyEdits:function(t){var e=this.$refs.textarea,i=this.history.stack[this.history.offset];i&&e&&(this.history.stack[this.history.offset]=s({},i,{selectionStart:e.selectionStart,selectionEnd:e.selectionEnd})),this._recordChange(t),this._updateInput(t)},_recordChange:function(t,e){void 0===e&&(e=!1);var i=this.history,n=i.stack,r=i.offset;if(n.length&&r>-1){this.history.stack=n.slice(0,r+1);var o=this.history.stack.length;if(o>100){var a=o-100;this.history.stack=n.slice(a,o),this.history.offset=Math.max(this.history.offset-a,0)}}var l=Date.now();if(e){var h=this.history.stack[this.history.offset];if(h&&l-h.timestamp<3e3){var u,d,c=/[^a-z0-9]([a-z0-9]+)$/i,f=null===(u=this._getLines(h.value,h.selectionStart).pop())||void 0===u?void 0:u.match(c),p=null===(d=this._getLines(t.value,t.selectionStart).pop())||void 0===d?void 0:d.match(c);if(f&&p&&p[1].startsWith(f[1]))return void(this.history.stack[this.history.offset]=s({},t,{timestamp:l}))}}this.history.stack.push(s({},t,{timestamp:l})),this.history.offset++},_updateInput:function(t){var e=this.$refs.textarea;e&&(e.value=t.value,e.selectionStart=t.selectionStart,e.selectionEnd=t.selectionEnd,this.$emit("update:modelValue",t.value))},handleChange:function(t){var e=t.target,i=e.value;this._recordChange({value:i,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},!0),this.$emit("update:modelValue",i)},_undoEdit:function(){var t=this.history,e=t.offset,i=t.stack[e-1];i&&(this._updateInput(i),this.history.offset=Math.max(e-1,0))},_redoEdit:function(){var t=this.history,e=t.stack,i=t.offset,s=e[i+1];s&&(this._updateInput(s),this.history.offset=Math.min(i+1,e.length-1))},handleKeyDown:function(t){var e=this.tabSize,i=this.insertSpaces,s=this.ignoreTabKey;if(this.$emit("keydown",t),!t.defaultPrevented){27===t.keyCode&&(t.target.blur(),this.$emit("blur",t));var o=t.target,a=o.value,l=o.selectionStart,h=o.selectionEnd,u=(i?" ":"\t").repeat(e);if(9===t.keyCode&&!s&&this.capture)if(t.preventDefault(),t.shiftKey){var d=this._getLines(a,l),c=d.length-1,f=this._getLines(a,h).length-1,p=a.split("\n").map((function(t,e){return e>=c&&e<=f&&t.startsWith(u)?t.substring(u.length):t})).join("\n");a!==p&&this._applyEdits({value:p,selectionStart:d[c].startsWith(u)?l-u.length:l,selectionEnd:h-(a.length-p.length)})}else if(l!==h){var y=this._getLines(a,l),m=y.length-1,v=this._getLines(a,h).length-1,g=y[m];this._applyEdits({value:a.split("\n").map((function(t,e){return e>=m&&e<=v?u+t:t})).join("\n"),selectionStart:/\S/.test(g)?l+u.length:l,selectionEnd:h+u.length*(v-m+1)})}else{var b=l+u.length;this._applyEdits({value:a.substring(0,l)+u+a.substring(h),selectionStart:b,selectionEnd:b})}else if(8===t.keyCode){var _=l!==h;if(a.substring(0,l).endsWith(u)&&!_){t.preventDefault();var k=l-u.length;this._applyEdits({value:a.substring(0,l-u.length)+a.substring(h),selectionStart:k,selectionEnd:k})}}else if(13===t.keyCode){if(l===h){var C=this._getLines(a,l).pop(),E=null==C?void 0:C.match(/^\s+/);if(E&&E[0]){t.preventDefault();var S="\n"+E[0],K=l+S.length;this._applyEdits({value:a.substring(0,l)+S+a.substring(h),selectionStart:K,selectionEnd:K})}}}else if(57===t.keyCode||219===t.keyCode||222===t.keyCode||192===t.keyCode){var N;57===t.keyCode&&t.shiftKey?N=["(",")"]:219===t.keyCode?N=t.shiftKey?["{","}"]:["[","]"]:222===t.keyCode?N=t.shiftKey?['"','"']:["'","'"]:192!==t.keyCode||t.shiftKey||(N=["`","`"]),l!==h&&N&&(t.preventDefault(),this._applyEdits({value:a.substring(0,l)+N[0]+a.substring(l,h)+N[1]+a.substring(h),selectionStart:l,selectionEnd:h+2}))}else!(r?t.metaKey&&90===t.keyCode:t.ctrlKey&&90===t.keyCode)||t.shiftKey||t.altKey?(r?t.metaKey&&90===t.keyCode&&t.shiftKey:n?t.ctrlKey&&89===t.keyCode:t.ctrlKey&&90===t.keyCode&&t.shiftKey)&&!t.altKey?(t.preventDefault(),this._redoEdit()):77!==t.keyCode||!t.ctrlKey||r&&!t.shiftKey||(t.preventDefault(),this.capture=!this.capture):(t.preventDefault(),this._undoEdit())}}},render:function(){var t=this,i=e.h("div",{class:"prism-editor__line-width-calc",style:"height: 0px; visibility: hidden; pointer-events: none;"},"999"),s=e.h("div",{class:"prism-editor__line-numbers",style:{"min-height":this.lineNumbersHeight},"aria-hidden":"true"},[i,Array.from(Array(this.lineNumbersCount).keys()).map((function(t,i){return e.h("div",{attrs:{class:"prism-editor__line-number token comment"}},""+ ++i)}))]),n=e.h("textarea",{ref:"textarea",onInput:this.handleChange,onKeydown:this.handleKeyDown,onClick:function(e){t.$emit("click",e)},onKeyup:function(e){t.$emit("keyup",e)},onFocus:function(e){t.$emit("focus",e)},onBlur:function(e){t.$emit("blur",e)},class:{"prism-editor__textarea":!0,"prism-editor__textarea--empty":this.isEmpty},spellCheck:"false",autocapitalize:"off",autocomplete:"off",autocorrect:"off","data-gramm":"false",placeholder:this.placeholder,"data-testid":"textarea",readonly:this.readonly,value:this.codeData}),r=e.h("pre",{ref:"pre",class:"prism-editor__editor","data-testid":"preview",innerHTML:this.content}),o=e.h("div",{class:"prism-editor__container"},[n,r]);return e.h("div",{class:"prism-editor-wrapper"},[this.lineNumbers&&s,o])}});t.PrismEditor=o,Object.defineProperty(t,"__esModule",{value:!0});let a=null;"undefined"!=typeof window?a=window.Vue:void 0!==i&&(a=i.Vue),a&&a.component("PrismEditor",o)})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((t=t||self).PrismEditor={},t.vue)}(this,(function(t,e){"use strict";var i=void 0!==typeof self?self:this;function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}var n="navigator"in i&&/Win/i.test(navigator.platform),r="navigator"in i&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),o=e.defineComponent({props:{lineNumbers:{type:Boolean,default:!1},autoStyleLineNumbers:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1},modelValue:{type:String,default:""},highlight:{type:Function,required:!0},tabSize:{type:Number,default:2},insertSpaces:{type:Boolean,default:!0},ignoreTabKey:{type:Boolean,default:!1},placeholder:{type:String,default:""}},data:function(){return{capture:!0,history:{stack:[],offset:-1},lineNumbersHeight:"20px",codeData:""}},watch:{modelValue:{immediate:!0,handler:function(t){this.codeData=t||""}},content:{immediate:!0,handler:function(){var t=this;this.lineNumbers&&this.$nextTick((function(){t.setLineNumbersHeight()}))}},lineNumbers:function(){var t=this;this.$nextTick((function(){t.styleLineNumbers(),t.setLineNumbersHeight()}))}},computed:{isEmpty:function(){return 0===this.codeData.length},content:function(){return this.highlight(this.codeData)+"<br />"},lineNumbersCount:function(){return this.codeData.split(/\r\n|\n/).length}},mounted:function(){this._recordCurrentState(),this.styleLineNumbers()},methods:{setLineNumbersHeight:function(){this.lineNumbersHeight=getComputedStyle(this.$refs.pre).height},styleLineNumbers:function(){if(this.lineNumbers&&this.autoStyleLineNumbers){var t=this.$refs.pre,e=this.$el.querySelector(".prism-editor__line-numbers"),i=window.getComputedStyle(t);this.$nextTick((function(){var s="border-top-left-radius",n="border-bottom-left-radius";e&&(e.style[s]=i[s],e.style[n]=i[n],t.style[s]="0",t.style[n]="0",["background-color","margin-top","padding-top","font-family","font-size","line-height"].forEach((function(t){e.style[t]=i[t]})),e.style["margin-bottom"]="-"+i["padding-top"])}))}},_recordCurrentState:function(){var t=this.$refs.textarea;t&&this._recordChange({value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})},_getLines:function(t,e){return t.substring(0,e).split("\n")},_applyEdits:function(t){var e=this.$refs.textarea,i=this.history.stack[this.history.offset];i&&e&&(this.history.stack[this.history.offset]=s({},i,{selectionStart:e.selectionStart,selectionEnd:e.selectionEnd})),this._recordChange(t),this._updateInput(t)},_recordChange:function(t,e){void 0===e&&(e=!1);var i=this.history,n=i.stack,r=i.offset;if(n.length&&r>-1){this.history.stack=n.slice(0,r+1);var o=this.history.stack.length;if(o>100){var a=o-100;this.history.stack=n.slice(a,o),this.history.offset=Math.max(this.history.offset-a,0)}}var l=Date.now();if(e){var h=this.history.stack[this.history.offset];if(h&&l-h.timestamp<3e3){var u,d,c=/[^a-z0-9]([a-z0-9]+)$/i,f=null===(u=this._getLines(h.value,h.selectionStart).pop())||void 0===u?void 0:u.match(c),p=null===(d=this._getLines(t.value,t.selectionStart).pop())||void 0===d?void 0:d.match(c);if(f&&p&&p[1].startsWith(f[1]))return void(this.history.stack[this.history.offset]=s({},t,{timestamp:l}))}}this.history.stack.push(s({},t,{timestamp:l})),this.history.offset++},_updateInput:function(t){var e=this.$refs.textarea;e&&(e.value=t.value,e.selectionStart=t.selectionStart,e.selectionEnd=t.selectionEnd,this.$emit("update:modelValue",t.value))},handleChange:function(t){var e=t.target,i=e.value;this._recordChange({value:i,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},!0),this.$emit("update:modelValue",i)},_undoEdit:function(){var t=this.history,e=t.offset,i=t.stack[e-1];i&&(this._updateInput(i),this.history.offset=Math.max(e-1,0))},_redoEdit:function(){var t=this.history,e=t.stack,i=t.offset,s=e[i+1];s&&(this._updateInput(s),this.history.offset=Math.min(i+1,e.length-1))},handleKeyDown:function(t){var e=this.tabSize,i=this.insertSpaces,s=this.ignoreTabKey;if(this.$emit("keydown",t),!t.defaultPrevented){27===t.keyCode&&(t.target.blur(),this.$emit("blur",t));var o=t.target,a=o.value,l=o.selectionStart,h=o.selectionEnd,u=(i?" ":"\t").repeat(e);if(9===t.keyCode&&!s&&this.capture)if(t.preventDefault(),t.shiftKey){var d=this._getLines(a,l),c=d.length-1,f=this._getLines(a,h).length-1,p=a.split("\n").map((function(t,e){return e>=c&&e<=f&&t.startsWith(u)?t.substring(u.length):t})).join("\n");a!==p&&this._applyEdits({value:p,selectionStart:d[c].startsWith(u)?l-u.length:l,selectionEnd:h-(a.length-p.length)})}else if(l!==h){var y=this._getLines(a,l),m=y.length-1,v=this._getLines(a,h).length-1,g=y[m];this._applyEdits({value:a.split("\n").map((function(t,e){return e>=m&&e<=v?u+t:t})).join("\n"),selectionStart:/\S/.test(g)?l+u.length:l,selectionEnd:h+u.length*(v-m+1)})}else{var b=l+u.length;this._applyEdits({value:a.substring(0,l)+u+a.substring(h),selectionStart:b,selectionEnd:b})}else if(8===t.keyCode){var _=l!==h;if(a.substring(0,l).endsWith(u)&&!_){t.preventDefault();var k=l-u.length;this._applyEdits({value:a.substring(0,l-u.length)+a.substring(h),selectionStart:k,selectionEnd:k})}}else if(13===t.keyCode){if(l===h){var C=this._getLines(a,l).pop(),E=null==C?void 0:C.match(/^\s+/);if(E&&E[0]){t.preventDefault();var S="\n"+E[0],K=l+S.length;this._applyEdits({value:a.substring(0,l)+S+a.substring(h),selectionStart:K,selectionEnd:K})}}}else if(57===t.keyCode||219===t.keyCode||222===t.keyCode||192===t.keyCode){var N;57===t.keyCode&&t.shiftKey?N=["(",")"]:219===t.keyCode?N=t.shiftKey?["{","}"]:["[","]"]:222===t.keyCode?N=t.shiftKey?['"','"']:["'","'"]:192!==t.keyCode||t.shiftKey||(N=["`","`"]),l!==h&&N&&(t.preventDefault(),this._applyEdits({value:a.substring(0,l)+N[0]+a.substring(l,h)+N[1]+a.substring(h),selectionStart:l,selectionEnd:h+2}))}else!(r?t.metaKey&&90===t.keyCode:t.ctrlKey&&90===t.keyCode)||t.shiftKey||t.altKey?(r?t.metaKey&&90===t.keyCode&&t.shiftKey:n?t.ctrlKey&&89===t.keyCode:t.ctrlKey&&90===t.keyCode&&t.shiftKey)&&!t.altKey?(t.preventDefault(),this._redoEdit()):77!==t.keyCode||!t.ctrlKey||r&&!t.shiftKey||(t.preventDefault(),this.capture=!this.capture):(t.preventDefault(),this._undoEdit())}}},render:function(){var t=this,i=e.h("div",{class:"prism-editor__line-width-calc",style:"height: 0px; visibility: hidden; pointer-events: none;"},"999"),s=e.h("div",{class:"prism-editor__line-numbers",style:{"min-height":this.lineNumbersHeight},"aria-hidden":"true"},[i,Array.from(Array(this.lineNumbersCount).keys()).map((function(t,i){return e.h("div",{class:"prism-editor__line-number token comment"},""+ ++i)}))]),n=e.h("textarea",{ref:"textarea",onInput:this.handleChange,onKeydown:this.handleKeyDown,onClick:function(e){t.$emit("click",e)},onKeyup:function(e){t.$emit("keyup",e)},onFocus:function(e){t.$emit("focus",e)},onBlur:function(e){t.$emit("blur",e)},class:{"prism-editor__textarea":!0,"prism-editor__textarea--empty":this.isEmpty},spellCheck:"false",autocapitalize:"off",autocomplete:"off",autocorrect:"off","data-gramm":"false",placeholder:this.placeholder,"data-testid":"textarea",readonly:this.readonly,value:this.codeData}),r=e.h("pre",{ref:"pre",class:"prism-editor__editor","data-testid":"preview",innerHTML:this.content}),o=e.h("div",{class:"prism-editor__container"},[n,r]);return e.h("div",{class:"prism-editor-wrapper"},[this.lineNumbers&&s,o])}});t.PrismEditor=o,Object.defineProperty(t,"__esModule",{value:!0});let a=null;"undefined"!=typeof window?a=window.Vue:void 0!==i&&(a=i.Vue),a&&a.component("PrismEditor",o)})); | ||
//# sourceMappingURL=prismeditor.umd.production.min.js.map |
{ | ||
"name": "vue-prism-editor", | ||
"version": "2.0.0-alpha.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "A dead simple code editor with syntax highlighting and line numbers.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -14,2 +14,4 @@ # Vue Prism Editor | ||
Editor works both for Vue 2.x and Vue 3.x and you are currently on the branch that supports Vue 3.x. | ||
[Go here for the Vue 2.x compatible version](https://github.com/koca/vue-prism-editor/) | ||
@@ -47,3 +49,3 @@ ## Demo | ||
```sh | ||
npm install vue-prism-editor | ||
npm install vue-prism-editor@alpha | ||
``` | ||
@@ -54,3 +56,3 @@ | ||
```sh | ||
yarn add vue-prism-editor | ||
yarn add vue-prism-editor@alpha | ||
``` | ||
@@ -87,3 +89,3 @@ | ||
highlighter(code) { | ||
return highlight(code, languages.js); //returns html | ||
return highlight(code, languages.js); // languages.<insert language> to return html with markup | ||
}, | ||
@@ -90,0 +92,0 @@ }, |
@@ -535,3 +535,3 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
Array.from(Array(this.lineNumbersCount).keys()).map((_, index) => { | ||
return h('div', { attrs: { class: 'prism-editor__line-number token comment' } }, `${++index}`); | ||
return h('div', { class: 'prism-editor__line-number token comment' }, `${++index}`); | ||
}), | ||
@@ -538,0 +538,0 @@ ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
242
270254
2227