@ulb-darmstadt/shacl-form 3.5.1 → 3.6.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.
- package/dist/assets/mode-BjerpqwF.js +13 -0
- package/dist/assets/mode-DEn7GsXU.js +13 -0
- package/dist/assets/{query-Bxz3-v4Z.js → query-C463ReGC.js} +8 -7
- package/dist/assets/{query-B8jMIyRl.js → query-CWsV9IRb.js} +5 -4
- package/dist/bundle.js +3 -3
- package/dist/index.js +3 -3
- package/dist/query/index.d.ts +9 -2
- package/package.json +2 -2
- package/src/query/query-mode.md +5 -0
- package/dist/assets/mode-DBZFH4zN.js +0 -13
- package/dist/assets/mode-eS6CudN5.js +0 -13
package/dist/query/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type QueryField = {
|
|
|
4
4
|
id: string;
|
|
5
5
|
path: QueryPathSegment[];
|
|
6
6
|
shapePath?: string[];
|
|
7
|
+
/** Value fixed by sh:hasValue on the property's shape. */
|
|
8
|
+
fixedValue?: Term;
|
|
7
9
|
datatype?: string;
|
|
8
10
|
discrete?: boolean;
|
|
9
11
|
};
|
|
@@ -32,6 +34,10 @@ export type HeatmapGrid = {
|
|
|
32
34
|
export type QueryFacet = {
|
|
33
35
|
fieldId: string;
|
|
34
36
|
count: number;
|
|
37
|
+
/** The facet cannot offer a meaningful editor, regardless of an active criterion. */
|
|
38
|
+
unavailable?: boolean;
|
|
39
|
+
/** Value selected when this field receives its first facet and has no active criterion. */
|
|
40
|
+
initialValue?: Term;
|
|
35
41
|
buckets?: {
|
|
36
42
|
value: Term;
|
|
37
43
|
label?: string;
|
|
@@ -60,8 +66,9 @@ export type QueryChange = {
|
|
|
60
66
|
export type QueryEditor = HTMLElement & {
|
|
61
67
|
queryField: QueryField;
|
|
62
68
|
getQueryCriteria: () => QueryCriterion[];
|
|
63
|
-
|
|
69
|
+
/** Returns true when applying the facet created an initial criterion. */
|
|
70
|
+
setQueryFacet: (facet?: QueryFacet) => boolean | void;
|
|
64
71
|
/** Optional so custom and plugin editors stay compatible with criterion invalidation. */
|
|
65
72
|
clearQueryCriteria?: () => void;
|
|
66
|
-
|
|
73
|
+
unavailable?: boolean;
|
|
67
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulb-darmstadt/shacl-form",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "SHACL form generator",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^8.1.5"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@ro-kit/ui-widgets": "^1.0.
|
|
89
|
+
"@ro-kit/ui-widgets": "^1.0.63",
|
|
90
90
|
"jsonld": "^9.0.0",
|
|
91
91
|
"leaflet": "^1.9.4",
|
|
92
92
|
"leaflet-editable": "^1.3.2",
|
package/src/query/query-mode.md
CHANGED
|
@@ -53,6 +53,7 @@ type QueryField = {
|
|
|
53
53
|
id: string
|
|
54
54
|
path: QueryPathSegment[]
|
|
55
55
|
shapePath?: string[]
|
|
56
|
+
fixedValue?: Term
|
|
56
57
|
datatype?: string
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -65,6 +66,7 @@ type QueryPathSegment = string | string[]
|
|
|
65
66
|
- `field.id` is an opaque, form-generated identifier. Use it to correlate a field with facet results; do not derive backend meaning from it.
|
|
66
67
|
- `field.path` is the complete RDF predicate path from the root resource to the value. A nested field can therefore have a path such as `[ex:author, ex:name]`. An array-valued segment represents `sh:alternativePath`, for example `[[ex:father, ex:mother], ex:name]`.
|
|
67
68
|
- `field.shapePath` identifies the property-shape branch. It distinguishes qualified or alternative branches that have the same RDF predicate path.
|
|
69
|
+
- `field.fixedValue` is the property's `sh:hasValue`, when present. Facet providers can use this shape-fixed metadata without creating a user-selectable criterion.
|
|
68
70
|
- `field.datatype` is the field's datatype IRI when the shape supplies one.
|
|
69
71
|
|
|
70
72
|
All criteria are combined with logical AND and apply to the same root resource. RDF path segments describe traversal from that root; intermediate resources are not result rows.
|
|
@@ -124,6 +126,7 @@ Return one facet per field that the backend can describe:
|
|
|
124
126
|
type QueryFacet = {
|
|
125
127
|
fieldId: string
|
|
126
128
|
count: number
|
|
129
|
+
initialValue?: Term
|
|
127
130
|
buckets?: Array<{
|
|
128
131
|
value: Term
|
|
129
132
|
label?: string
|
|
@@ -137,8 +140,10 @@ type QueryFacet = {
|
|
|
137
140
|
|
|
138
141
|
- `fieldId` must equal the corresponding `QueryField.id`.
|
|
139
142
|
- `count` is the number of matching root resources for which the field is available. Providers should count distinct roots when RDF joins can produce duplicates.
|
|
143
|
+
- `initialValue` pre-selects a discrete bucket when the first facets are applied and the field has no active criterion. It is ignored on later refreshes, so users can clear the selection. When an initial value is applied, the form emits the resulting query and refreshes facets once.
|
|
140
144
|
- `buckets` supplies discrete RDF values, optional display labels, and counts. For a field with `sh:in`, buckets outside the shape's allowed values are discarded. An active value missing from refreshed buckets remains selectable with count zero so the user can remove it.
|
|
141
145
|
- `min` and `max` supply typed bounds for numeric and temporal fields. When they form a usable interval, the two bound inputs become a range slider.
|
|
146
|
+
- `unavailable: true` hides a facet that cannot offer a meaningful editor, even when it has an active criterion.
|
|
142
147
|
- `error: true` marks a field-level failure.
|
|
143
148
|
|
|
144
149
|
An inactive leaf with `count: 0` is given the `query-unavailable` class and hidden by the default theme. An active field remains visible even when its count becomes zero. Structural parent branches are hidden when they contain no available leaf. The host element receives `query-facets-empty` when no filter is available and affected properties receive `query-facet-error` for field-level failures.
|
|
@@ -1,13 +0,0 @@
|
|
|
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-B8jMIyRl.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 r=S(t,o);r&&r[0]<r[1]&&(c=r);let i=u??k(r,e&&c);if(!i||i[0]===i[1]){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value)),n.invalid=!0;return}(e?.min||e?.max)&&(u??=i);let s=new y;s.classList.add(`editor`,`query-range-slider`),s.dense=t.config.theme.dense,s.clearable=!0,s.range=``,s.setAttribute(`range`,``),s.min=String(i[0]),s.max=String(i[1]),s.step=String(C(t,i)),s.labelFormatter=e=>w(e,t);let l=e?.min?T(e.min,t):i[0],d=e?.max?T(e.max,t):i[1];s.value=JSON.stringify([O(l??i[0],i[0],i[1]),O(d??i[1],i[0],i[1])]),s.dataset.active=e?.min||e?.max?`true`:`false`,s.addEventListener(`change`,()=>{s.dataset.active=`true`,u??=[Number(s.min),Number(s.max)]}),a.appendChild(s)};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=t=>{e.container.appendChild(t),t.invalid&&e.classList.add(`query-unavailable`)},r=e.template;if(r.or?.length||r.xone?.length){let n=W(r);if(n){t(V(n,e.parent));return}let i=r.or?.length?r.or:r.xone;e.container.appendChild(h(i,e,r.config));return}if(!r.nodeShapes.size){t(V(r,e.parent));return}if(B(r)){let n=i(r);n.facet=!0,n.nodeShapes=new Set;for(let e of r.nodeShapes)if(e.targetClass){n.class=e.targetClass;break}n.nodeKind??=s,t(V(n,e.parent));return}for(let t of r.nodeShapes){let i=new Set(e.parent.ancestorShapeIds);if(i.add(e.parent.template.id.value),i.has(t.id.value))continue;let a=e.parent.queryContext??{path:[],shapePath:[]},o=new u(t,void 0,r.nodeKind,r.label,!1,i,{path:[...a.path,n(r)],shapePath:[...a.shapePath,G(r)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),r.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};
|
|
@@ -1,13 +0,0 @@
|
|
|
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-Bxz3-v4Z.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 r=S(t,o);r&&r[0]<r[1]&&(c=r);let i=l??k(r,e&&c);if(!i||i[0]===i[1]){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value)),n.invalid=!0;return}(e?.min||e?.max)&&(l??=i);let s=new b;s.classList.add(`editor`,`query-range-slider`),s.dense=t.config.theme.dense,s.clearable=!0,s.range=``,s.setAttribute(`range`,``),s.min=String(i[0]),s.max=String(i[1]),s.step=String(C(t,i)),s.labelFormatter=e=>w(e,t);let u=e?.min?T(e.min,t):i[0],d=e?.max?T(e.max,t):i[1];s.value=JSON.stringify([O(u??i[0],i[0],i[1]),O(d??i[1],i[0],i[1])]),s.dataset.active=e?.min||e?.max?`true`:`false`,s.addEventListener(`change`,()=>{s.dataset.active=`true`,l??=[Number(s.min),Number(s.max)]}),a.appendChild(s)};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=t=>{e.container.appendChild(t),t.invalid&&e.classList.add(`query-unavailable`)},r=e.template;if(r.or?.length||r.xone?.length){let n=W(r);if(n){t(V(n,e.parent));return}let i=r.or?.length?r.or:r.xone;e.container.appendChild(f(i,e,r.config));return}if(!r.nodeShapes.size){t(V(r,e.parent));return}if(B(r)){let n=i(r);n.facet=!0,n.nodeShapes=new Set;for(let e of r.nodeShapes)if(e.targetClass){n.class=e.targetClass;break}n.nodeKind??=d,t(V(n,e.parent));return}for(let t of r.nodeShapes){let i=new Set(e.parent.ancestorShapeIds);if(i.add(e.parent.template.id.value),i.has(t.id.value))continue;let a=e.parent.queryContext??{path:[],shapePath:[]},o=new h(t,void 0,r.nodeKind,r.label,!1,i,{path:[...a.path,n(r)],shapePath:[...a.shapePath,G(r)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),r.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};
|