Files
small-packages/luci-app-honk/root/etc/honk/doona/assets/CodeEditor-B7e2c4Ke.js
T
2026-10-08 20:05:36 +08:00

2 lines
13 KiB
JavaScript

import{r as e,j as r}from"./vendor-react-64fcanlc.js";import{bN as t,gr as o,bM as n,fl as a,bq as c,u as s,df as i,B as l,fr as d,ft as p}from"./index-XeGFdFb3.js";import{S as m,a as u,E as f,C as g,b,l as v,c as x,h,d as y,r as k,e as w,f as C,g as j,i as R,j as A,s as E,k as L,t as M,m as N,n as F,o as O,p as S,q as $,u as q,v as B,w as D,x as I,y as T,z as H,D as K,R as V,A as z,B as G,F as U,G as W,H as P,I as J,J as _,K as Q,L as X}from"./vendor-editor-BRV-W12m.js";import{d as Y,s as Z}from"./daeTokens-BVtuNnWZ.js";import{s as ee}from"./nodes-Bm1vmvln.js";import{M as re}from"./AppearanceControls-Q-jHRGz9.js";import{A as te,n as oe}from"./logs-DNePHVHd.js";import"./_commonjsHelpers-CXUWDbkB.js";import"./index-DUM-iwa2.js";import"./ItemText-Bvif-kkw.js";import"./Select-OqnbuzuK.js";const ne=m.define({name:"dae",languageData:{commentTokens:{line:"#"},closeBrackets:{brackets:["(","{","'",'"']}},startState:Z,token:Y}),ae=["global","subscription","node","group","dns","routing"].map(e=>({label:e,type:"keyword"})),ce=n.map(e=>({label:e,type:"property",apply:e+": "})),se=["domain","dip","sip","dport","sport","l4proto","ipversion","pname","mac","dscp","qname","qtype","upstream"].map(e=>({label:e,type:"function",apply:e+"("})),ie=["geosite","geoip","suffix","full","keyword","regex"].map(e=>({label:e,type:"constant",apply:e+":"})),le=o.map(e=>({label:e,type:"constant"})),de=t.map(e=>({label:e,type:"keyword"})),pe=[{label:"fallback",type:"keyword",apply:"fallback: "},{label:"include",type:"keyword",apply:"include "}];function me(e){return u({override:[r=>function(e,r){const t=e.matchBefore(/[\w.-]*/);if(!t)return null;const o=e.state.doc.lineAt(e.pos),n=o.text.slice(0,e.pos-o.from),a=/->\s*[\w.-]*$/.test(n)||/^\s*fallback:\s*[\w.-]*$/.test(n);if(t.from===t.to&&!e.explicit&&!a)return null;const c=e.state.doc.sliceString(0,e.pos),{blocks:s,tokens:i}=ee(c),l=i.at(-1);if(l?.to===e.pos&&("quoted"===l.kind||"comment"===l.kind))return null;const d=s.find(r=>r.close===e.pos)?.name;let p;if(a)p=[...r().map(e=>({label:e.name,apply:e.written,type:"variable"})),...de];else if(/\b(domain|dip|sip|qname)\(\s*[\w.-]*$/.test(n))p=ie;else if(void 0===d)p=ae.map(e=>({...e,apply:(r,t,o,n)=>{const a=e.label+" {\n \n}";r.dispatch({changes:{from:o,to:n,insert:a},selection:{anchor:o+e.label.length+4}})}}));else if("routing"===d||"dns"===d)p=[...se,...pe];else if("global"===d)p=ce;else{if("group"!==d)return null;p=/\bpolicy\s*:\s*[\w.-]*$/.test(n)?le:[...le.map(e=>({...e,apply:"policy: "+e.label})),{label:"filter",type:"property",apply:"filter: "}]}return{from:t.from,options:p,validFor:/^[\w.-]*$/}}(r,e)]})}function ue(e){let r=!1;const t=r=>(r.state.readOnly&&e(),!1);return f.domEventHandlers({keydown:(e,r)=>function(e){return"Backspace"===e.key||"Delete"===e.key||"Enter"===e.key||1===[...e.key].length&&!e.ctrlKey&&!e.metaKey}(e)&&t(r),paste:(e,r)=>t(r),cut:(e,r)=>t(r),pointerdown:e=>(r="touch"===e.pointerType,!1),click:(e,o)=>r&&t(o)})}const fe=[["Completions","cm.completions"],["Find","cm.find"],["Replace","cm.replace"],["next","cm.next"],["previous","cm.previous"],["all","cm.all"],["match case","cm.matchCase"],["regexp","cm.regexp"],["by word","cm.byWord"],["replace","cm.replaceOne"],["replace all","cm.replaceAll"],["close","ui.close"],["Go to line","cm.gotoLine"],["go","cm.go"],["current match","cm.currentMatch"],["replaced $ matches","cm.replacedMatches"],["replaced match on line $","cm.replacedOnLine"],["on line","cm.onLine"],["Selection deleted","cm.selectionDeleted"],["Control character","cm.controlCharacter"]],ge=e=>b.phrases.of(Object.fromEntries(fe.map(([r,t])=>[r,e(t)]))),be=f.theme({"&":{backgroundColor:"var(--rp-base)",color:"var(--rp-text)",border:"1px solid var(--rp-hl-high)",borderRadius:"var(--rp-r-md)",fontSize:"var(--rp-text-sm)"},"&.cm-focused":{outline:"none",borderColor:"var(--rp-text)"},".cm-scroller":{fontFamily:"var(--rp-font-mono)",lineHeight:"var(--rp-line-body)",fontVariantLigatures:"none",borderRadius:"calc(var(--rp-r-md) - 1px)"},".cm-content":{padding:"var(--rp-space-2) 0",caretColor:"var(--rp-text)"},".cm-line":{padding:"0 var(--rp-space-3)"},".cm-gutters":{backgroundColor:"var(--rp-base)",color:"var(--rp-muted)",border:"none"},".cm-lineNumbers .cm-gutterElement":{padding:"0 var(--rp-space-2) 0 var(--rp-space-3)",minWidth:"40px"},".cm-activeLine, .cm-focusLine":{backgroundColor:"color-mix(in srgb, var(--rp-hl-med) 60%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--rp-text)"},".cm-selectionBackground, &.cm-focused .cm-selectionBackground, ::selection":{backgroundColor:"var(--rp-hl-high)"},".cm-cursor":{borderLeftColor:"var(--rp-text)"},".cm-matchingBracket":{backgroundColor:"color-mix(in srgb, var(--rp-accent) 20%, transparent)",outline:"none"},".cm-selectionMatch":{backgroundColor:"color-mix(in srgb, var(--rp-notice) 25%, transparent)"},".cm-gutter-lint":{width:"12px"},".cm-gutter-lint .cm-gutterElement":{padding:"0"},".cm-lint-marker":{width:"8px",height:"8px",margin:"6px 2px",borderRadius:"50%"},".cm-lint-marker-error":{content:"none",backgroundColor:"var(--rp-negative)"},".cm-lint-marker-warning":{content:"none",backgroundColor:"var(--rp-notice)"},".cm-lint-marker-info":{content:"none",backgroundColor:"var(--rp-foam)"},".cm-tooltip.cm-tooltip-lint":{backgroundColor:"var(--rp-text)",color:"var(--rp-on-text)",border:"none",borderRadius:"var(--rp-r-sm)",padding:"var(--rp-space-half) 0"},".cm-tooltip-lint .cm-diagnostic":{border:"none",padding:"var(--rp-space-half) var(--rp-space-2)",fontSize:"var(--rp-text-xs)",lineHeight:"16px",fontFamily:"inherit"},".cm-tooltip-lint .cm-diagnosticText":{color:"inherit"},".cm-diag-line-error":{backgroundColor:"color-mix(in srgb, var(--rp-negative) 14%, transparent)"},".cm-diag-line-warning":{backgroundColor:"color-mix(in srgb, var(--rp-notice) 16%, transparent)"},".cm-diag-line-info":{backgroundColor:"color-mix(in srgb, var(--rp-foam) 14%, transparent)"},".cm-lintRange-error":{backgroundImage:"none",textDecoration:"underline wavy var(--rp-negative)",textUnderlineOffset:"3px"},".cm-lintRange-warning":{backgroundImage:"none",textDecoration:"underline wavy var(--rp-notice)",textUnderlineOffset:"3px"},".cm-lintRange-info":{backgroundImage:"none",textDecoration:"underline dotted var(--rp-foam)",textUnderlineOffset:"3px"},".cm-tooltip":{backgroundColor:"var(--rp-surface)",border:"1px solid var(--rp-hl-high)",borderRadius:"var(--rp-r-md)",color:"var(--rp-text)"},".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--rp-selected)",color:"var(--rp-text)"},".cm-tooltip.cm-tooltip-autocomplete > ul":{fontFamily:"var(--rp-font-mono)",fontVariantLigatures:"none"},".cm-panels":{backgroundColor:"var(--rp-surface)",color:"var(--rp-text)"},".cm-panels-bottom":{borderTop:"1px solid var(--rp-hl-med)"},".cm-textfield":{border:"1px solid var(--rp-hl-high)",borderRadius:"var(--rp-r-sm)",backgroundColor:"var(--rp-base)",color:"var(--rp-text)"},".cm-button":{border:"1px solid var(--rp-hl-high)",borderRadius:"var(--rp-r-sm)",backgroundImage:"none",backgroundColor:"var(--rp-overlay)",color:"var(--rp-text)"}}),ve=_.define([{tag:Q.comment,color:"var(--rp-code-comment)"},{tag:Q.keyword,color:"var(--rp-code-keyword)",fontWeight:"700"},{tag:Q.string,color:"var(--rp-code-string)"},{tag:Q.number,color:"var(--rp-code-number)"},{tag:Q.propertyName,color:"var(--rp-code-propertyName)"},{tag:Q.variableName,color:"var(--rp-code-variableName)"},{tag:Q.operator,color:"var(--rp-code-operator)"},{tag:Q.punctuation,color:"var(--rp-code-punctuation)"}]),xe=z.of((e,r)=>{const t=e.lineAt(r,-1),o=t.from>0?e.lineAt(t.from-1,-1):null;if(!o)return 0;const n=/^\s*/.exec(o.text)[0].length,a=/\{\s*(#.*)?$/.test(o.text),c=/^\s*\}/.test(t.text);return Math.max(0,n+(a?2:0)-(c?2:0))}),he=J.define(),ye={error:K.line({class:"cm-diag-line cm-diag-line-error"}),warning:K.line({class:"cm-diag-line cm-diag-line-warning"}),info:K.line({class:"cm-diag-line cm-diag-line-info"})},ke=H.define({create:()=>K.none,update(e,r){let t=e.map(r.changes);for(const o of r.effects){if(!o.is(he))continue;const e=new V,n={error:0,warning:1,info:2},a=new Map;for(const t of o.value){if(t.line<1||t.line>r.state.doc.lines)continue;const e=a.get(t.line);(!e||n[t.level]<n[e.level])&&a.set(t.line,t)}for(const t of[...a.keys()].sort((e,r)=>e-r)){const o=r.state.doc.line(t).from;e.add(o,o,ye[a.get(t).level])}t=e.finish()}return t},provide:e=>f.decorations.from(e)}),we=[{id:"undo",label:"cm.undo",run:I},{id:"redo",label:"cm.redo",run:T},{id:"comment",label:"cm.toggleComment",run:M}],Ce=[],je=P.define(),Re=J.define(),Ae=K.line({class:"cm-focusLine"}),Ee=H.define({create:()=>K.none,update(e,r){let t=e.map(r.changes);for(const o of r.effects)o.is(Re)&&(t=K.set(Ae.range(r.state.doc.line(o.value).from)));return t},provide:e=>f.decorations.from(e)}),Le=e=>[b.readOnly.of(e),f.editable.of(!e),e?Ee:[G(),U(),W()]];function Me({value:t,onChange:o,readOnly:n=!1,marks:m=Ce,focusLine:u,label:I,outbounds:T,onSave:H,onReadOnlyAttempt:K,compact:V,actions:z=[],focusKey:G,banner:U}){const W=e.useRef(null),P=a(W,`${n} ${!!o} ${I}`),J=e.useRef(null);e.useLayoutEffect(()=>{P&&W.current?.contains(document.activeElement)&&J.current?.querySelector("button")?.focus()},[P]);const _=e.useRef(null),{isFocusVisible:Q}=c({isTextInput:!0}),Y=e.useRef(null),Z=e.useRef(null),ee=e.useRef(o),ae=e.useRef(T),ce=e.useRef(H),se=e.useRef(K);e.useEffect(()=>{ee.current=o,ae.current=T,ce.current=H,se.current=K});const ie=e.useRef(new g),le=s(),de=e.useRef(new g),pe=e.useRef(new g),fe=e.useRef(new g);e.useLayoutEffect(()=>{const e=new f({parent:_.current,state:b.create({doc:t,extensions:[v(),x(),f.scrollMargins.of(e=>{const r=Y.current?.getBoundingClientRect().bottom;return void 0===r?null:{top:Math.min(r,Math.max(0,r-e.scrollDOM.getBoundingClientRect().top))}}),h(),fe.current.of(y()),k(),ke,w(),C(),j(),R.of(" "),A(),xe,me(()=>ae.current?.()??[]),ne,E(ve),be,L.of([{key:"Mod-s",run:()=>(ce.current?.(),!0)},{key:"Mod-/",run:M},{key:"Mod-g",run:N},...F,...O,...S,...$,...q,B]),ie.current.of(Le(n)),de.current.of(ge(le)),pe.current.of(f.contentAttributes.of({"aria-label":I,tabindex:"0"})),ue(()=>se.current?.()),f.updateListener.of(e=>{e.docChanged&&!e.transactions.some(e=>e.annotation(je))&&ee.current?.(e.state.doc.toString())})]})});return Z.current=e,()=>{e.destroy(),Z.current=null}},[]),e.useEffect(()=>{const e=Z.current;e&&e.dispatch({effects:ie.current.reconfigure(Le(n))})},[n]),e.useEffect(()=>{Z.current?.dispatch({effects:de.current.reconfigure(ge(le))})},[le]),e.useEffect(()=>{Z.current?.dispatch({effects:pe.current.reconfigure(f.contentAttributes.of({"aria-label":I,tabindex:"0"}))})},[I]),e.useEffect(()=>{const e=Z.current;e&&e.state.doc.toString()!==t&&(e.dispatch({changes:{from:0,to:e.state.doc.length,insert:t},annotations:je.of(!0),effects:fe.current.reconfigure([])}),e.dispatch({effects:fe.current.reconfigure(y())}))},[t]),e.useEffect(()=>{const e=Z.current;if(!e)return;const r=D(e.state,function(e,r){return r.filter(r=>r.line>=1&&r.line<=e.doc.lines).map(r=>{const t=e.doc.line(r.line),o=Math.max(0,(r.column??1)-1),n=(new TextEncoder).encode(t.text);let a=0;for(let e=0;e<Math.min(o,n.length);){const r=n[e]<128?1:n[e]<224?2:n[e]<240?3:4;if(e+r>o)break;e+=r,a+=4===r?2:1}return{from:t.from+a,to:t.to,severity:r.level,message:r.message}})}(e.state,m)),t=Array.isArray(r.effects)?r.effects:r.effects?[r.effects]:[];e.dispatch({...r,effects:[...t,he.of(m)]})},[m]),e.useEffect(()=>{const e=Z.current;if(!e||!u||u<1||u>e.state.doc.lines)return;const r=e.state.doc.line(u);e.dispatch({selection:{anchor:r.from},effects:[Re.of(u),f.scrollIntoView(r.from,{y:"center"})]}),e.focus()},[u,G]);const ye=e=>{Z.current&&e(Z.current)};return r.jsxs(r.Fragment,{children:[!V&&r.jsxs("div",{className:"rp-editor-head",ref:Y,children:[r.jsxs("div",{className:"rp-editor-toolbar",children:[z.length>0&&r.jsx("div",{className:"rp-toolbar",children:r.jsx(i,{children:r.jsx(te,{actions:z,overflowMode:"wrap"})})}),r.jsxs("div",{className:"rp-editor-actions","data-collapsed":P||void 0,children:[r.jsxs("div",{className:"rp-toolbar",ref:W,children:[r.jsx(l,{onPress:()=>ye(X),children:le(n?"cm.find":"cm.findReplace")}),r.jsx(l,{onPress:()=>ye(N),children:le("cm.gotoLine")}),o&&r.jsx(re,{label:le("cm.commands"),isDisabled:n,content:r.jsx(d,{"aria-label":le("cm.commands"),onAction:e=>{const r=we.find(r=>r.id===e);r&&ye(r.run)},children:we.map(e=>r.jsx(p,{id:e.id,className:"rp-item plain",textValue:le(e.label),children:le(e.label)},e.id))}),children:le("cm.commands")})]}),P&&r.jsx("div",{className:"rp-editor-overflow",ref:J,children:r.jsx(oe,{actions:[{id:"find",label:le(n?"cm.find":"cm.findReplace"),onAction:()=>requestAnimationFrame(()=>ye(X))},{id:"line",label:le("cm.gotoLine"),onAction:()=>requestAnimationFrame(()=>ye(N))},...o?we.map(e=>({id:e.id,label:le(e.label),isDisabled:n,onAction:()=>requestAnimationFrame(()=>ye(e.run))})):[]]})})]})]}),U]}),r.jsx("div",{className:V?"rp-editor compact":"rp-editor",ref:_,"data-keyboard":Q||void 0})]})}export{Me as CodeEditor};