@ulb-darmstadt/shacl-form 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import{D as e,L as t,O as n,P as r,T as i,U as a,W as o,Y as s,a as c,et as l,n as u,o as d,p as f,q as p,t as m,x as h}from"./query-iCQx9XSS.js";import{DataFactory as g}from"n3";import{RokitInput as _,RokitSelect as v,RokitSlider as y,epochToDate as b}from"@ro-kit/ui-widgets";function x(e,t){let n=document.createElement(`div`),r=!!(t.facet||t.in||t.class||t.datatype?.equals(l));n.classList.add(`query-editor`),n.dataset.queryFieldId=e.id,n.setAttribute(`part`,`query-editor`);let i=document.createElement(`label`);i.textContent=t.label,t.description&&(i.title=t.description.value),n.appendChild(i);let a=document.createElement(`div`);a.classList.add(`query-controls`),n.appendChild(a);let o,s=A(t),c,u,d=(e=``)=>{let n=document.createElement(`div`);n.classList.add(`query-value-row`);let r=new v;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=t.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of s){let t=document.createElement(`li`);if(t.dataset.value=F(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,n.appendChild(r),n},f=(e=[])=>{a.replaceChildren(),a.appendChild(d(e[0]??``))},h=(e,n=``)=>{let r=new _;return r.classList.add(`editor`,`query-range-bound`),r.type=P(t),r.label=e,r.clearable=!0,r.dense=t.config.theme.dense,r.value=n,r},g=e=>{a.replaceChildren();let n=S(t,o);n&&n[0]<n[1]&&(c=n);let r=u??k(n,e&&c);if(!r||r[0]===r[1]){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value));return}(e?.min||e?.max)&&(u??=r);let i=new y;i.classList.add(`editor`,`query-range-slider`),i.dense=t.config.theme.dense,i.clearable=!0,i.range=``,i.setAttribute(`range`,``),i.min=String(r[0]),i.max=String(r[1]),i.step=String(C(t,r)),i.labelFormatter=e=>w(e,t);let s=e?.min?T(e.min,t):r[0],l=e?.max?T(e.max,t):r[1];i.value=JSON.stringify([O(s??r[0],r[0],r[1]),O(l??r[1],r[0],r[1])]),i.dataset.active=e?.min||e?.max?`true`:`false`,i.addEventListener(`change`,()=>{i.dataset.active=`true`,u??=[Number(i.min),Number(i.max)]}),a.appendChild(i)};return n.getQueryCriteria=()=>{if(m(e)){let n=a.querySelector(`rokit-slider`);if(n){if(n.dataset.active!==`true`)return[];let r=D(n.value);return r?[{field:e,operator:`range`,min:E(r[0],t),max:E(r[1],t)}]:[]}let r=a.querySelectorAll(`rokit-input`),i=M(r[0]?.value,t),o=M(r[1]?.value,t);return i||o?[{field:e,operator:`range`,min:i,max:o}]:[]}if(r)return Array.from(a.querySelectorAll(`rokit-select`)).flatMap(t=>{if(!t.value)return[];let n=s.find(e=>F(e.term)===t.value)?.term;return n?[{field:e,operator:`equals`,value:n}]:[]});let n=N(t)&&!t.class&&!t.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(a.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=M(i?.value,t,a);return o?[{field:e,operator:n,value:o}]:[]})},n.clearQueryCriteria=()=>{if(m(e)){u=void 0,c=void 0;let e=a.querySelector(`rokit-slider`);if(e)e.dataset.active=`false`,e.value=JSON.stringify([Number(e.min),Number(e.max)]);else for(let e of a.querySelectorAll(`rokit-input`))e.value=``}else if(r)for(let e of a.querySelectorAll(`rokit-select`))e.value=``;else for(let e of a.querySelectorAll(`.query-value`))e.value=``},n.setQueryFacet=i=>{let c=n.getQueryCriteria();if(o=i,r&&o?.buckets){let e=new Map(A(t).map(e=>[F(e.term),e])),n=new Map(c.flatMap(e=>e.value?[[F(e.value),e.value]]:[]));s=o.buckets.flatMap(n=>{let r=e.get(F(n.value));return t.in&&!r?[]:[{term:n.value,label:n.label??r?.label??n.value.value,count:n.count}]});for(let[t,r]of n)s.some(e=>F(e.term)===t)||s.push({term:r,label:e.get(t)?.label??r.value,count:0});f([...n.keys()])}else if(m(e)){let e=c[0];g(e?{min:e.min,max:e.max}:void 0)}else if(!i)for(let e of a.querySelectorAll(`.query-value`))e.value=``},m(e)?g():r?f():(a.replaceChildren(),a.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let r=new _;r.classList.add(`editor`,`query-value`),r.type=P(t),r.clearable=!0,r.dense=t.config.theme.dense;let i;if(r.addEventListener(`input`,()=>{clearTimeout(i),i=setTimeout(()=>{n.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(r),t.datatype?.equals(p)){let n=t.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(n.classList.add(`lang-chooser`,`query-language`),n.title=`Language of the text`,n.setAttribute(`aria-label`,`Language of the text`),n instanceof HTMLSelectElement)for(let e of t.languageIn??[]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.value,n.appendChild(t)}else n.maxLength=35,n.placeholder=`lang?`,n.value=t.config.languages.find(e=>e.length>0)??``;e.appendChild(n)}return e})())),n}function S(e,t){let n=t?.min?T(t.min,e):void 0,r=t?.max?T(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n===void 0?i:i===void 0?n:Math.max(n,i),s=r===void 0?a:a===void 0?r:Math.min(r,a);return o!==void 0&&s!==void 0&&Number.isFinite(o)&&Number.isFinite(s)&&o<=s?[o,s]:void 0}function C(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function w(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?b(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?b(e):String(Math.round(e*1e3)/1e3)}function T(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function E(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?g.literal(b(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?g.literal(b(e),n):g.literal(String(e),n)}function D(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function O(e,t,n){return Math.min(n,Math.max(t,e))}function k(e,t){return e&&e[0]<e[1]?e:t||e}function A(e){if(e.datatype?.equals(l))return[{term:g.literal(`true`,l),label:`true`},{term:g.literal(`false`,l),label:`false`}];let n=[];return e.in?n=r(e.config.lists[e.in]??[],e.config.store,e.config.languages):e.class&&(n=t(e.class,e)),j(n)}function j(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...j(e.children??[])])}function M(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?g.namedNode(e):t.datatype?.equals(p)?n?g.literal(e,n):void 0:t.datatype?g.literal(e,t.datatype):g.literal(e)}function N(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(p)}function P(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function F(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var I=`form.mode-query { padding: 0; }
2
+ :host([loading]) form.mode-query > shacl-node { display: none; }
3
+ .mode-query shacl-property.query-unavailable { display: none; }
4
+ .mode-query .shacl-group:not(:has(shacl-property:not(.query-unavailable))), .mode-query shacl-node:not(:has(shacl-property:not(.query-unavailable))) { display: none; }
5
+ .query-editor { display: flex; align-items: center; width: 100%; padding: 3px 0; }
6
+ .query-editor > label { width: var(--label-width); flex-shrink: 0; padding-right: 1em; word-break: break-word; }
7
+ .query-controls { display: flex; flex: 1; min-width: 0; }
8
+ .query-controls > rokit-input, .query-controls > rokit-slider, .query-value-row > rokit-input, .query-value-row > rokit-select { min-height: 28px; width: 100%; flex-grow: 1; }
9
+ .query-value-row { display: flex; flex: 1; width: 100%; min-width: 0; gap: 4px; }
10
+ .query-language { min-height: 28px; flex: 0 0 auto; }
11
+ .query-range-slider[data-active='false'] { opacity: 0.7; }
12
+ .query-facet-error .query-editor > label { color: var(--shacl-error-color); }
13
+ `,L=0,R=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(I),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),t=this.getQuery(),n=this.host.config.queryFacetProvider;if(this.previousQuery&&n?.invalidatedFields){let r=new Set(n.invalidatedFields({previousQuery:this.previousQuery,query:t,fields:e}));for(let e of this.host.form.querySelectorAll(`.query-editor`))r.has(e.queryField.id)&&e.clearQueryCriteria?.();t=this.getQuery()}this.previousQuery=t,this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:t})),await this.requestFacets(t)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;this.applyFacets(a),this.facetsApplied=!0,this.setFacetsPending(!1)}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e){let t=new Map(e.map(e=>[e.fieldId,e]));for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let n=t.get(e.queryField.id),r=e.getQueryCriteria().length>0;e.setQueryFacet(n);let i=e.closest(`shacl-property`);i?.classList.toggle(`query-unavailable`,n?.count===0&&!r),i?.classList.toggle(`query-facet-error`,n?.error===!0)}let n=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of n){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let r=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));this.host.classList.toggle(`query-facets-empty`,!r)}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function z(e){let t=e.template;if(t.or?.length||t.xone?.length){let n=W(t);if(n){e.container.appendChild(V(n,e.parent));return}let r=t.or?.length?t.or:t.xone;e.container.appendChild(h(r,e,t.config));return}if(!t.nodeShapes.size){e.container.appendChild(V(t,e.parent));return}if(B(t)){let n=i(t);n.facet=!0,n.nodeShapes=new Set;for(let e of t.nodeShapes)if(e.targetClass){n.class=e.targetClass;break}n.nodeKind??=s,e.container.appendChild(V(n,e.parent));return}for(let r of t.nodeShapes){let i=new Set(e.parent.ancestorShapeIds);if(i.add(e.parent.template.id.value),i.has(r.id.value))continue;let a=e.parent.queryContext??{path:[],shapePath:[]},o=new u(r,void 0,t.nodeKind,t.label,!1,i,{path:[...a.path,n(t)],shapePath:[...a.shapePath,G(t)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),t.config.hierarchyColorsStyleSheet!==void 0&&s.appendChild(d(!0)),s.appendChild(o),e.container.appendChild(s),await o.ready}}function B(e){return e.facet===void 0?Array.from(e.nodeShapes).some(e=>e.facet===!0):e.facet}function V(e,t){let r=t.queryContext??{path:[],shapePath:[]},i={id:`qf${(L++).toString(36)}`,path:[...r.path,n(e)],shapePath:[...r.shapePath,G(e)],datatype:e.datatype?.value,discrete:e.facet===!0},a=f(e.path,e.datatype?.value)?.createQueryEditor?.(i,e)??x(i,e);return a.queryField=i,a.classList.add(`property-instance`,`query-editor`),a.dataset.path=e.path,a}async function H(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function U(e,t,n){e.or=void 0,e.xone=void 0;let r=new c(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function W(t){let n=t.or??t.xone;if(!n?.length)return;let r=n.map(n=>{let r=i(t);return r.or=void 0,r.xone=void 0,e(r,t.config.store.getQuads(n,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(r.some(e=>!e||!o.has(e.value)))return;let s=i(t);return s.or=void 0,s.xone=void 0,s.datatype=r.find(e=>e&&a.has(e.value))??r[0],s}function G(e){return e.qualifiedValueShape||e.pathAlternatives?e.queryShapePathId??e.id.value:e.path}export{R as QueryModeController,H as activateNodeConstraintOption,U as activatePropertyConstraintOption,z as initializeQueryProperty};
@@ -0,0 +1,13 @@
1
+ import{$ as e,F as t,I as n,K as r,N as i,Q as a,U as o,a as s,b as c,ft as l,h as u,it as d,k as f,lt as p,m,n as h,nt as g,o as _,p as v,t as y,v as b}from"./query-C9SE6CaJ.js";function x(e,t){let n=document.createElement(`div`),r=!!(t.facet||t.in||t.class||t.datatype?.equals(p));n.classList.add(`query-editor`),n.dataset.queryFieldId=e.id,n.setAttribute(`part`,`query-editor`);let i=document.createElement(`label`);i.textContent=t.label,t.description&&(i.title=t.description.value),n.appendChild(i);let a=document.createElement(`div`);a.classList.add(`query-controls`),n.appendChild(a);let o,s=A(t),c,l,d=(e=``)=>{let n=document.createElement(`div`);n.classList.add(`query-value-row`);let r=new m;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=t.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of s){let t=document.createElement(`li`);if(t.dataset.value=F(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,n.appendChild(r),n},f=(e=[])=>{a.replaceChildren(),a.appendChild(d(e[0]??``))},h=(e,n=``)=>{let r=new u;return r.classList.add(`editor`,`query-range-bound`),r.type=P(t),r.label=e,r.clearable=!0,r.dense=t.config.theme.dense,r.value=n,r},_=e=>{a.replaceChildren();let n=S(t,o);n&&n[0]<n[1]&&(c=n);let r=l??k(n,e&&c);if(!r||r[0]===r[1]){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value));return}(e?.min||e?.max)&&(l??=r);let i=new b;i.classList.add(`editor`,`query-range-slider`),i.dense=t.config.theme.dense,i.clearable=!0,i.range=``,i.setAttribute(`range`,``),i.min=String(r[0]),i.max=String(r[1]),i.step=String(C(t,r)),i.labelFormatter=e=>w(e,t);let s=e?.min?T(e.min,t):r[0],u=e?.max?T(e.max,t):r[1];i.value=JSON.stringify([O(s??r[0],r[0],r[1]),O(u??r[1],r[0],r[1])]),i.dataset.active=e?.min||e?.max?`true`:`false`,i.addEventListener(`change`,()=>{i.dataset.active=`true`,l??=[Number(i.min),Number(i.max)]}),a.appendChild(i)};return n.getQueryCriteria=()=>{if(y(e)){let n=a.querySelector(`rokit-slider`);if(n){if(n.dataset.active!==`true`)return[];let r=D(n.value);return r?[{field:e,operator:`range`,min:E(r[0],t),max:E(r[1],t)}]:[]}let r=a.querySelectorAll(`rokit-input`),i=M(r[0]?.value,t),o=M(r[1]?.value,t);return i||o?[{field:e,operator:`range`,min:i,max:o}]:[]}if(r)return Array.from(a.querySelectorAll(`rokit-select`)).flatMap(t=>{if(!t.value)return[];let n=s.find(e=>F(e.term)===t.value)?.term;return n?[{field:e,operator:`equals`,value:n}]:[]});let n=N(t)&&!t.class&&!t.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(a.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=M(i?.value,t,a);return o?[{field:e,operator:n,value:o}]:[]})},n.clearQueryCriteria=()=>{if(y(e)){l=void 0,c=void 0;let e=a.querySelector(`rokit-slider`);if(e)e.dataset.active=`false`,e.value=JSON.stringify([Number(e.min),Number(e.max)]);else for(let e of a.querySelectorAll(`rokit-input`))e.value=``}else if(r)for(let e of a.querySelectorAll(`rokit-select`))e.value=``;else for(let e of a.querySelectorAll(`.query-value`))e.value=``},n.setQueryFacet=i=>{let c=n.getQueryCriteria();if(o=i,r&&o?.buckets){let e=new Map(A(t).map(e=>[F(e.term),e])),n=new Map(c.flatMap(e=>e.value?[[F(e.value),e.value]]:[]));s=o.buckets.flatMap(n=>{let r=e.get(F(n.value));return t.in&&!r?[]:[{term:n.value,label:n.label??r?.label??n.value.value,count:n.count}]});for(let[t,r]of n)s.some(e=>F(e.term)===t)||s.push({term:r,label:e.get(t)?.label??r.value,count:0});f([...n.keys()])}else if(y(e)){let e=c[0];_(e?{min:e.min,max:e.max}:void 0)}else if(!i)for(let e of a.querySelectorAll(`.query-value`))e.value=``},y(e)?_():r?f():(a.replaceChildren(),a.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let r=new u;r.classList.add(`editor`,`query-value`),r.type=P(t),r.clearable=!0,r.dense=t.config.theme.dense;let i;if(r.addEventListener(`input`,()=>{clearTimeout(i),i=setTimeout(()=>{n.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(r),t.datatype?.equals(g)){let n=t.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(n.classList.add(`lang-chooser`,`query-language`),n.title=`Language of the text`,n.setAttribute(`aria-label`,`Language of the text`),n instanceof HTMLSelectElement)for(let e of t.languageIn??[]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.value,n.appendChild(t)}else n.maxLength=35,n.placeholder=`lang?`,n.value=t.config.languages.find(e=>e.length>0)??``;e.appendChild(n)}return e})())),n}function S(e,t){let n=t?.min?T(t.min,e):void 0,r=t?.max?T(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n===void 0?i:i===void 0?n:Math.max(n,i),s=r===void 0?a:a===void 0?r:Math.min(r,a);return o!==void 0&&s!==void 0&&Number.isFinite(o)&&Number.isFinite(s)&&o<=s?[o,s]:void 0}function C(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function w(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?v(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?v(e):String(Math.round(e*1e3)/1e3)}function T(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function E(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?l.literal(v(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?l.literal(v(e),n):l.literal(String(e),n)}function D(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function O(e,t,n){return Math.min(n,Math.max(t,e))}function k(e,t){return e&&e[0]<e[1]?e:t||e}function A(e){if(e.datatype?.equals(p))return[{term:l.literal(`true`,p),label:`true`},{term:l.literal(`false`,p),label:`false`}];let t=[];return e.in?t=o(e.config.lists[e.in]??[],e.config.store,e.config.languages):e.class&&(t=r(e.class,e)),j(t)}function j(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...j(e.children??[])])}function M(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?l.namedNode(e):t.datatype?.equals(g)?n?l.literal(e,n):void 0:t.datatype?l.literal(e,t.datatype):l.literal(e)}function N(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(g)}function P(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function F(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var I=`form.mode-query { padding: 0; }
2
+ :host([loading]) form.mode-query > shacl-node { display: none; }
3
+ .mode-query shacl-property.query-unavailable { display: none; }
4
+ .mode-query .shacl-group:not(:has(shacl-property:not(.query-unavailable))), .mode-query shacl-node:not(:has(shacl-property:not(.query-unavailable))) { display: none; }
5
+ .query-editor { display: flex; align-items: center; width: 100%; padding: 3px 0; }
6
+ .query-editor > label { width: var(--label-width); flex-shrink: 0; padding-right: 1em; word-break: break-word; }
7
+ .query-controls { display: flex; flex: 1; min-width: 0; }
8
+ .query-controls > rokit-input, .query-controls > rokit-slider, .query-value-row > rokit-input, .query-value-row > rokit-select { min-height: 28px; width: 100%; flex-grow: 1; }
9
+ .query-value-row { display: flex; flex: 1; width: 100%; min-width: 0; gap: 4px; }
10
+ .query-language { min-height: 28px; flex: 0 0 auto; }
11
+ .query-range-slider[data-active='false'] { opacity: 0.7; }
12
+ .query-facet-error .query-editor > label { color: var(--shacl-error-color); }
13
+ `,L=0,R=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(I),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),t=this.getQuery(),n=this.host.config.queryFacetProvider;if(this.previousQuery&&n?.invalidatedFields){let r=new Set(n.invalidatedFields({previousQuery:this.previousQuery,query:t,fields:e}));for(let e of this.host.form.querySelectorAll(`.query-editor`))r.has(e.queryField.id)&&e.clearQueryCriteria?.();t=this.getQuery()}this.previousQuery=t,this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:t})),await this.requestFacets(t)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;this.applyFacets(a),this.facetsApplied=!0,this.setFacetsPending(!1)}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e){let t=new Map(e.map(e=>[e.fieldId,e]));for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let n=t.get(e.queryField.id),r=e.getQueryCriteria().length>0;e.setQueryFacet(n);let i=e.closest(`shacl-property`);i?.classList.toggle(`query-unavailable`,n?.count===0&&!r),i?.classList.toggle(`query-facet-error`,n?.error===!0)}let n=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of n){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let r=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));this.host.classList.toggle(`query-facets-empty`,!r)}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function z(e){let t=e.template;if(t.or?.length||t.xone?.length){let n=W(t);if(n){e.container.appendChild(V(n,e.parent));return}let r=t.or?.length?t.or:t.xone;e.container.appendChild(f(r,e,t.config));return}if(!t.nodeShapes.size){e.container.appendChild(V(t,e.parent));return}if(B(t)){let n=i(t);n.facet=!0,n.nodeShapes=new Set;for(let e of t.nodeShapes)if(e.targetClass){n.class=e.targetClass;break}n.nodeKind??=d,e.container.appendChild(V(n,e.parent));return}for(let r of t.nodeShapes){let i=new Set(e.parent.ancestorShapeIds);if(i.add(e.parent.template.id.value),i.has(r.id.value))continue;let a=e.parent.queryContext??{path:[],shapePath:[]},o=new h(r,void 0,t.nodeKind,t.label,!1,i,{path:[...a.path,n(t)],shapePath:[...a.shapePath,G(t)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),t.config.hierarchyColorsStyleSheet!==void 0&&s.appendChild(_(!0)),s.appendChild(o),e.container.appendChild(s),await o.ready}}function B(e){return e.facet===void 0?Array.from(e.nodeShapes).some(e=>e.facet===!0):e.facet}function V(e,t){let r=t.queryContext??{path:[],shapePath:[]},i={id:`qf${(L++).toString(36)}`,path:[...r.path,n(e)],shapePath:[...r.shapePath,G(e)],datatype:e.datatype?.value,discrete:e.facet===!0},a=c(e.path,e.datatype?.value)?.createQueryEditor?.(i,e)??x(i,e);return a.queryField=i,a.classList.add(`property-instance`,`query-editor`),a.dataset.path=e.path,a}async function H(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function U(e,t,n){e.or=void 0,e.xone=void 0;let r=new s(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function W(n){let r=n.or??n.xone;if(!r?.length)return;let o=r.map(e=>{let r=i(n);return r.or=void 0,r.xone=void 0,t(r,n.config.store.getQuads(e,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(o.some(t=>!t||!e.has(t.value)))return;let s=i(n);return s.or=void 0,s.xone=void 0,s.datatype=o.find(e=>e&&a.has(e.value))??o[0],s}function G(e){return e.qualifiedValueShape||e.pathAlternatives?e.queryShapePathId??e.id.value:e.path}export{R as QueryModeController,H as activateNodeConstraintOption,U as activatePropertyConstraintOption,z as initializeQueryProperty};