- md5
- 1b4e6b47328f80c0153f4323e6d26f72
- sha1
- 1395b00d1517c249d711b5dee61b06b74b6c8f97
- sha256
- 8b217add2ce39def9ba2711ca8053ccd250be2a2abe9ddb06a5b30b71726f74f
import{getPanel as ae,showPanel as ce,EditorView as D,Decoration as T,ViewPlugin as fe,gutter as de,showTooltip as ue,hoverTooltip as me,GutterMarker as he,WidgetType as ge,logException as pe}from"@codemirror/view";import{RangeSet as O,StateEffect as P,StateField as E,Facet as K,combineConfig as N,RangeSetBuilder as be}from"@codemirror/state";function M(){return M=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},M.apply(null,arguments)}function y(){var t=arguments[0];typeof t=="string"&&(t=document.createElement(t));var e=1,n=arguments[1];if(n&&typeof n=="object"&&n.nodeType==null&&!Array.isArray(n)){for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i)){var s=n[i];typeof s=="string"?t.setAttribute(i,s):s!=null&&(t[i]=s)}e++}for(;e<arguments.length;e++)V(t,arguments[e]);return t}function V(t,e){if(typeof e=="string")t.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)t.appendChild(e);else if(Array.isArray(e))for(var n=0;n<e.length;n++)V(t,e[n]);else throw new RangeError("Unsupported child node: "+e)}class _{constructor(e,n,i){this.from=e,this.to=n,this.diagnostic=i}}class C{constructor(e,n,i){this.diagnostics=e,this.panel=n,this.selected=i}static init(e,n,i){let s=i.facet(x).markerFilter;s&&(e=s(e,i));let o=e.slice().sort((u,b)=>u.from-b.from||u.to-b.to),r=new be,l=[],a=0,c=i.doc.iter(),d=0,w=i.doc.length;for(let u=0;;){let b=u==o.length?null:o[u];if(!b&&!l.length)break;let g,m;if(l.length)g=a,m=l.reduce((f,k)=>Math.min(f,k.to),b&&b.from>g?b.from:1e8);else{if(g=b.from,g>w)break;m=b.to,l.push(b),u++}for(;u<o.length;){let f=o[u];if(f.from==g&&(f.to>f.from||f.to==g))l.push(f),u++,m=Math.min(f.to,m);else{m=Math.min(f.from,m);break}}m=Math.min(m,w);let L=!1;if(l.some(f=>f.from==g&&(f.to==m||m==w))&&(L=g==m,!L&&m-g<10)){let f=g-(d+c.value.length);f>0&&(c.next(f),d=g);for(let k=g;;){if(k>=m){L=!0;break}if(!c.lineBreak&&d+c.value.length>k)break;k=d+c.value.length,d+=c.value.length,c.next()}}let H=se(l);if(L)r.add(g,g,T.widget({widget:new Se(H),diagnostics:l.slice()}));else{let f=l.reduce((k,$)=>$.markClass?k+" "+$.markClass:k,"");r.add(g,m,T.mark({class:"cm-lintRange cm-lintRange-"+H+f,diagnostics:l.slice(),inclusiveEnd:l.some(k=>k.to>m)}))}if(a=m,a==w)break;for(let f=0;f<l.length;f++)l[f].to<=a&&l.splice(f--,1)}let p=r.finish();return new C(p,n,v(p))}}function v(t,e=null,n=0){let i=null;return t.between(n,1e9,(s,o,{spec:r})=>{if(!(e&&r.diagnostics.indexOf(e)<0))if(!i)i=new _(s,o,e||r.diagnostics[0]);else{if(r.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new _(i.from,o,i.diagnostic)}}),i}function Y(t,e){let n=e.pos,i=e.end||n,s=t.state.facet(x).hideOn(t,n,i);if(s!=null)return s;let o=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(r=>r.is(S))||t.changes.touchesRange(o.from,Math.max(o.to,i)))}function q(t,e){return t.field(h,!1)?e:e.concat(P.appendConfig.of(re))}function U(t,e){return{effects:q(t,[S.of(e)])}}const S=P.define(),B=P.define(),W=P.define(),h=E.define({create(){return new C(T.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let n=t.diagnostics.map(e.changes),i=null,s=t.panel;if(t.selected){let o=e.changes.mapPos(t.selected.from,1);i=v(n,t.selected.diagnostic,o)||v(n,null,o)}!n.size&&s&&e.state.facet(x).autoPanel&&(s=null),t=new C(n,s,i)}for(let n of e.effects)if(n.is(S)){let i=e.state.facet(x).autoPanel?n.value.length?R.open:null:t.panel;t=C.init(n.value,i,e.state)}else n.is(B)?t=new C(t.diagnostics,n.value?R.open:null,t.selected):n.is(W)&&(t=new C(t.diagnostics,t.panel,n.value));return t},provide:t=>[ce.from(t,e=>e.panel),D.decorations.from(t,e=>e.diagnostics)]});function we(t){let e=t.field(h,!1);return e?e.diagnostics.size:0}const ke=T.mark({class:"cm-lintRange cm-lintRange-active"});function ye(t,e,n){let{diagnostics:i}=t.state.field(h),s,o=-1,r=-1;i.between(e-(n<0?1:0),e+(n>0?1:0),(a,c,{spec:d})=>{if(e>=a&&e<=c&&(a==c||(e>a||n>0)&&(e<c||n<0)))return s=d.diagnostics,o=a,r=c,!1});let l=t.state.facet(x).tooltipFilter;return s&&l&&(s=l(s,t.state)),s?{pos:o,end:r,above:t.state.doc.lineAt(o).to<r,create(){return{dom:Z(t,s)}}}:null}function Z(t,e){return y("ul",{class:"cm-tooltip-lint"},e.map(n=>ie(t,n,!1)))}const X=t=>{let e=t.state.field(h,!1);(!e||!e.panel)&&t.dispatch({effects:q(t.state,[B.of(!0)])});let n=ae(t,R.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},G=t=>{let e=t.state.field(h,!1);return!e||!e.panel?!1:(t.dispatch({effects:B.of(!1)}),!0)},J=t=>{let e=t.state.field(h,!1);if(!e)return!1;let n=t.state.selection.main,i=v(e.diagnostics,null,n.to+1);return!i&&(i=v(e.diagnostics,null,0),!i||i.from==n.from&&i.to==n.to)?!1:(t.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},xe=t=>{let{state:e}=t,n=e.field(h,!1);if(!n)return!1;let i=e.selection.main,s,o,r,l;return n.diagnostics.between(0,e.doc.length,(a,c)=>{c<i.to&&(s==null||s<a)&&(s=a,o=c),(r==null||a>r)&&(r=a,l=c)}),r==null||s==null&&r==i.from?!1:(t.dispatch({selection:{anchor:s??r,head:o??l},scrollIntoView:!0}),!0)},ve=[{key:"Mod-Shift-m",run:X,preventDefault:!0},{key:"F8",run:J}],Q=fe.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(x);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let t=Date.now();if(t<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-t);else{this.set=!1;let{state:e}=this.view,{sources:n}=e.facet(x);n.length&&Ce(n.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(U(this.view.state,i.reduce((s,o)=>s.concat(o))))},i=>{pe(this.view.state,i)})}}update(t){let e=t.state.facet(x);(t.docChanged||e!=t.startState.facet(x)||e.needsRefresh&&e.needsRefresh(t))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function Ce(t,e,n){let i=[],s=-1;for(let o of t)o.then(r=>{i.push(r),clearTimeout(s),i.length==t.length?e(i):s=setTimeout(()=>e(i),200)},n)}const x=K.define({combine(t){return M({sources:t.map(e=>e.source).filter(e=>e!=null)},N(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ee,tooltipFilter:ee,needsRefresh:(e,n)=>e?n?i=>e(i)||n(i):e:n,hideOn:(e,n)=>e?n?(i,s,o)=>e(i,s,o)||n(i,s,o):e:n,autoPanel:(e,n)=>e||n}))}});function ee(t,e){return t?e?(n,i)=>e(t(n,i),i):t:e}function Te(t,e={}){return[x.of({source:t,config:e}),Q,re]}function Pe(t){let e=t.plugin(Q);e&&e.force()}function te(t){let e=[];if(t)e:for(let{name:n}of t){for(let i=0;i<n.length;i++){let s=n[i];if(/[a-zA-Z]/.test(s)&&!e.some(o=>o.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function ie(t,e,n){var i;let s=n?te(e.actions):[];return y("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},y("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((o,r)=>{let l=!1,a=u=>{if(u.preventDefault(),l)return;l=!0;let b=v(t.state.field(h).diagnostics,e);b&&o.apply(t,b.from,b.to)},{name:c}=o,d=s[r]?c.indexOf(s[r]):-1,w=d<0?c:[c.slice(0,d),y("u",c.slice(d,d+1)),c.slice(d+1)],p=o.markClass?" "+o.markClass:"";return y("button",{type:"button",class:"cm-diagnosticAction"+p,onclick:a,onmousedown:a,"aria-label":` Action: ${c}${d<0?"":` (access key "${s[r]})"`}.`},w)}),e.source&&y("div",{class:"cm-diagnosticSource"},e.source))}class Se extends ge{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return y("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ne{constructor(e,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=ie(e,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class R{constructor(e){this.view=e,this.items=[];let n=s=>{if(!(s.ctrlKey||s.altKey||s.metaKey)){if(s.keyCode==27)G(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:o}=this.items[this.selectedIndex],r=te(o.actions);for(let l=0;l<r.length;l++)if(r[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=v(this.view.state.field(h).diagnostics,o);a&&o.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()}},i=s=>{for(let o=0;o<this.items.length;o++)this.items[o].dom.contains(s.target)&&this.moveSelection(o)};this.list=y("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:i}),this.dom=y("div",{class:"cm-panel-lint"},this.list,y("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>G(this.view)},"\xD7")),this.update()}get selectedIndex(){let e=this.view.state.field(h).selected;if(!e)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==e.diagnostic)return n;return-1}update(){let{diagnostics:e,selected:n}=this.view.state.field(h),i=0,s=!1,o=null,r=new Set;for(e.between(0,this.view.state.doc.length,(l,a,{spec:c})=>{for(let d of c.diagnostics){if(r.has(d))continue;r.add(d);let w=-1,p;for(let u=i;u<this.items.length;u++)if(this.items[u].diagnostic==d){w=u;break}w<0?(p=new ne(this.view,d),this.items.splice(i,0,p),s=!0):(p=this.items[w],w>i&&(this.items.splice(i,w-i),s=!0)),n&&p.diagnostic==n.diagnostic?p.dom.hasAttribute("aria-selected")||(p.dom.setAttribute("aria-selected","true"),o=p):p.dom.hasAttribute("aria-selected")&&p.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new ne(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),o?(this.list.setAttribute("aria-activedescendant",o.id),this.view.requestMeasure({key:this,read:()=>({sel:o.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let c=a.height/this.list.offsetHeight;l.top<a.top?this.list.scrollTop-=(a.top-l.top)/c:l.bottom>a.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/c)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function n(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)n();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)n()}moveSelection(e){if(this.selectedIndex<0)return;let n=this.view.state.field(h),i=v(n.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:W.of(i)})}static open(e){return new R(e)}}function A(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function F(t){return A(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Re=D.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:F("#d11")},".cm-lintRange-warning":{backgroundImage:F("orange")},".cm-lintRange-info":{backgroundImage:F("#999")},".cm-lintRange-hint":{backgroundImage:F("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function Le(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function se(t){let e="hint",n=1;for(let i of t){let s=Le(i.severity);s>n&&(n=s,e=i.severity)}return e}class oe extends he{constructor(e){super(),this.diagnostics=e,this.severity=se(e)}toDOM(e){let n=document.createElement("div");n.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,s=e.state.facet(I).tooltipFilter;return s&&(i=s(i,e.state)),i.length&&(n.onmouseover=()=>Me(e,n,i)),n}}function De(t,e){let n=i=>{let s=e.getBoundingClientRect();if(!(i.clientX>s.left-10&&i.clientX<s.right+10&&i.clientY>s.top-10&&i.clientY<s.bottom+10)){for(let o=i.target;o;o=o.parentNode)if(o.nodeType==1&&o.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",n),t.state.field(le)&&t.dispatch({effects:z.of(null)})}};window.addEventListener("mousemove",n)}function Me(t,e,n){function i(){let r=t.elementAtHeight(e.getBoundingClientRect().top+5-t.documentTop);t.coordsAtPos(r.from)&&t.dispatch({effects:z.of({pos:r.from,above:!1,clip:!1,create(){return{dom:Z(t,n),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,De(t,e)}let{hoverTime:s}=t.state.facet(I),o=setTimeout(i,s);e.onmouseout=()=>{clearTimeout(o),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(o),o=setTimeout(i,s)}}function Ae(t,e){let n=Object.create(null);for(let s of e){let o=t.lineAt(s.from);(n[o.from]||(n[o.from]=[])).push(s)}let i=[];for(let s in n)i.push(new oe(n[s]).range(+s));return O.of(i,!0)}const Fe=de({class:"cm-gutter-lint",markers:t=>t.state.field(j),widgetMarker:(t,e,n)=>{let i=[];return t.state.field(j).between(n.from,n.to,(s,o,r)=>{s>n.from&&s<n.to&&i.push(...r.diagnostics)}),i.length?new oe(i):null}}),j=E.define({create(){return O.empty},update(t,e){t=t.map(e.changes);let n=e.state.facet(I).markerFilter;for(let i of e.effects)if(i.is(S)){let s=i.value;n&&(s=n(s||[],e.state)),t=Ae(e.state.doc,s.slice(0))}return t}}),z=P.define(),le=E.define({create(){return null},update(t,e){return t&&e.docChanged&&(t=Y(e,t)?null:M({},t,{pos:e.changes.mapPos(t.pos)})),e.effects.reduce((n,i)=>i.is(z)?i.value:n,t)},provide:t=>ue.from(t)}),Ie=D.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:A('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:A('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:A('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),re=[h,D.decorations.compute([h],t=>{let{selected:e,panel:n}=t.field(h);return!e||!n||e.from==e.to?T.none:T.set([ke.range(e.from,e.to)])}),me(ye,{hideOn:Y}),Re],I=K.define({combine(t){return N(t,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function Oe(t={}){return[I.of(t),j,Fe,Ie,le]}function Ee(t,e){let n=t.field(h,!1);if(n&&n.diagnostics.size){let i=[],s=[],o=-1;for(let r=O.iter([n.diagnostics]);;r.next()){for(let l=0;l<i.length;l++)(!r.value||r.value.spec.diagnostics.indexOf(i[l])<0)&&(e(i[l],s[l],o),i.splice(l,1),s.splice(l--,1));if(!r.value)break;for(let l of r.value.spec.diagnostics)i.indexOf(l)<0&&(i.push(l),s.push(r.from));o=r.to}}}export{G as closeLintPanel,we as diagnosticCount,Ee as forEachDiagnostic,Pe as forceLinting,Oe as lintGutter,ve as lintKeymap,Te as linter,J as nextDiagnostic,X as openLintPanel,xe as previousDiagnostic,U as setDiagnostics,S as setDiagnosticsEffect};
The same content is in 5 releases, Joomla 6.2.0-alpha1 to 6.2.0-beta2. See them all, or every version of this file.