838eec30a8
- Implemented a new composable `useTheme` for managing theme state. - Added functions to read and write theme preference to local storage. - Applied theme styles to the DOM based on user preference. - Introduced a toggle function to switch between light and dark themes. refactor: enhance copilot plugin functionality - Improved request handling with sequence and document versioning. - Refactored ghost text handling to improve clarity and efficiency. - Updated markdown insertion logic to handle parsed content more robustly. - Enhanced error handling and logging for better debugging. style: update global styles for light and dark themes - Defined CSS variables for light and dark themes to streamline styling. - Improved overall styling consistency and responsiveness. - Added transitions for smoother theme changes and interactions.
2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{c as _,d as q,E as A,D as v,h as V,W as K}from"./cm-view-CiSFjroV.js";import{b as N,S as D,F as U,e as Y,m as j}from"./cm-state-X9WpHEQO.js";import{c as w}from"./vendor-crelt-C8TCjufn.js";class B{constructor(e,i,s){this.from=e,this.to=i,this.diagnostic=s}}class y{constructor(e,i,s){this.diagnostics=e,this.panel=i,this.selected=s}static init(e,i,s){let n=s.facet(S).markerFilter;n&&(e=n(e,s));let o=e.slice().sort((m,p)=>m.from-p.from||m.to-p.to),a=new j,l=[],c=0,r=s.doc.iter(),f=0,k=s.doc.length;for(let m=0;;){let p=m==o.length?null:o[m];if(!p&&!l.length)break;let u,h;if(l.length)u=c,h=l.reduce((d,x)=>Math.min(d,x.to),p&&p.from>u?p.from:1e8);else{if(u=p.from,u>k)break;h=p.to,l.push(p),m++}for(;m<o.length;){let d=o[m];if(d.from==u&&(d.to>d.from||d.to==u))l.push(d),m++,h=Math.min(d.to,h);else{h=Math.min(d.from,h);break}}h=Math.min(h,k);let R=!1;if(l.some(d=>d.from==u&&(d.to==h||h==k))&&(R=u==h,!R&&h-u<10)){let d=u-(f+r.value.length);d>0&&(r.next(d),f=u);for(let x=u;;){if(x>=h){R=!0;break}if(!r.lineBreak&&f+r.value.length>x)break;x=f+r.value.length,f+=r.value.length,r.next()}}let F=le(l);if(R)a.add(u,u,v.widget({widget:new ie(F),diagnostics:l.slice()}));else{let d=l.reduce((x,L)=>L.markClass?x+" "+L.markClass:x,"");a.add(u,h,v.mark({class:"cm-lintRange cm-lintRange-"+F+d,diagnostics:l.slice(),inclusiveEnd:l.some(x=>x.to>h)}))}if(c=h,c==k)break;for(let d=0;d<l.length;d++)l[d].to<=c&&l.splice(d--,1)}let g=a.finish();return new y(g,i,C(g))}}function C(t,e=null,i=0){let s=null;return t.between(i,1e9,(n,o,{spec:a})=>{if(!(e&&a.diagnostics.indexOf(e)<0))if(!s)s=new B(n,o,e||a.diagnostics[0]);else{if(a.diagnostics.indexOf(s.diagnostic)<0)return!1;s=new B(s.from,o,s.diagnostic)}}),s}function Z(t,e){let i=e.pos,s=e.end||i,n=t.state.facet(S).hideOn(t,i,s);if(n!=null)return n;let o=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(a=>a.is($))||t.changes.touchesRange(o.from,Math.max(o.to,s)))}function G(t,e){return t.field(b,!1)?e:e.concat(D.appendConfig.of(re))}const $=D.define(),M=D.define(),z=D.define(),b=N.define({create(){return new y(v.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),s=null,n=t.panel;if(t.selected){let o=e.changes.mapPos(t.selected.from,1);s=C(i,t.selected.diagnostic,o)||C(i,null,o)}!i.size&&n&&e.state.facet(S).autoPanel&&(n=null),t=new y(i,n,s)}for(let i of e.effects)if(i.is($)){let s=e.state.facet(S).autoPanel?i.value.length?P.open:null:t.panel;t=y.init(i.value,s,e.state)}else i.is(M)?t=new y(t.diagnostics,i.value?P.open:null,t.selected):i.is(z)&&(t=new y(t.diagnostics,t.panel,i.value));return t},provide:t=>[q.from(t,e=>e.panel),A.decorations.from(t,e=>e.diagnostics)]}),J=v.mark({class:"cm-lintRange cm-lintRange-active"});function Q(t,e,i){let{diagnostics:s}=t.state.field(b),n,o=-1,a=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(c,r,{spec:f})=>{if(e>=c&&e<=r&&(c==r||(e>c||i>0)&&(e<r||i<0)))return n=f.diagnostics,o=c,a=r,!1});let l=t.state.facet(S).tooltipFilter;return n&&l&&(n=l(n,t.state)),n?{pos:o,end:a,above:t.state.doc.lineAt(o).to<a,create(){return{dom:X(t,n)}}}:null}function X(t,e){return w("ul",{class:"cm-tooltip-lint"},e.map(i=>W(t,i,!1)))}const ee=t=>{let e=t.state.field(b,!1);(!e||!e.panel)&&t.dispatch({effects:G(t.state,[M.of(!0)])});let i=_(t,P.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0},T=t=>{let e=t.state.field(b,!1);return!e||!e.panel?!1:(t.dispatch({effects:M.of(!1)}),!0)},te=t=>{let e=t.state.field(b,!1);if(!e)return!1;let i=t.state.selection.main,s=e.diagnostics.iter(i.to+1);return!s.value&&(s=e.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to)?!1:(t.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),!0)},fe=[{key:"Mod-Shift-m",run:ee,preventDefault:!0},{key:"F8",run:te}],S=U.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...Y(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:E,tooltipFilter:E,needsRefresh:(e,i)=>e?i?s=>e(s)||i(s):e:i,hideOn:(e,i)=>e?i?(s,n,o)=>e(s,n,o)||i(s,n,o):e:i,autoPanel:(e,i)=>e||i})}}});function E(t,e){return t?e?(i,s)=>e(t(i,s),s):t:e}function H(t){let e=[];if(t)e:for(let{name:i}of t){for(let s=0;s<i.length;s++){let n=i[s];if(/[a-zA-Z]/.test(n)&&!e.some(o=>o.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function W(t,e,i){var s;let n=i?H(e.actions):[];return w("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},w("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(s=e.actions)===null||s===void 0?void 0:s.map((o,a)=>{let l=!1,c=m=>{if(m.preventDefault(),l)return;l=!0;let p=C(t.state.field(b).diagnostics,e);p&&o.apply(t,p.from,p.to)},{name:r}=o,f=n[a]?r.indexOf(n[a]):-1,k=f<0?r:[r.slice(0,f),w("u",r.slice(f,f+1)),r.slice(f+1)],g=o.markClass?" "+o.markClass:"";return w("button",{type:"button",class:"cm-diagnosticAction"+g,onclick:c,onmousedown:c,"aria-label":` Action: ${r}${f<0?"":` (access key "${n[a]})"`}.`},k)}),e.source&&w("div",{class:"cm-diagnosticSource"},e.source))}class ie extends K{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return w("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class O{constructor(e,i){this.diagnostic=i,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=W(e,i,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class P{constructor(e){this.view=e,this.items=[];let i=n=>{if(n.keyCode==27)T(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:o}=this.items[this.selectedIndex],a=H(o.actions);for(let l=0;l<a.length;l++)if(a[l].toUpperCase().charCodeAt(0)==n.keyCode){let c=C(this.view.state.field(b).diagnostics,o);c&&o.actions[l].apply(e,c.from,c.to)}}else return;n.preventDefault()},s=n=>{for(let o=0;o<this.items.length;o++)this.items[o].dom.contains(n.target)&&this.moveSelection(o)};this.list=w("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:i,onclick:s}),this.dom=w("div",{class:"cm-panel-lint"},this.list,w("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>T(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(b).selected;if(!e)return-1;for(let i=0;i<this.items.length;i++)if(this.items[i].diagnostic==e.diagnostic)return i;return-1}update(){let{diagnostics:e,selected:i}=this.view.state.field(b),s=0,n=!1,o=null,a=new Set;for(e.between(0,this.view.state.doc.length,(l,c,{spec:r})=>{for(let f of r.diagnostics){if(a.has(f))continue;a.add(f);let k=-1,g;for(let m=s;m<this.items.length;m++)if(this.items[m].diagnostic==f){k=m;break}k<0?(g=new O(this.view,f),this.items.splice(s,0,g),n=!0):(g=this.items[k],k>s&&(this.items.splice(s,k-s),n=!0)),i&&g.diagnostic==i.diagnostic?g.dom.hasAttribute("aria-selected")||(g.dom.setAttribute("aria-selected","true"),o=g):g.dom.hasAttribute("aria-selected")&&g.dom.removeAttribute("aria-selected"),s++}});s<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new O(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!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:c})=>{let r=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/r:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/r)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function i(){let s=e;e=s.nextSibling,s.remove()}for(let s of this.items)if(s.dom.parentNode==this.list){for(;e!=s.dom;)i();e=s.dom.nextSibling}else this.list.insertBefore(s.dom,e);for(;e;)i()}moveSelection(e){if(this.selectedIndex<0)return;let i=this.view.state.field(b),s=C(i.diagnostics,this.items[e].diagnostic);s&&this.view.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0,effects:z.of(s)})}static open(e){return new P(e)}}function se(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 I(t){return se(`<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 ne=A.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:I("#d11")},".cm-lintRange-warning":{backgroundImage:I("orange")},".cm-lintRange-info":{backgroundImage:I("#999")},".cm-lintRange-hint":{backgroundImage:I("#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}}});function oe(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function le(t){let e="hint",i=1;for(let s of t){let n=oe(s.severity);n>i&&(i=n,e=s.severity)}return e}const re=[b,A.decorations.compute([b],t=>{let{selected:e,panel:i}=t.field(b);return!e||!i||e.from==e.to?v.none:v.set([J.range(e.from,e.to)])}),V(Q,{hideOn:Z}),ne];export{fe as l};
|