@ulb-darmstadt/shacl-form 3.7.0 → 3.7.2
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-Cj8mO4Xn.js +13 -0
- package/dist/assets/mode-DH9hcPDl.js +13 -0
- package/dist/assets/{query-DbfDRxlr.js → query-BSFvTpfv.js} +2 -2
- package/dist/assets/{query-byEWeJbo.js → query-DNdA4lu-.js} +2 -2
- package/dist/bundle.js +9 -9
- package/dist/index.js +5 -5
- package/dist/property.d.ts +1 -0
- package/package.json +1 -1
- package/dist/assets/mode-CW6bB5zW.js +0 -13
- package/dist/assets/mode-DosrdOwE.js +0 -13
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import{$ as e,A as t,B as n,C as r,
|
|
1
|
+
import{$ as e,A as t,B as n,C as r,D as i,H as a,I as o,K as s,L as c,M as l,N as u,P as d,Q as ee,T as f,U as p,V as m,W as h,X as g,Y as _,Z as v,_ as y,b,c as x,d as S,et as te,f as C,g as w,h as T,i as E,j as D,l as O,n as k,p as A,r as j,t as ne,tt as re,u as M,v as N,w as P,x as F,y as I,z as L}from"./assets/query-BSFvTpfv.js";import{BlankNode as R,DataFactory as z,Literal as B,NamedNode as V,Store as H}from"n3";import{RokitButton as U,RokitCollapsible as W,RokitInput as G,RokitSelect as K,RokitTextArea as q}from"@ro-kit/ui-widgets";import{Validator as J}from"shacl-engine";var Y=`
|
|
2
2
|
.editor:not([type='checkbox']) { border: 1px solid var(--shacl-border-color, #DDD); }
|
|
3
3
|
.property-instance label { display: inline-flex; align-self: center; word-break: break-word; line-height: 1em; padding-right: 1em; flex-shrink: 0; position: relative; }
|
|
4
4
|
.property-instance:has(> .editor:is(textarea, rokit-textarea)) > label { align-self: flex-start; padding-top: 0.45em; }
|
|
5
5
|
.property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
|
|
6
6
|
.mode-edit .property-instance label { width: var(--label-width); }
|
|
7
|
-
`,X=class extends
|
|
8
|
-
`+t}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){let e=new Z;return Object.keys(e).map(e=>(e=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase()),`data-`+e))}buildTemplateKey(e,t){let n=e.value;return t&&(t instanceof
|
|
7
|
+
`,X=class extends F{constructor(e){super(e||Y),this.idCtr=0}createDefaultTemplate(e,t,n,r,i){let a=t??i?.defaultValue??null;if(r.id=`e${this.idCtr++}`,r.classList.add(`editor`),r.setAttribute(`part`,`editor`),i?.datatype?r.shaclDatatype=i.datatype:t instanceof B&&(r.shaclDatatype=t.datatype),i&&f(i)>0&&(r.dataset.minCount=String(f(i))),i?.class&&(r.dataset.class=i.class.value),i?.nodeKind)r.dataset.nodeKind=i.nodeKind.value;else if(t&&(t instanceof V||i?.nodeKind?.equals(g))&&(r.dataset.nodeKind=s+`IRI`,i)){let e=L(i.config.store.getQuads(t,null,null,null),i.config.languages);e&&(t=z.literal(e))}(i?.hasValue&&t||i?.readonly)&&(r.disabled=!0);let o=t?.value||i?.defaultValue?.value||``;t instanceof R?o=t.id:t instanceof V&&i?.nodeKind?.value===`http://www.w3.org/ns/shacl#IRIOrLiteral`&&(o=`<${t.value}>`),i?.datatype?.equals(re)?r.checked=t?.value===`true`||i?.defaultValue?.value===`true`:r.type===`file`?r.binaryData=o||void 0:r.value=o,N(r,a);let c=document.createElement(`label`);c.htmlFor=r.id,c.innerText=e,c.setAttribute(`part`,`label`),i?.description&&c.setAttribute(`title`,i.description.value);let l=i?.description?i.description.value:i?.pattern?i.pattern:null;l&&r.setAttribute(`placeholder`,l),n&&(r.setAttribute(`required`,`true`),c.classList.add(`required`));let u=document.createElement(`div`);return u.setAttribute(`part`,`field`),u.appendChild(c),u.appendChild(r),u}createDateEditor(e,t,r,i){let a=new G;i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?(a.type=`datetime-local`,a.setAttribute(`step`,`1`)):a.type=`date`,a.clearable=!0,a.dense=this.dense,a.classList.add(`pr-0`);let o=this.createDefaultTemplate(e,null,r,a,i);if(t){let e=i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?n(t.value):m(t.value);e?(a.value=e.value,e.suffix&&(a.dataset.xsdTemporalSuffix=e.suffix)):console.error(`unable to parse xsd date literal`,t),N(a,t)}return o}createTextEditor(e,t,n,r){let i;return r.singleLine===!1?(i=new q,i.resize=`auto`):i=new G,i.dense=this.dense,r.pattern&&(i.pattern=r.pattern),r.minLength&&(i.minLength=r.minLength),r.maxLength&&(i.maxLength=r.maxLength),this.createDefaultTemplate(e,t,n,i,r)}createLangStringEditor(e,t,n,r){let i=this.createTextEditor(e,t,n,r),a=i.querySelector(`:scope .editor`),o;if(r.languageIn?.length){o=document.createElement(`select`);for(let e of r.languageIn){let t=document.createElement(`option`);t.innerText=e.value,o.appendChild(t)}}else o=document.createElement(`input`),o.maxLength=5,o.size=5,o.placeholder=`lang?`;return o.title=`Language of the text`,o.classList.add(`lang-chooser`),o.setAttribute(`part`,`lang-chooser`),o.slot=`suffix`,a.addEventListener(`change`,()=>{o.required=a.value!==``}),o.addEventListener(`change`,e=>{e.stopPropagation(),a&&(a.dataset.lang=o.value,a.dispatchEvent(new Event(`change`,{bubbles:!0})))}),t instanceof B&&(o.value=t.language),a.dataset.lang=o.value,N(a,t??r.defaultValue),a.appendChild(o),i}createBooleanEditor(e,t,n,r){let i=document.createElement(`input`);i.type=`checkbox`,i.classList.add(`ml-0`);let a=this.createDefaultTemplate(e,null,n,i,r);return i.removeAttribute(`required`),a.querySelector(`:scope label`)?.classList.remove(`required`),t instanceof B&&(i.checked=t.value===`true`,N(i,t)),a}createFileEditor(e,t,n,r){let i=document.createElement(`input`);return i.type=`file`,i.addEventListener(`change`,e=>{if(i.files?.length){e.stopPropagation();let t=new FileReader;t.readAsDataURL(i.files[0]),t.onload=()=>{i.binaryData=btoa(t.result),i.parentElement?.dispatchEvent(new Event(`change`,{bubbles:!0}))}}else i.binaryData=void 0}),this.createDefaultTemplate(e,t,n,i,r)}createNumberEditor(e,t,n,r){let i=new G,a=h.has(r.datatype?.value??``);i.type=a?`text`:`number`,a&&(i.pattern=r.datatype?.value===`http://www.w3.org/2001/XMLSchema#decimal`?`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)`:`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)(?:[eE][+\\-]?[0-9]+)?`,i.updateComplete.then(()=>{i.inputElement.inputMode=`decimal`}),i.addEventListener(`input`,()=>{i.setCustomValidity(i.validity.patternMismatch?`Value does not have datatype <`+r.datatype?.value+`>`:void 0,i.inputElement)})),i.clearable=!0,i.dense=this.dense,i.classList.add(`pr-0`);let o=r.minInclusive===void 0?r.minExclusive===void 0?void 0:r.minExclusive+1:r.minInclusive,s=r.maxInclusive===void 0?r.maxExclusive===void 0?void 0:r.maxExclusive-1:r.maxInclusive;return o!==void 0&&(i.min=String(o)),s!==void 0&&(i.max=String(s)),!a&&r.datatype?.value!==`http://www.w3.org/2001/XMLSchema#integer`&&(i.step=`any`),this.createDefaultTemplate(e,t,n,i,r)}createListEditor(e,t,n,r,i){let a=new K;a.clearable=!0,a.dense=this.dense;let o=this.createDefaultTemplate(e,null,n,a,i),s=document.createElement(`ul`),c=[],l=!0,u=(e,t)=>{let n=document.createElement(`li`);if(typeof e.value==`string`?(n.dataset.value=e.value,n.innerText=e.label?e.label:e.value):(n.dataset.value=b(e.value),c.push(e.value),n.innerText=e.label?e.label:e.value.value),t.appendChild(n),e.children?.length){l=!1;let t=document.createElement(`ul`);n.appendChild(t);for(let n of e.children)u(n,t)}};for(let e of r)u(e,s);return l||(a.collapse=!0),a.appendChild(s),I(a,c),t=t??i?.defaultValue??null,t&&(a.value=b(t),N(a,t)),o}createButton(e,t){let n=new U;return n.dense=this.dense,n.textContent=e,t?(n.setAttribute(`primary`,``),n.setAttribute(`part`,`button primary`)):n.setAttribute(`part`,`button`),n}},Z=class{constructor(){this.shapes=null,this.shapesUrl=null,this.shapeSubject=null,this.values=null,this.valuesUrl=null,this.valueSubject=null,this.valuesSubject=null,this.valuesNamespace=``,this.valuesGraph=null,this.preserveUnmappedValues=null,this.view=null,this.mode=null,this.language=null,this.loading=`Loading…`,this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=p.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense=`true`,this.useShadowRoot=`true`}},ie=`#4c93d785, #f85e9a85, #00327385, #87001f85`,Q=class{constructor(e){this.attributes=new Z,this.mode=`edit`,this.lists={},this.groups=[],this.renderedNodes=new Set,this.originalValues=new H,this._store=new H,this._nodeTemplates={},this._propertyTemplates={},this.validator=new J(this._store,{details:!0,factory:z}),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this.form=e,this._theme=new X,this.languages=[...new Set(navigator.languages.flatMap(e=>e.length>2?[e.toLocaleLowerCase(),e.substring(0,2)]:e)),``]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this.originalValues=new H,this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){let t=new Z;if(Object.keys(t).forEach(n=>{let r=e.dataset[n];r!==void 0&&(t[n]=r)}),t.mode!==null&&![`edit`,`view`,`query`].includes(t.mode))throw Error(`invalid shacl-form mode: ${t.mode}`);if(this.mode=t.mode??(t.view===null?`edit`:`view`),this.theme.setDense(t.dense===`true`),this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){let e=this.languages.indexOf(t.language);e>-1&&this.languages.splice(e,1),this.languages.unshift(t.language)}if(t.valuesGraph&&(this.valuesGraphId=z.namedNode(t.valuesGraph)),t.hierarchyColors!=null){let e=t.hierarchyColors.length?t.hierarchyColors:ie,n=`:host { --hierarchy-colors: ${e}; --hierarchy-colors-length: ${e.split(`,`).length} }`;for(let e=8;e>=0;e--){let t=`shacl-property { --hierarchy-level: ${e} }`;for(let n=0;n<e;n++)t=`shacl-property `+t;n=n+`
|
|
8
|
+
`+t}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){let e=new Z;return Object.keys(e).map(e=>(e=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase()),`data-`+e))}buildTemplateKey(e,t){let n=e.value;return t&&(t instanceof P?n+=`*`+t.id.value:n+=`*`+this.buildTemplateKey(t.id,t.parent)),n}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){let e=new Set;for(let t of Object.values(this._nodeTemplates))e.add(t.id.value);return e}getNodeTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._nodeTemplates[n];return r||=new j(e,this,t),r}getPropertyTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._propertyTemplates[n];return r||=new P(e,t),r}get nodeTemplates(){return Object.values(this._nodeTemplates)}get theme(){return this._theme}set theme(e){this._theme=e,e.setDense(this.attributes.dense===`true`)}get store(){return this._store}get editMode(){return this.mode===`edit`}get queryMode(){return this.mode===`query`}set store(e){this._store=e,this.lists=o(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(e=>{this.groups.push(e.id)},_,`${s}PropertyGroup`,null),this.validator=new J(e,{details:!0,factory:z})}},ae=200,$=class extends HTMLElement{static get observedAttributes(){return Q.dataAttributes()}constructor(){super(),this.shape=null,this.styleElement=null,this.validationQueue=Promise.resolve(),this.validationGeneration=0,this.form=document.createElement(`form`),this.form.setAttribute(`part`,`form`),this.config=new Q(this.form),this.form.addEventListener(`change`,e=>{e.stopPropagation(),this.config.queryMode?this.queryController?.handleChange():this.config.editMode&&this.validate(!0).then(e=>{this.refreshClassInstanceEditors(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:e.conforms,report:e}}))}).catch(e=>{console.warn(e)})})}connectedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}attributeChangedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.queryController?.dispose(),this.queryController=void 0,this.setAttribute(`loading`,``),this.config.theme.apply(this.form),this.applyStyles([this.config.theme.stylesheet]),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await C({shapes:this.config.attributes.shapes,shapesUrl:this.config.attributes.shapesUrl,values:this.config.attributes.values,valuesUrl:this.config.attributes.valuesUrl,valuesSubject:this.config.attributes.valuesSubject,loadOwlImports:this.config.attributes.ignoreOwlImports===null,classInstanceProvider:this.config.classInstanceProvider,rdfUrlResolver:this.config.rdfUrlResolver,proxy:this.config.attributes.proxy},this.config.originalValues),this.config.resourceLinkProvider&&await x(this.config),this.config.attributes.valuesSubject||(this.config.attributes.valuesSubject=M(this.config.store)||null),this.form.replaceChildren();let e=this.findRootShaclShapeSubject();if(e){if(this.form.classList.forEach(e=>{this.form.classList.remove(e)}),this.form.classList.toggle(`mode-edit`,this.config.editMode),this.form.classList.toggle(`mode-view`,this.config.mode===`view`),this.form.classList.toggle(`mode-query`,this.config.queryMode),this.config.queryMode){let{QueryModeController:e}=await r(async()=>{let{QueryModeController:e}=await import(`./assets/mode-DH9hcPDl.js`);return{QueryModeController:e}},[]);this.queryController=new e(this)}this.config.theme.apply(this.form);let t=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&t.push(this.config.hierarchyColorsStyleSheet),this.queryController&&t.push(this.queryController.stylesheet);for(let e of T())e.stylesheet&&t.push(e.stylesheet);this.applyStyles(t);let n=new j(e,this.config);for(let e of this.config.nodeTemplates)E(e);if(this.shape=new k(n,this.config.attributes.valuesSubject?z.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&n.label){let e=document.createElement(`h3`);e.innerText=n.label.value,this.form.prepend(e)}if(this.config.editMode){if(this.config.attributes.submitButton!==null){let e=this.config.theme.createButton(this.config.attributes.submitButton||`Submit`,!0);e.classList.add(`submit-button`);let t=e.getAttribute(`part`);e.setAttribute(`part`,`${t?t+` `:``}submit-button`),e.addEventListener(`click`,e=>{e.preventDefault(),this.form.reportValidity()?this.validate().then(e=>{e?.conforms?this.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0})):this.focusFirstInvalidElement()}):this.validate().then(()=>{this.focusFirstInvalidElement(!0)})}),this.form.appendChild(e)}await this.shape?.ready,this.config.attributes.valuesSubject&&this.removeFromDataGraph(z.namedNode(this.config.attributes.valuesSubject)),await this.validate(!0),this.refreshClassInstanceEditors()}else this.config.queryMode&&(await this.shape.ready,await this.queryController?.initialize())}else if(this.config.store.countQuads(null,null,null,te)>0)throw Error(`shacl root node shape not found`)}catch(e){console.error(e);let t=document.createElement(`div`);t.innerText=String(e),this.form.replaceChildren(t)}this.config.queryMode&&this.config.queryFacetProvider&&this.queryController||this.removeAttribute(`loading`),await this.shape?.ready,this.dispatchEvent(new Event(`ready`,{bubbles:!0,composed:!0}))},200)}ensureRenderRoot(){this.config.attributes.useShadowRoot===`false`?(this.shadowRoot?.contains(this.form)&&this.shadowRoot.removeChild(this.form),this.contains(this.form)||this.prepend(this.form)):(this.shadowRoot||this.attachShadow({mode:`open`}),this.shadowRoot.contains(this.form)||this.shadowRoot.prepend(this.form))}focusFirstInvalidElement(e=!1){let t=this.form.querySelector(`:scope .invalid > .editor`);t?(e&&t.reportValidity?.(),t instanceof K?t.input.inputElement.focus():t.focus()):this.form.querySelector(`:scope .invalid`)?.scrollIntoView()}applyStyles(e){if(this.config.attributes.useShadowRoot!==`false`&&this.shadowRoot){this.shadowRoot.adoptedStyleSheets=e,this.styleElement&&=(this.styleElement.remove(),null);return}let t=e.map(e=>Array.from(e.cssRules).map(e=>e.cssText).join(`
|
|
9
9
|
`).replace(/:host\b/g,`shacl-form`)).join(`
|
|
10
|
-
`);this.styleElement||(this.styleElement=document.createElement(`style`),this.prepend(this.styleElement)),this.styleElement.textContent=t}serialize(e=`text/turtle`,t){return this.assertNotQueryMode(`serialize`),t??=this.toRDF(),
|
|
10
|
+
`);this.styleElement||(this.styleElement=document.createElement(`style`),this.prepend(this.styleElement)),this.styleElement.textContent=t}serialize(e=`text/turtle`,t){return this.assertNotQueryMode(`serialize`),t??=this.toRDF(),y(t.getQuads(null,null,null,null),e,u)}toRDF(e=new H){this.assertNotQueryMode(`toRDF`);let t;return this.config.attributes.preserveUnmappedValues!==null&&(t=this.preparePreservedOutput(e)),this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),t?.size&&this.pruneOrphanedBlankNodes(e,t),e}preparePreservedOutput(e){let t=this.config.originalValues,n=new Map;e.addQuads(t.getQuads(null,null,null,null));for(let r of this.form.querySelectorAll(`shacl-property`))if(!r.parent.linked){for(let i of r.template.pathAlternatives??[r.template.path])if(i)for(let a of t.getQuads(r.parent.nodeId,i,null,null))e.delete(a),a.object.termType===`BlankNode`&&n.set(a.object.id,a.object)}for(let n of this.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`))if(n.template.targetClass)for(let r of t.getQuads(n.nodeId,_,n.template.targetClass,null))e.delete(r);let r=this.config.attributes.generateNodeShapeReference;if(this.shape&&r)for(let n of t.getQuads(this.shape.nodeId,z.namedNode(r),this.shape.template.id,null))e.delete(n);return n}pruneOrphanedBlankNodes(e,t){let n=new Map(t),r=[...t.values()];for(;r.length;){let t=r.pop();for(let i of e.getQuads(t,null,null,null))i.object.termType===`BlankNode`&&!n.has(i.object.id)&&(n.set(i.object.id,i.object),r.push(i.object))}let i=new Set,a=[],o=e=>{i.has(e.id)||(i.add(e.id),a.push(e))};for(let e of this.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`))e.nodeId.termType===`BlankNode`&&n.has(e.nodeId.id)&&o(e.nodeId);for(let t of n.values())e.getQuads(null,null,t,null).some(e=>e.subject.termType!==`BlankNode`||!n.has(e.subject.id))&&o(t);for(;a.length;){let t=a.pop();for(let r of e.getQuads(t,null,null,null))r.object.termType===`BlankNode`&&n.has(r.object.id)&&o(r.object)}for(let t of n.values())if(!i.has(t.id))for(let n of e.getQuads(t,null,null,null))e.delete(n)}registerPlugin(e){w(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}setRdfUrlResolver(e){this.config.rdfUrlResolver=e,this.initialize()}setResourceLinkProvider(e){this.config.resourceLinkProvider=e,this.initialize()}setQueryFacetProvider(e){this.config.queryFacetProvider=e,this.queryController?.refreshFacets()}getQuery(){return this.shape?this.queryController?.getQuery()??{rootShapeId:this.shape.template.id.value,targetClass:this.shape.template.targetClass?.value,criteria:[]}:{rootShapeId:``,criteria:[]}}refreshQueryFacets(){this.queryController?.refreshFacets()}async validate(e=!1){this.assertNotQueryMode(`validate`);let t=++this.validationGeneration;for(let e of this.form.querySelectorAll(`:scope .validation-error`))e.remove();for(let t of this.form.querySelectorAll(`:scope .property-instance`)){let n=t.querySelector(`:scope > .editor`),r=!!n?.value,i=n?.validity?.valid===!1&&(r||!e);t.classList.toggle(`invalid`,i),r&&!i?t.classList.add(`valid`):t.classList.remove(`valid`),i&&n?.validationMessage&&this.appendValidationErrorDisplay(t,n.validationMessage)}for(let e of this.form.querySelectorAll(`.add-button-wrapper`))e.classList.remove(`invalid`,`validation-error`);if(!this.shape)return{conforms:!0,results:[]};if(!e){let e=this.form.querySelectorAll(`.add-button-wrapper.required`);for(let t of e)t.classList.add(`invalid`),t.after(this.createValidationErrorDisplay(`Value is required`,`node`));if(e.length>0)return{conforms:!1,results:[]}}let n=this.shape,r=()=>new Promise(r=>{this.config.store.deleteGraph(this.config.valuesGraphId||``).on(`end`,async()=>{n.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{let i=await this.config.validator.validate({dataset:this.config.store,terms:[n.nodeId]},[{terms:[n.template.id]}]);if(t!==this.validationGeneration){r(i);return}let a=[...i.results];for(let t=0;t<a.length;t++){let n=a[t];if(a.push(...n.results??[]),n.focusNode?.ptrs?.length)for(let t of n.focusNode.ptrs){let r=t._term;if(n.path?.length){let t=n.path[0].predicates[0],i=e=>`
|
|
11
11
|
:scope shacl-node[data-node-id='${r.id}'] > shacl-property > .property-instance[${e}='${t.id}'] > .editor,
|
|
12
12
|
:scope shacl-node[data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[${e}='${t.id}'] > .editor,
|
|
13
13
|
:scope shacl-node[data-node-id='${r.id}'] > .shacl-group > shacl-property > .property-instance[${e}='${t.id}'] > .editor,
|
|
@@ -18,4 +18,4 @@ import{$ as e,A as t,B as n,C as r,E as i,F as a,G as o,H as s,I as c,J as l,M a
|
|
|
18
18
|
:scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .alternative-path-constraint[data-path='${t.id}']`)),a.length===0&&(a=this.form.querySelectorAll(`
|
|
19
19
|
:scope [data-node-id='${r.id}'] > shacl-property > .property-instance[data-predicate='${t.id}'],
|
|
20
20
|
:scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[data-predicate='${t.id}']`));for(let t of a)if(t.classList.contains(`editor`)){if(!e||t.value){let e=t.parentElement;e.classList.add(`invalid`),e.classList.remove(`valid`),this.appendValidationErrorDisplay(e,n);do e instanceof W&&(e.open=!0),e=e.parentElement;while(e)}}else e||(t.classList.add(`invalid`),t.classList.remove(`valid`),t.appendChild(this.createValidationErrorDisplay(n,`node`)))}else e||this.form.querySelector(`:scope [data-node-id='${r.id}']:not([part~='linked-node'])`)?.prepend(this.createValidationErrorDisplay(n,`node`))}}r(i)}catch(e){console.error(e),r({conforms:!1,results:[]})}})}),i=this.validationQueue.then(r,r);return this.validationQueue=i.then(()=>void 0,()=>void 0),i}assertNotQueryMode(e){if(this.config.queryMode)throw Error(`${e}() is not available in query mode; use getQuery()`)}refreshClassInstanceEditors(){if(!(!this.shape||!this.config.editMode))for(let e of this.form.querySelectorAll(`shacl-property`))e.refreshClassInstances()}appendValidationErrorDisplay(e,t,n){let r=this.createValidationErrorDisplay(t,n),i=e.querySelector(`:scope > .validation-error`);if(!i){e.appendChild(r);return}if(r.title&&this.hasExplicitShaclMessage(t)){i.title=r.title;return}r.title&&!i.title.split(`
|
|
21
|
-
`).includes(r.title)&&(i.title=i.title?`${i.title}\n${r.title}`:r.title)}hasExplicitShaclMessage(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.shape?.message?.length?!0:[...t.shape?.ptr?.terms??[],...t.source??[]].some(e=>this.config.store.countQuads(e,
|
|
21
|
+
`).includes(r.title)&&(i.title=i.title?`${i.title}\n${r.title}`:r.title)}hasExplicitShaclMessage(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.shape?.message?.length?!0:[...t.shape?.ptr?.terms??[],...t.source??[]].some(e=>this.config.store.countQuads(e,ee,null,null)>0)}createValidationErrorDisplay(e,t){let n=document.createElement(`span`);n.classList.add(`validation-error`),t&&n.classList.add(t);let r=typeof e==`object`&&e?e:null;return r?r.message?.length?n.title+=c(this.config.languages,r.message):r.sourceConstraintComponent?.value&&(n.title=r.sourceConstraintComponent.value):typeof e==`string`&&(n.title=e),n}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){let e=z.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,_,v,null).length===0){console.warn(`shapes graph does not contain requested node shape ${this.config.attributes.shapeSubject}`);return}else return e}else{if(this.config.attributes.valuesSubject&&this.config.store.countQuads(null,null,null,a)>0){let t=z.namedNode(this.config.attributes.valuesSubject),n=O(this.config.store,this.config.attributes.valuesSubject),r=this.config.store.getQuads(t,_,null,a);if(r.length===0&&console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${_.id} nor ${p.id} statement`),n)return n;for(let e of r)if(this.config.store.getQuads(e.object,_,v,null).length>0)return e.object;let i=this.config.store.getObjects(t,_,a);for(let t of i)for(let n of this.config.store.getQuads(null,e,t,null))return n.subject}let t=this.config.store.getQuads(null,_,v,null);if(t.length==0){console.warn(`shapes graph does not contain any node shapes`);return}return t.length>1&&(console.warn(`shapes graph contains`,t.length,`node shapes. choosing first found which is`,t[0].subject.value),console.info(`hint: set the node shape to use with element attribute "data-shape-subject"`)),t[0].subject}}removeFromDataGraph(e){for(let t of this.config.store.getQuads(e,null,null,a))this.config.store.delete(t),(t.object.termType===`NamedNode`||t.object.termType===`BlankNode`)&&this.removeFromDataGraph(t.object)}};window.customElements.define(`shacl-form`,$);export{Q as Config,X as DefaultTheme,A as Plugin,$ as ShaclForm,P as ShaclPropertyTemplate,F as Theme,t as fetchRDF,O as findConformsToShapeSubject,M as findConformsToValuesSubject,L as findLabel,S as importRDF,ae as initTimeout,ne as isRangeQueryField,C as loadGraphs,D as loadRDF,l as parseRDF,u as prefixes,i as propertyMappers,d as rdfCache,w as registerPlugin};
|
package/dist/property.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare class ShaclProperty extends HTMLElement {
|
|
|
26
26
|
private rdfListToRDF;
|
|
27
27
|
private removePreservedRdfList;
|
|
28
28
|
}
|
|
29
|
+
export declare function detectRdfListItemTemplate(template: ShaclPropertyTemplate): ShaclPropertyTemplate | undefined;
|
|
29
30
|
export declare function createPropertyInstance(template: ShaclPropertyTemplate, value?: Term, forceRemovable?: boolean, linked?: boolean, parentNode?: ShaclNode): Promise<HTMLElement>;
|
|
30
31
|
export declare function appendRemoveButton(instance: HTMLElement, label: string, dense: boolean, colorize: boolean, forceRemovable?: boolean): void;
|
|
31
32
|
export declare function createRemoveButtonWrapper(colorize: boolean): HTMLDivElement;
|
package/package.json
CHANGED
|
@@ -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-byEWeJbo.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(n.unavailable=!!(i&&i[0]===i[1]),n.unavailable)return;if(!i){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value));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});let r=!1;if(n.size===0&&o.initialValue){let e=F(o.initialValue);s.some(t=>F(t.term)===e)&&(n.set(e,o.initialValue),r=!0)}return f([...n.keys()]),r}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=``;return!1},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&&r!==void 0,s=o?n:n===void 0?i:i===void 0?n:Math.max(n,i),c=o?r:r===void 0?a:a===void 0?r:Math.min(r,a);return s!==void 0&&c!==void 0&&Number.isFinite(s)&&Number.isFinite(c)&&s<=c?[s,c]: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;let o=this.applyFacets(a,!this.facetsApplied);this.facetsApplied=!0,this.setFacetsPending(!1),o&&(await new Promise(e=>setTimeout(e,0)),await this.emitQueryAndRefreshFacets())}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e,t){let n=new Map(e.map(e=>[e.fieldId,e])),r=!1;for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let i=n.get(e.queryField.id);i?.initialValue&&!t&&(i={...i,initialValue:void 0});let a=e.setQueryFacet(i)===!0;r||=a;let o=a||e.getQueryCriteria().length>0,s=e.closest(`shacl-property`);s?.classList.toggle(`query-unavailable`,e.unavailable||i?.unavailable===!0||i?.count===0&&!o),s?.classList.toggle(`query-facet-error`,i?.error===!0)}let i=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of i){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 a=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));return this.host.classList.toggle(`query-facets-empty`,!a),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.unavailable&&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)],fixedValue:e.hasValue,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};
|
|
@@ -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-DbfDRxlr.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(n.unavailable=!!(i&&i[0]===i[1]),n.unavailable)return;if(!i){a.append(h(`Minimum`,e?.min?.value),h(`Maximum`,e?.max?.value));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});let r=!1;if(n.size===0&&o.initialValue){let e=F(o.initialValue);s.some(t=>F(t.term)===e)&&(n.set(e,o.initialValue),r=!0)}return f([...n.keys()]),r}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=``;return!1},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&&r!==void 0,s=o?n:n===void 0?i:i===void 0?n:Math.max(n,i),c=o?r:r===void 0?a:a===void 0?r:Math.min(r,a);return s!==void 0&&c!==void 0&&Number.isFinite(s)&&Number.isFinite(c)&&s<=c?[s,c]: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;let o=this.applyFacets(a,!this.facetsApplied);this.facetsApplied=!0,this.setFacetsPending(!1),o&&(await new Promise(e=>setTimeout(e,0)),await this.emitQueryAndRefreshFacets())}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e,t){let n=new Map(e.map(e=>[e.fieldId,e])),r=!1;for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let i=n.get(e.queryField.id);i?.initialValue&&!t&&(i={...i,initialValue:void 0});let a=e.setQueryFacet(i)===!0;r||=a;let o=a||e.getQueryCriteria().length>0,s=e.closest(`shacl-property`);s?.classList.toggle(`query-unavailable`,e.unavailable||i?.unavailable===!0||i?.count===0&&!o),s?.classList.toggle(`query-facet-error`,i?.error===!0)}let i=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of i){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 a=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));return this.host.classList.toggle(`query-facets-empty`,!a),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.unavailable&&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)],fixedValue:e.hasValue,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};
|