CoreFiles by mySites.guru
codemirror-lang-xml.min.js1 lines, 5,037 bytes, from Joomla_5.0.2-Stable-Full_Package.zip
Raw History Compare with 5.0.1
md5
3a48645fab88de7bbc095f79049053f4
sha1
392bca18169868e100918025f97fff4129b8d1d6
sha256
97e0b8454e012150389c1fff0efee032d8c705f5a0634b63ab561da9e91fc5ee
import{parser as V}from"@lezer/xml";import{LRLanguage as F,indentNodeProp as $,foldNodeProp as w,bracketMatchingHandle as I,LanguageSupport as L,syntaxTree as k}from"@codemirror/language";function C(e,t){let r=t&&t.getChild("TagName");return r?e.sliceString(r.from,r.to):""}function O(e,t){let r=t&&t.firstChild;return!r||r.name!="OpenTag"?"":C(e,r)}function D(e,t,r){let n=t&&t.getChildren("Attribute").find(o=>o.from<=r&&o.to>=r),a=n&&n.getChild("AttributeName");return a?e.sliceString(a.from,a.to):""}function N(e){for(let t=e&&e.parent;t;t=t.parent)if(t.name=="Element")return t;return null}function M(e,t){var r;let n=k(e).resolveInner(t,-1),a=null;for(let o=n;!a&&o.parent;o=o.parent)(o.name=="OpenTag"||o.name=="CloseTag"||o.name=="SelfClosingTag"||o.name=="MismatchedCloseTag")&&(a=o);if(a&&(a.to>t||a.lastChild.type.isError)){let o=a.parent;if(n.name=="TagName")return a.name=="CloseTag"||a.name=="MismatchedCloseTag"?{type:"closeTag",from:n.from,context:o}:{type:"openTag",from:n.from,context:N(o)};if(n.name=="AttributeName")return{type:"attrName",from:n.from,context:a};if(n.name=="AttributeValue")return{type:"attrValue",from:n.from,context:a};let m=n==a||n.name=="Attribute"?n.childBefore(t):n;return m?.name=="StartTag"?{type:"openTag",from:t,context:N(o)}:m?.name=="StartCloseTag"&&m.to<=t?{type:"closeTag",from:t,context:o}:m?.name=="Is"?{type:"attrValue",from:t,context:a}:m?{type:"attrName",from:t,context:a}:null}else if(n.name=="StartCloseTag")return{type:"closeTag",from:t,context:n.parent};for(;n.parent&&n.to==t&&!(!((r=n.lastChild)===null||r===void 0)&&r.type.isError);)n=n.parent;return n.name=="Element"||n.name=="Text"||n.name=="Document"?{type:"tag",from:t,context:n.name=="Element"?n:N(n)}:null}class P{constructor(t,r,n){this.attrs=r,this.attrValues=n,this.children=[],this.name=t.name,this.completion=Object.assign(Object.assign({type:"type"},t.completion||{}),{label:this.name}),this.openCompletion=Object.assign(Object.assign({},this.completion),{label:"<"+this.name}),this.closeCompletion=Object.assign(Object.assign({},this.completion),{label:"</"+this.name+">",boost:2}),this.closeNameCompletion=Object.assign(Object.assign({},this.completion),{label:this.name+">"}),this.text=t.textContent?t.textContent.map(a=>({label:a,type:"text"})):[]}}const j=/^[:\-\.\w\u00b7-\uffff]*$/;function S(e){return Object.assign(Object.assign({type:"property"},e.completion||{}),{label:e.name})}function x(e){return typeof e=="string"?{label:`"${e}"`,type:"constant"}:/^"/.test(e.label)?e:Object.assign(Object.assign({},e),{label:`"${e.label}"`})}function A(e,t){let r=[],n=[],a=Object.create(null);for(let l of t){let f=S(l);r.push(f),l.global&&n.push(f),l.values&&(a[l.name]=l.values.map(x))}let o=[],m=[],h=Object.create(null);for(let l of e){let f=n,i=a;l.attributes&&(f=f.concat(l.attributes.map(p=>typeof p=="string"?r.find(b=>b.label==p)||{label:p,type:"property"}:(p.values&&(i==a&&(i=Object.create(i)),i[p.name]=p.values.map(x)),S(p)))));let g=new P(l,f,i);h[g.name]=g,o.push(g),l.top&&m.push(g)}m.length||(m=o);for(let l=0;l<o.length;l++){let f=e[l],i=o[l];if(f.children)for(let g of f.children)h[g]&&i.children.push(h[g]);else i.children=o}return l=>{var f;let{doc:i}=l.state,g=M(l.state,l.pos);if(!g||g.type=="tag"&&!l.explicit)return null;let{type:p,from:b,context:d}=g;if(p=="openTag"){let s=m,u=O(i,d);if(u){let c=h[u];s=c?.children||o}return{from:b,options:s.map(c=>c.completion),validFor:j}}else if(p=="closeTag"){let s=O(i,d);return s?{from:b,to:l.pos+(i.sliceString(l.pos,l.pos+1)==">"?1:0),options:[((f=h[s])===null||f===void 0?void 0:f.closeNameCompletion)||{label:s+">",type:"type"}],validFor:j}:null}else if(p=="attrName"){let s=h[C(i,d)];return{from:b,options:s?.attrs||n,validFor:j}}else if(p=="attrValue"){let s=D(i,d,b);if(!s)return null;let u=h[C(i,d)],c=(u?.attrValues||a)[s];return!c||!c.length?null:{from:b,to:l.pos+(i.sliceString(l.pos,l.pos+1)=='"'?1:0),options:c,validFor:/^"[^"]*"?$/}}else if(p=="tag"){let s=O(i,d),u=h[s],c=[],T=d&&d.lastChild;s&&(!T||T.name!="CloseTag"||C(i,T)!=s)&&c.push(u?u.closeCompletion:{label:"</"+s+">",type:"type",boost:2});let y=c.concat((u?.children||(d?o:m)).map(v=>v.openCompletion));if(d&&u?.text.length){let v=d.firstChild;v.to>l.pos-20&&!/\S/.test(l.state.sliceDoc(v.to,l.pos))&&(y=y.concat(u.text))}return{from:b,options:y,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}else return null}}const E=F.define({name:"xml",parser:V.configure({props:[$.add({Element(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),w.add({Element(e){let t=e.firstChild,r=e.lastChild;return!t||t.name!="OpenTag"?null:{from:t.to,to:r.name=="CloseTag"?r.from:e.to}}}),I.add({"OpenTag CloseTag":e=>e.getChild("TagName")})]}),languageData:{commentTokens:{block:{open:"<!--",close:"-->"}},indentOnInput:/^\s*<\/$/}});function _(e={}){return new L(E,E.data.of({autocomplete:A(e.elements||[],e.attributes||[])}))}export{A as completeFromSchema,_ as xml,E as xmlLanguage};

The same content is in 13 releases, Joomla 5.0.1-rc1 to 5.1.0-beta1. See them all, or every version of this file.