@ulb-darmstadt/shacl-form 2.0.0 → 2.0.1

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/config.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare class ElementAttributes {
27
27
  submitButton: string | null;
28
28
  generateNodeShapeReference: string;
29
29
  showNodeIds: string | null;
30
+ showRootShapeLabel: string | null;
30
31
  dense: string;
31
32
  }
32
33
  export declare class Config {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{DataFactory as u,Store as J,Quad as pe,StreamParser as Le,Literal as S,NamedNode as R,Writer as Te}from"n3";import{RdfXmlParser as Ie}from"rdfxml-streaming-parser";import je from"jsonld";import{RokitCollapsible as Y,RokitSelect as ge,RokitButton as Pe,RokitInput as B,RokitTextArea as Re}from"@ro-kit/ui-widgets";import{v4 as ae}from"uuid";import{Validator as re}from"shacl-engine";const d="http://www.w3.org/ns/shacl#",le="http://datashapes.org/dash#",E="http://www.w3.org/2001/XMLSchema#",x="http://www.w3.org/1999/02/22-rdf-syntax-ns#",Z="http://www.w3.org/2000/01/rdf-schema#",ee="http://www.w3.org/2004/02/skos/core#",De="http://www.w3.org/2002/07/owl#",$e="http://www.w3.org/ns/oa#",Ne="http://purl.org/dc/terms/",Ae="http://xmlns.com/foaf/0.1/",T=u.namedNode("loaded-shapes"),b=u.namedNode("loaded-data"),g=u.namedNode(x+"type"),me=u.namedNode(x+"langString"),k=u.namedNode(Ne+"conformsTo"),ce=u.namedNode(Z+"subClassOf"),te=u.namedNode(De+"imports"),Oe=u.namedNode(ee+"broader"),_e=u.namedNode(ee+"narrower"),z=u.namedNode(d+"NodeShape"),be=u.namedNode(d+"IRI"),H=u.namedNode(d+"property"),se=u.namedNode(d+"class");u.namedNode(d+"node");const Q=u.namedNode(d+"targetClass"),qe=u.namedNode(d+"nodeKind"),ke=u.namedNode(E+"string");function D(s,e,t=d,i){let n="";const o=Fe(s,e,t,i);return o&&(n=o.value),n}function Fe(s,e,t=d,i){let n;const o=t+e;if(i?.length){for(const a of i)for(const r of s)if(r.predicate.value===o){if(r.object.id.endsWith(`@${a}`))return r.object;r.object.id.indexOf("@")<0?n=r.object:n||(n=r.object)}}else for(const a of s)if(a.predicate.value===o)return a.object;return n}function Ve(s){s.querySelector(".editor")?.focus()}function P(s,e){return D(s,"prefLabel",ee,e)||D(s,"label",Z,e)||D(s,"name",Ae,e)}function ve(s,e,t){const i=[];for(const n of s)i.push({value:n,label:P(e.getQuads(n,null,null,null),t),children:[]});return i}function K(s,e){for(const t in e)s=s.replace(e[t],"");return s}function ye(s,e,t,i,n=new Set){for(const o of e.owlImports)n.has(o.id)||(n.add(o.id),i.push(...t.getSubjects(g,s,o)));e.parent&&ye(s,e.parent,t,i,n)}function ne(s,e){if(e.in){const t=e.config.lists[e.in];return ve(t?.length?t:[],e.config.store,e.config.languages)}else{const t=e.config.store.getSubjects(g,s,T);t.push(...e.config.store.getSubjects(g,s,b)),ye(s,e,e.config.store,t);const i=new Map,n=new Map;for(const a of t)i.set(a.id,{value:a,label:P(e.config.store.getQuads(a,null,null,null),e.config.languages),children:[]});for(const a of t){for(const r of e.config.store.getObjects(a,Oe,null))i.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,_e,null))i.has(r.id)&&n.set(r.id,a.id);for(const r of e.config.store.getObjects(a,ce,null))i.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())i.get(r)?.children?.push(i.get(a));const o=[];for(const[a,r]of i.entries())n.has(a)||o.push(r);for(const a of e.config.store.getSubjects(ce,s,null))o.push(...ne(a,e));return o}}function W(s){let e;try{e=new URL(s)}catch{return!1}return e.protocol==="http:"||e.protocol==="https:"}function de(s,e,t){if(e===void 0)return t;if(t===void 0)return e;const i=s.indexOf(e.language);if(i<0)return t;const n=s.indexOf(t.language);return n<0||n>i?e:t}function Me(s,{remove:e=!1,ignoreErrors:t=!1}={}){const i={},n=t?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),o=s.getQuads(null,x+"rest",x+"nil",null),a=e?[...o]:[];return o.forEach(r=>{const l=[];let c=!1,f,h;const v=r.graph;let p=r.subject;for(;p&&!c;){const w=s.getQuads(null,null,p,null),C=s.getQuads(p,null,null,null).filter(y=>!y.predicate.equals(g));let m,N=null,oe=null,A=null;for(let y=0;y<C.length&&!c;y++)m=C[y],m.graph.equals(v)?f?c=n(p,"has non-list arcs out"):m.predicate.value===x+"first"?N?c=n(p,"has multiple rdf:first arcs"):a.push(N=m):m.predicate.value===x+"rest"?oe?c=n(p,"has multiple rdf:rest arcs"):a.push(oe=m):w.length?c=n(p,"can't be subject and object"):(f=m,h="subject"):c=n(p,"not confined to single graph");for(let y=0;y<w.length&&!c;++y)m=w[y],f?c=n(p,"can't have coreferences"):m.predicate.value===x+"rest"?A?c=n(p,"has incoming rdf:rest arcs"):A=m:(f=m,h="object");N?l.unshift(N.object):c=n(p,"has no list head"),p=A&&A.subject}c?e=!1:f&&(i[f[h].value]=l)}),e&&s.removeQuads(a),i}const O={},G={},j={};async function Qe(s){const e={store:new J,importedUrls:[],importedClasses:[],atts:s},t=[];if(s.shapes?t.push(L(F(s.shapes,T),e)):s.shapesUrl&&t.push(L(_(s.shapesUrl,e,T),e)),s.values?t.push(L(F(s.values,b),e)):s.valuesUrl&&t.push(L(_(s.valuesUrl,e,b),e)),await Promise.all(t),e.store.countQuads(null,null,null,T)===0&&s.valuesSubject){const i=[...e.store.getObjects(s.valuesSubject,k,b)],n=[];for(const o of i){const a=we(o.value);a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(L(_(a,e,T),e)))}try{await Promise.allSettled(n)}catch(o){console.warn(o)}}return e.store}async function L(s,e){const t=await s,i=[];for(const n of t){if(e.store.add(new pe(n.subject,n.predicate,n.object,n.graph)),te.equals(n.predicate)&&e.atts.loadOwlImports){const o=we(n.object.value);o&&e.importedUrls.indexOf(o)<0&&(e.importedUrls.push(o),i.push(L(_(o,e),e)))}if(e.atts.classInstanceProvider&&(se.equals(n.predicate)||Q.equals(n.predicate))){const o=n.object.value;if(e.importedClasses.indexOf(o)<0){let a;o in G?a=G[o]:(a=e.atts.classInstanceProvider(o),G[o]=a),e.importedClasses.push(o),i.push(L(F(await a,T),e))}}}await Promise.allSettled(i)}async function _(s,e,t){return s in O||(O[s]=new Promise(async(i,n)=>{try{let o=s;e.atts.proxy&&(o=e.atts.proxy+encodeURIComponent(s));const a=await fetch(o,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(r=>r.text());i(await F(a,t||u.namedNode(s)))}catch(o){n(o)}})),O[s]}async function F(s,e){if(ue(s)==="json")try{s=await je.toRDF(JSON.parse(s),{format:"application/n-quads"})}catch(i){console.error(i)}const t=[];return await new Promise((i,n)=>{const o=ue(s)==="xml"?new Ie:new Le;o.on("data",a=>{t.push(new pe(a.subject,a.predicate,a.object,e))}).on("error",a=>{n(a)}).on("prefix",(a,r)=>{a&&(j[a]=r)}).on("end",()=>{i(null)}),o.write(s),o.end()}),t}function we(s){if(W(s))return s;const e=s.split(":");if(e.length===2){const t=j[e[0]];if(t&&(s=s.replace(`${e[0]}:`,t),W(s)))return s}return null}function ue(s){return/^\s*\{/.test(s)?"json":/^\s*<\?xml/.test(s)?"xml":"ttl"}const Be={[`${d}name`]:(s,e)=>{const t=e;s.name=de(s.config.languages,s.name,t)},[`${d}description`]:(s,e)=>{const t=e;s.description=de(s.config.languages,s.description,t)},[`${d}path`]:(s,e)=>{s.path=e.value},[`${d}group`]:(s,e)=>{s.group=e.id},[`${d}datatype`]:(s,e)=>{s.datatype=e},[`${d}nodeKind`]:(s,e)=>{s.nodeKind=e},[`${d}minCount`]:(s,e)=>{s.minCount=parseInt(e.value)},[`${d}maxCount`]:(s,e)=>{s.maxCount=parseInt(e.value)},[`${d}minLength`]:(s,e)=>{s.minLength=parseInt(e.value)},[`${d}maxLength`]:(s,e)=>{s.maxLength=parseInt(e.value)},[`${d}minInclusive`]:(s,e)=>{s.minInclusive=parseInt(e.value)},[`${d}maxInclusive`]:(s,e)=>{s.maxInclusive=parseInt(e.value)},[`${d}minExclusive`]:(s,e)=>{s.minExclusive=parseInt(e.value)},[`${d}maxExclusive`]:(s,e)=>{s.maxExclusive=parseInt(e.value)},[`${d}pattern`]:(s,e)=>{s.pattern=e.value},[`${d}order`]:(s,e)=>{s.order=parseInt(e.value)},[`${le}singleLine`]:(s,e)=>{s.singleLine=e.value==="true"},[`${le}readonly`]:(s,e)=>{s.readonly=e.value==="true"},[`${$e}styleClass`]:(s,e)=>{s.cssClass=e.value},[`${d}in`]:(s,e)=>{s.in=e.value},[`${d}languageIn`]:(s,e)=>{s.languageIn=s.config.lists[e.value],s.datatype=me},[`${d}defaultValue`]:(s,e)=>{s.defaultValue=e},[`${d}hasValue`]:(s,e)=>{s.hasValue=e},[`${d}node`]:(s,e)=>{s.node=e,s.nodeShapes.add(s.config.getNodeTemplate(e,s))},[`${d}and`]:(s,e)=>{s.and=e.value;const t=s.config.lists[s.and];if(t?.length)for(const i of t)s.nodeShapes.add(s.config.getNodeTemplate(i,s))},[`${d}qualifiedValueShape`]:(s,e)=>{const t=s.config.getNodeTemplate(e,s);s.qualifiedValueShape=t,s.nodeShapes.add(t)},[`${d}qualifiedMinCount`]:(s,e)=>{s.qualifiedMinCount=parseInt(e.value)},[`${d}qualifiedMaxCount`]:(s,e)=>{s.qualifiedMaxCount=parseInt(e.value)},[te.id]:(s,e)=>{s.owlImports.add(e)},[se.id]:(s,e)=>{s.class=e;const t=s.config.store.getSubjects(Q,e,null);t.length>0&&(s.node=t[0])},[`${d}or`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.or=t:console.error("list for sh:or not found:",e.value,"existing lists:",s.config.lists)},[`${d}xone`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.xone=t:console.error("list for sh:xone not found:",e.value,"existing lists:",s.config.lists)}};class he{constructor(e,t){this.label="",this.nodeShapes=new Set,this.owlImports=new Set,this.id=e,this.parent=t,this.config=t.config,this.config.registerPropertyTemplate(this),ie(this,this.config.store.getQuads(e,null,null,null)),this.aggregatedMinCount=Math.max(this.minCount||0,this.qualifiedMinCount||0),this.aggregatedMaxCount=Math.min(this.maxCount||0,this.qualifiedMaxCount||0)}}function Se(s){const e=Object.assign({},s);return e.nodeShapes=new Set(s.nodeShapes),e.owlImports=new Set(s.owlImports),s.languageIn&&(e.languageIn=[...s.languageIn]),s.or&&(e.or=[...s.or]),s.xone&&(e.xone=[...s.xone]),e}function ie(s,e){for(const t of e)Be[t.predicate.id]?.call(s,s,t.object);return s.label=s.name?.value||P(e,s.config.languages),s.label||(s.label=s.path?K(s.path,j):"unknown"),s}function Ee(s,e){const t=e,i=s;for(const n in e)n!=="parent"&&n!=="config"&&n!=="id"&&t[n]!==void 0&&t[n]!==""&&(Array.isArray(t[n])?i[n].push(...t[n]):t[n]instanceof Set&&t[n].size?i[n]=new Set([...i[n],...t[n]]):i[n]=t[n])}function Ce(s,e,t){const i=document.createElement("div");i.classList.add("shacl-or-constraint");const n=[];if(e instanceof I){const o=[];let a=!1;s.length&&(a=t.store.countQuads(s[0],H,null,null)>0);for(let c=0;c<s.length;c++)if(a){const f=t.store.getObjects(s[c],H,null),h=[];let v="";for(const p of f){const w=t.getPropertyTemplate(p,e.template),C=new V(w,e);h.push(C),v+=(v.length>1?" / ":"")+C.template.label}o.push(h),n.push({label:v,value:c.toString()})}else{const f=s[c],h=t.getPropertyTemplate(f,e.template),v=new V(h,e);o.push([v]),n.push({label:v.template.label,value:c.toString()})}const r=t.theme.createListEditor("Please choose",null,!1,n),l=r.querySelector(".editor");l.onchange=()=>{if(l.value){const c=o[parseInt(l.value)];let f;c.length&&(f=c[0],i.replaceWith(c[0]));for(let h=1;h<c.length;h++)f.after(c[h]),f=c[h]}},i.appendChild(r)}else{const o=[];for(let l=0;l<s.length;l++){const c=t.store.getQuads(s[l],null,null,null);c.length&&(o.push(c),n.push({label:P(c,t.languages)||K(c[0].predicate.value,j)+" = "+K(c[0].object.value,j),value:l.toString()}))}const a=t.theme.createListEditor(e.template.label+"?",null,!1,n,e.template),r=a.querySelector(".editor");r.onchange=()=>{if(r.value){const l=ie(Se(e.template),o[parseInt(r.value)]);i.replaceWith(q(l,void 0,!0))}},i.appendChild(a)}return i}function ze(s,e,t){if(e instanceof S){const i=e.datatype;for(const n of s){const o=t.store.getQuads(n,null,null,null);for(const a of o)if(a.predicate.value===`${d}datatype`&&a.object.equals(i))return o}}else{const i=t.store.getObjects(e,g,null);for(const n of s){const o=t.store.getQuads(n,null,null,null);for(const a of o)if(i.length>0){if(a.predicate.value===`${d}node`){for(const r of i)if(t.store.getQuads(a.object,Q,r,null).length>0)return o}if(a.predicate.equals(se)){for(const r of i)if(a.object.equals(r))return o}}else if(a.predicate.equals(qe)&&a.object.equals(be))return o}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Ge(s,e,t){for(const i of s){let n=!1;const o=t.store.getObjects(i,H,null);for(const a of o){const r=t.store.getObjects(a,`${d}path`,null);for(const l of r)if(n=t.store.countQuads(e,l,null,null)>0,n)break}if(n)return o}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const Ue=`form { display:block; --label-width: 8em; --caret-size: 10px; }
1
+ import{DataFactory as u,Store as Z,Quad as pe,StreamParser as Te,Literal as S,NamedNode as $,Writer as Ie}from"n3";import{RdfXmlParser as je}from"rdfxml-streaming-parser";import Re from"jsonld";import{RokitCollapsible as ee,RokitSelect as ge,RokitButton as $e,RokitInput as G,RokitTextArea as Pe}from"@ro-kit/ui-widgets";import{v4 as re}from"uuid";import{Validator as le}from"shacl-engine";const d="http://www.w3.org/ns/shacl#",ce="http://datashapes.org/dash#",E="http://www.w3.org/2001/XMLSchema#",x="http://www.w3.org/1999/02/22-rdf-syntax-ns#",B="http://www.w3.org/2000/01/rdf-schema#",te="http://www.w3.org/2004/02/skos/core#",De="http://www.w3.org/2002/07/owl#",Ne="http://www.w3.org/ns/oa#",me="http://purl.org/dc/terms/",Ae="http://xmlns.com/foaf/0.1/",T=u.namedNode("loaded-shapes"),b=u.namedNode("loaded-data"),g=u.namedNode(x+"type"),be=u.namedNode(x+"langString"),k=u.namedNode(me+"conformsTo"),de=u.namedNode(B+"subClassOf"),se=u.namedNode(De+"imports"),Oe=u.namedNode(te+"broader"),_e=u.namedNode(te+"narrower"),U=u.namedNode(d+"NodeShape"),ve=u.namedNode(d+"IRI"),W=u.namedNode(d+"property"),ne=u.namedNode(d+"class");u.namedNode(d+"node");const z=u.namedNode(d+"targetClass"),qe=u.namedNode(d+"nodeKind"),ke=u.namedNode(E+"string");function P(t,e,s=d,i){let n="";const o=Fe(t,e,s,i);return o&&(n=o.value),n}function Fe(t,e,s=d,i){let n;const o=s+e;if(i?.length){for(const a of i)for(const r of t)if(r.predicate.value===o){if(r.object.id.endsWith(`@${a}`))return r.object;r.object.id.indexOf("@")<0?n=r.object:n||(n=r.object)}}else for(const a of t)if(a.predicate.value===o)return a.object;return n}function Ve(t){t.querySelector(".editor")?.focus()}function R(t,e){return P(t,"prefLabel",te,e)||P(t,"label",B,e)||P(t,"name",Ae,e)}function ye(t,e,s){const i=[];for(const n of t)i.push({value:n,label:R(e.getQuads(n,null,null,null),s),children:[]});return i}function X(t,e){for(const s in e)t=t.replace(e[s],"");return t}function we(t,e,s,i,n=new Set){for(const o of e.owlImports)n.has(o.id)||(n.add(o.id),i.push(...s.getSubjects(g,t,o)));e.parent&&we(t,e.parent,s,i,n)}function ie(t,e){if(e.in){const s=e.config.lists[e.in];return ye(s?.length?s:[],e.config.store,e.config.languages)}else{const s=e.config.store.getSubjects(g,t,T);s.push(...e.config.store.getSubjects(g,t,b)),we(t,e,e.config.store,s);const i=new Map,n=new Map;for(const a of s)i.set(a.id,{value:a,label:R(e.config.store.getQuads(a,null,null,null),e.config.languages),children:[]});for(const a of s){for(const r of e.config.store.getObjects(a,Oe,null))i.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,_e,null))i.has(r.id)&&n.set(r.id,a.id);for(const r of e.config.store.getObjects(a,de,null))i.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())i.get(r)?.children?.push(i.get(a));const o=[];for(const[a,r]of i.entries())n.has(a)||o.push(r);for(const a of e.config.store.getSubjects(de,t,null))o.push(...ie(a,e));return o}}function J(t){let e;try{e=new URL(t)}catch{return!1}return e.protocol==="http:"||e.protocol==="https:"}function F(t,e,s){if(e===void 0)return s;if(s===void 0)return e;const i=t.indexOf(e.language);if(i<0)return s;const n=t.indexOf(s.language);return n<0||n>i?e:s}function Me(t,{remove:e=!1,ignoreErrors:s=!1}={}){const i={},n=s?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),o=t.getQuads(null,x+"rest",x+"nil",null),a=e?[...o]:[];return o.forEach(r=>{const l=[];let c=!1,f,h;const v=r.graph;let p=r.subject;for(;p&&!c;){const w=t.getQuads(null,null,p,null),C=t.getQuads(p,null,null,null).filter(y=>!y.predicate.equals(g));let m,N=null,ae=null,A=null;for(let y=0;y<C.length&&!c;y++)m=C[y],m.graph.equals(v)?f?c=n(p,"has non-list arcs out"):m.predicate.value===x+"first"?N?c=n(p,"has multiple rdf:first arcs"):a.push(N=m):m.predicate.value===x+"rest"?ae?c=n(p,"has multiple rdf:rest arcs"):a.push(ae=m):w.length?c=n(p,"can't be subject and object"):(f=m,h="subject"):c=n(p,"not confined to single graph");for(let y=0;y<w.length&&!c;++y)m=w[y],f?c=n(p,"can't have coreferences"):m.predicate.value===x+"rest"?A?c=n(p,"has incoming rdf:rest arcs"):A=m:(f=m,h="object");N?l.unshift(N.object):c=n(p,"has no list head"),p=A&&A.subject}c?e=!1:f&&(i[f[h].value]=l)}),e&&t.removeQuads(a),i}const O={},H={},j={};async function Qe(t){const e={store:new Z,importedUrls:[],importedClasses:[],atts:t},s=[];if(t.shapes?s.push(L(V(t.shapes,T),e)):t.shapesUrl&&s.push(L(_(t.shapesUrl,e,T),e)),t.values?s.push(L(V(t.values,b),e)):t.valuesUrl&&s.push(L(_(t.valuesUrl,e,b),e)),await Promise.all(s),e.store.countQuads(null,null,null,T)===0&&t.valuesSubject){const i=[...e.store.getObjects(t.valuesSubject,k,b)],n=[];for(const o of i){const a=Se(o.value);a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(L(_(a,e,T),e)))}try{await Promise.allSettled(n)}catch(o){console.warn(o)}}return e.store}async function L(t,e){const s=await t,i=[];for(const n of s){if(e.store.add(new pe(n.subject,n.predicate,n.object,n.graph)),se.equals(n.predicate)&&e.atts.loadOwlImports){const o=Se(n.object.value);o&&e.importedUrls.indexOf(o)<0&&(e.importedUrls.push(o),i.push(L(_(o,e),e)))}if(e.atts.classInstanceProvider&&(ne.equals(n.predicate)||z.equals(n.predicate))){const o=n.object.value;if(e.importedClasses.indexOf(o)<0){let a;o in H?a=H[o]:(a=e.atts.classInstanceProvider(o),H[o]=a),e.importedClasses.push(o),i.push(L(V(await a,T),e))}}}await Promise.allSettled(i)}async function _(t,e,s){return t in O||(O[t]=new Promise(async(i,n)=>{try{let o=t;e.atts.proxy&&(o=e.atts.proxy+encodeURIComponent(t));const a=await fetch(o,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(r=>r.text());i(await V(a,s||u.namedNode(t)))}catch(o){n(o)}})),O[t]}async function V(t,e){if(ue(t)==="json")try{t=await Re.toRDF(JSON.parse(t),{format:"application/n-quads"})}catch(i){console.error(i)}const s=[];return await new Promise((i,n)=>{const o=ue(t)==="xml"?new je:new Te;o.on("data",a=>{s.push(new pe(a.subject,a.predicate,a.object,e))}).on("error",a=>{n(a)}).on("prefix",(a,r)=>{a&&(j[a]=r)}).on("end",()=>{i(null)}),o.write(t),o.end()}),s}function Se(t){if(J(t))return t;const e=t.split(":");if(e.length===2){const s=j[e[0]];if(s&&(t=t.replace(`${e[0]}:`,s),J(t)))return t}return null}function ue(t){return/^\s*\{/.test(t)?"json":/^\s*<\?xml/.test(t)?"xml":"ttl"}const Be={[`${d}name`]:(t,e)=>{const s=e;t.name=F(t.config.languages,t.name,s)},[`${d}description`]:(t,e)=>{const s=e;t.description=F(t.config.languages,t.description,s)},[`${d}path`]:(t,e)=>{t.path=e.value},[`${d}group`]:(t,e)=>{t.group=e.id},[`${d}datatype`]:(t,e)=>{t.datatype=e},[`${d}nodeKind`]:(t,e)=>{t.nodeKind=e},[`${d}minCount`]:(t,e)=>{t.minCount=parseInt(e.value)},[`${d}maxCount`]:(t,e)=>{t.maxCount=parseInt(e.value)},[`${d}minLength`]:(t,e)=>{t.minLength=parseInt(e.value)},[`${d}maxLength`]:(t,e)=>{t.maxLength=parseInt(e.value)},[`${d}minInclusive`]:(t,e)=>{t.minInclusive=parseInt(e.value)},[`${d}maxInclusive`]:(t,e)=>{t.maxInclusive=parseInt(e.value)},[`${d}minExclusive`]:(t,e)=>{t.minExclusive=parseInt(e.value)},[`${d}maxExclusive`]:(t,e)=>{t.maxExclusive=parseInt(e.value)},[`${d}pattern`]:(t,e)=>{t.pattern=e.value},[`${d}order`]:(t,e)=>{t.order=parseInt(e.value)},[`${ce}singleLine`]:(t,e)=>{t.singleLine=e.value==="true"},[`${ce}readonly`]:(t,e)=>{t.readonly=e.value==="true"},[`${Ne}styleClass`]:(t,e)=>{t.cssClass=e.value},[`${d}in`]:(t,e)=>{t.in=e.value},[`${d}languageIn`]:(t,e)=>{t.languageIn=t.config.lists[e.value],t.datatype=be},[`${d}defaultValue`]:(t,e)=>{t.defaultValue=e},[`${d}hasValue`]:(t,e)=>{t.hasValue=e},[`${d}node`]:(t,e)=>{t.node=e,t.nodeShapes.add(t.config.getNodeTemplate(e,t))},[`${d}and`]:(t,e)=>{t.and=e.value;const s=t.config.lists[t.and];if(s?.length)for(const i of s)t.nodeShapes.add(t.config.getNodeTemplate(i,t))},[`${d}qualifiedValueShape`]:(t,e)=>{const s=t.config.getNodeTemplate(e,t);t.qualifiedValueShape=s,t.nodeShapes.add(s)},[`${d}qualifiedMinCount`]:(t,e)=>{t.qualifiedMinCount=parseInt(e.value)},[`${d}qualifiedMaxCount`]:(t,e)=>{t.qualifiedMaxCount=parseInt(e.value)},[se.id]:(t,e)=>{t.owlImports.add(e)},[ne.id]:(t,e)=>{t.class=e;const s=t.config.store.getSubjects(z,e,null);s.length>0&&(t.node=s[0])},[`${d}or`]:(t,e)=>{const s=t.config.lists[e.value];s?.length?t.or=s:console.error("list for sh:or not found:",e.value,"existing lists:",t.config.lists)},[`${d}xone`]:(t,e)=>{const s=t.config.lists[e.value];s?.length?t.xone=s:console.error("list for sh:xone not found:",e.value,"existing lists:",t.config.lists)}};class he{constructor(e,s){this.label="",this.nodeShapes=new Set,this.owlImports=new Set,this.id=e,this.parent=s,this.config=s.config,this.config.registerPropertyTemplate(this),oe(this,this.config.store.getQuads(e,null,null,null)),this.aggregatedMinCount=Math.max(this.minCount||0,this.qualifiedMinCount||0),this.aggregatedMaxCount=Math.min(this.maxCount||0,this.qualifiedMaxCount||0)}}function Ee(t){const e=Object.assign({},t);return e.nodeShapes=new Set(t.nodeShapes),e.owlImports=new Set(t.owlImports),t.languageIn&&(e.languageIn=[...t.languageIn]),t.or&&(e.or=[...t.or]),t.xone&&(e.xone=[...t.xone]),e}function oe(t,e){for(const s of e)Be[s.predicate.id]?.call(t,t,s.object);return t.label=t.name?.value||R(e,t.config.languages),t.label||(t.label=t.path?X(t.path,j):"unknown"),t}function Ce(t,e){const s=e,i=t;for(const n in e)n!=="parent"&&n!=="config"&&n!=="id"&&s[n]!==void 0&&s[n]!==""&&(Array.isArray(s[n])?i[n].push(...s[n]):s[n]instanceof Set&&s[n].size?i[n]=new Set([...i[n],...s[n]]):i[n]=s[n])}function xe(t,e,s){const i=document.createElement("div");i.classList.add("shacl-or-constraint");const n=[];if(e instanceof I){const o=[];let a=!1;t.length&&(a=s.store.countQuads(t[0],W,null,null)>0);for(let c=0;c<t.length;c++)if(a){const f=s.store.getObjects(t[c],W,null),h=[];let v="";for(const p of f){const w=s.getPropertyTemplate(p,e.template),C=new M(w,e);h.push(C),v+=(v.length>1?" / ":"")+C.template.label}o.push(h),n.push({label:v,value:c.toString()})}else{const f=t[c],h=s.getPropertyTemplate(f,e.template),v=new M(h,e);o.push([v]),n.push({label:v.template.label,value:c.toString()})}const r=s.theme.createListEditor("Please choose",null,!1,n),l=r.querySelector(".editor");l.onchange=()=>{if(l.value){const c=o[parseInt(l.value)];let f;c.length&&(f=c[0],i.replaceWith(c[0]));for(let h=1;h<c.length;h++)f.after(c[h]),f=c[h]}},i.appendChild(r)}else{const o=[];for(let l=0;l<t.length;l++){const c=s.store.getQuads(t[l],null,null,null);c.length&&(o.push(c),n.push({label:R(c,s.languages)||X(c[0].predicate.value,j)+" = "+X(c[0].object.value,j),value:l.toString()}))}const a=s.theme.createListEditor(e.template.label+"?",null,!1,n,e.template),r=a.querySelector(".editor");r.onchange=()=>{if(r.value){const l=oe(Ee(e.template),o[parseInt(r.value)]);i.replaceWith(q(l,void 0,!0))}},i.appendChild(a)}return i}function ze(t,e,s){if(e instanceof S){const i=e.datatype;for(const n of t){const o=s.store.getQuads(n,null,null,null);for(const a of o)if(a.predicate.value===`${d}datatype`&&a.object.equals(i))return o}}else{const i=s.store.getObjects(e,g,null);for(const n of t){const o=s.store.getQuads(n,null,null,null);for(const a of o)if(i.length>0){if(a.predicate.value===`${d}node`){for(const r of i)if(s.store.getQuads(a.object,z,r,null).length>0)return o}if(a.predicate.equals(ne)){for(const r of i)if(a.object.equals(r))return o}}else if(a.predicate.equals(qe)&&a.object.equals(ve))return o}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Ge(t,e,s){for(const i of t){let n=!1;const o=s.store.getObjects(i,W,null);for(const a of o){const r=s.store.getObjects(a,`${d}path`,null);for(const l of r)if(n=s.store.countQuads(e,l,null,null)>0,n)break}if(n)return o}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const Ue=`form { display:block; --label-width: 8em; --caret-size: 10px; }
2
2
  form.mode-edit { padding-left: 1em; }
3
3
  form, form * { box-sizing: border-box; }
4
4
  shacl-node, .collapsible::part(content) { display: flex; flex-direction: column; width: 100%; position: relative; }
@@ -36,6 +36,7 @@ textarea.editor { resize: vertical; }
36
36
  .d-flex { display: flex; }
37
37
  .lang { opacity: 0.65; font-size: 0.6em; }
38
38
  a, a:visited { color: inherit; }
39
+ h3 { margin-top: 0; }
39
40
 
40
41
  .fadeIn, .fadeOut { animation: fadeIn 0.2s ease-out; }
41
42
  .fadeOut { animation-direction: reverse; animation-timing-function: ease-out;}
@@ -60,18 +61,18 @@ a, a:visited { color: inherit; }
60
61
  background: linear-gradient(var(--hierarchy-colors)) no-repeat 0 calc(var(--index) * 100% / (var(--hierarchy-colors-length) - 1)) / 100% calc(1px * infinity);
61
62
  }
62
63
  .property-instance:not(:has(shacl-node)) > .remove-button-wrapper.colorize::before { background: 0; }
63
- `;class He{constructor(e){this.dense=!0;let t=Ue;e&&(t+=`
64
- `+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}setDense(e){this.dense=e}createViewer(e,t,i){const n=document.createElement("div"),o=document.createElement("label");o.innerHTML=e+":",i.description&&o.setAttribute("title",i.description.value),n.appendChild(o);let a=t.value,r=null;if(t instanceof R){const c=i.config.store.getQuads(a,null,null,null);if(c.length){const f=P(c,i.config.languages);f&&(a=f)}}else t instanceof S&&(t.language?(r=document.createElement("span"),r.classList.add("lang"),r.innerText=`@${t.language}`):t.datatype.value===`${E}date`?a=new Date(Date.parse(t.value)).toDateString():t.datatype.value===`${E}dateTime`&&(a=new Date(Date.parse(t.value)).toLocaleString()));let l;return W(t.value)?(l=document.createElement("a"),l.setAttribute("href",t.value)):l=document.createElement("div"),l.classList.add("d-flex"),l.innerText=a,r&&l.appendChild(r),n.appendChild(l),n}}function Ke(s,e,t){if(t){const i=s.aggregatedMinCount>0;if(s.class&&!s.hasValue)return s.config.theme.createListEditor(s.label,e,i,ne(s.class,s),s);if(s.in){const n=s.config.lists[s.in];if(n?.length){const o=ve(n,s.config.store,s.config.languages);return s.config.theme.createListEditor(s.label,e,i,o,s)}else console.error("list not found:",s.in,"existing lists:",s.config.lists)}if(s.datatype?.equals(me)||s.languageIn?.length||s.datatype===void 0&&e instanceof S&&e.language)return s.config.theme.createLangStringEditor(s.label,e,i,s);switch(s.datatype?.value.replace(E,"")){case"integer":case"float":case"double":case"decimal":return s.config.theme.createNumberEditor(s.label,e,i,s);case"date":case"dateTime":return s.config.theme.createDateEditor(s.label,e,i,s);case"boolean":return s.config.theme.createBooleanEditor(s.label,e,i,s);case"base64Binary":return s.config.theme.createFileEditor(s.label,e,i,s)}return s.config.theme.createTextEditor(s.label,e,i,s)}else{if(e)return s.config.theme.createViewer(s.label,e,s);const i=document.createElement("div");return i.innerHTML="No value",i}}function We(s,e,t){if(e==="application/ld+json")return Xe(s);{const i=new Te({format:e,prefixes:t});i.addQuads(s);let n="";return i.end((o,a)=>{o&&console.error(o),n=a}),n}}function Xe(s){const e=[];for(const t of s){const i={"@id":t.subject.id};if(t.predicate===g)i["@type"]=t.object.id;else{let n=t.object.value;t.object instanceof S?t.object.language?n={"@language":t.object.language,"@value":t.object.value}:t.object.datatype&&t.object.datatype.value!==`${E}#string`&&(n={"@type":t.object.datatype.value,"@value":t.object.value}):n={"@id":t.object.id},i[t.predicate.value]=n}e.push(i)}return JSON.stringify(e)}function Je(s){let e=s.shaclDatatype,t=s.dataset.value||s.value;if(t){if(t.startsWith("<")&&t.endsWith(">")&&t.indexOf(":")>-1)return u.namedNode(t.substring(1,t.length-1));if(s.dataset.class||s.dataset.nodeKind===d+"IRI")return u.namedNode(t);if(s.dataset.link)return JSON.parse(s.dataset.link);if(s.dataset.lang?e=s.dataset.lang:s.type==="number"?t=parseFloat(t):s.type==="file"&&s.binaryData?t=s.binaryData:s.type==="datetime-local"&&(t=new Date(t).toISOString().slice(0,19)),(!e||e instanceof R&&ke.equals(e))&&typeof t=="string"){let i=t.split("^^");i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')&&i[1].split(":").length===2?(t=i[0].substring(1,i[0].length-1),e=u.namedNode(i[1])):(i=t.split("@"),i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')?(t=i[0].substring(1,i[0].length-1),e=i[1]):t.startsWith('"')&&t.endsWith('"')&&(t=t.substring(1,t.length-1)))}return u.literal(t,e)}else if((s.type==="checkbox"||s.getAttribute("type")==="checkbox")&&(s.checked||parseInt(s.dataset.minCount||"0")>0))return u.literal(s.checked?"true":"false",e)}const $={};function Ye(s){s.predicate===void 0&&s.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',s):$[`${s.predicate}^${s.datatype}`]=s}function Ze(){return Object.entries($).map(s=>s[1])}function et(s,e){let t=$[`${s}^${e}`];return t||(t=$[`${s}^undefined`],t)?t:$[`undefined^${e}`]}class mt{constructor(e,t){this.predicate=e.predicate,this.datatype=e.datatype,t&&(this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t))}createViewer(e,t){return e.config.theme.createViewer(e.label,t,e)}}class V extends HTMLElement{constructor(e,t){if(super(),this.template=e,this.parent=t,this.container=this,this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){const i=new Y;i.classList.add("collapsible","shacl-group"),i.open=e.config.attributes.collapse==="open",i.label=this.template.label,this.container=i,this.appendChild(this.container)}this.template.order!==void 0&&(this.style.order=`${this.template.order}`),this.template.cssClass&&this.classList.add(this.template.cssClass),e.config.editMode&&!t.linked&&(this.addButton=this.createAddButton(),this.container.appendChild(this.addButton),this.addEventListener("change",()=>{this.updateControls()}))}async bindValues(e){if(this.template.path){let t=!1;if(e){let i=this.template.config.store.getQuads(e,this.template.path,null,this.parent.linked?null:b);i=await this.filterValidValues(i,e);for(const n of i)this.template.config.store.delete(n),this.addPropertyInstance(n.object),this.template.hasValue&&n.object.equals(this.template.hasValue)&&(t=!0)}this.template.config.editMode&&(this.template.hasValue&&!t&&!this.parent.linked&&this.addPropertyInstance(this.template.hasValue),this.updateControls())}}addPropertyInstance(e){let t;if(this.template.or?.length||this.template.xone?.length){const i=this.template.or?.length?this.template.or:this.template.xone;let n=!1;if(e){const o=ze(i,e,this.template.config);if(o.length){const a=ie(Se(this.template),o);t=q(a,e,!0),n=!0}}n||(t=Ce(i,this,this.template.config),xe(t,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else{let i=!1;if(e&&!(e instanceof S)){const n=this.getRdfClassToLinkOrCreate();n&&this.template.config.store.countQuads(e,g,n,b)===0&&(i=!0)}t=q(this.template,e,void 0,i||this.parent.linked)}return this.addButton?this.container.insertBefore(t,this.addButton):this.container.appendChild(t),t}updateControls(){let e=this.instanceCount();e===0&&(this.template.nodeShapes.size===0||this.template.aggregatedMinCount>0)&&(this.addPropertyInstance(),e=this.instanceCount());let t;this.template.aggregatedMinCount>0?t=e>this.template.aggregatedMinCount:t=this.template.nodeShapes.size>0||e>1;const i=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",t),this.classList.toggle("may-add",i)}instanceCount(){return this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length}toRDF(e,t){const i=u.namedNode(this.template.path);for(const n of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance"))if(n.firstChild instanceof I){const o=n.firstChild.toRDF(e);e.addQuad(t,i,o,this.template.config.valuesGraphId)}else for(const o of n.querySelectorAll(":scope > .editor")){const a=Je(o);a&&e.addQuad(t,i,a,this.template.config.valuesGraphId)}}getRdfClassToLinkOrCreate(){if(this.template.class&&this.template.nodeShapes.size)return this.template.class;for(const e of this.template.nodeShapes)if(e.targetClass)return e.targetClass}async filterValidValues(e,t){let i=this.template.id,n=[t];if(this.template.qualifiedValueShape){i=this.template.qualifiedValueShape.id,n=[];for(const r of e)n.push(r.object)}const o=await this.template.config.validator.validate({dataset:this.template.config.store,terms:n},[{terms:[i]}]),a=[];for(const r of o.results){const l=this.template.qualifiedValueShape?r.focusNode:r.value;l?.ptrs?.length&&a.push(l.ptrs[0]._term.id)}return e.filter(r=>a.indexOf(r.object.id)===-1)}createAddButton(){const e=new ge;e.dense=this.template.config.theme.dense,e.label="+ "+this.template.label,e.title="Add "+this.template.label,e.autoGrowLabelWidth=!0,e.classList.add("add-button");let t=[],i=this.getRdfClassToLinkOrCreate();if(i&&(t=ne(i,this.template)),t.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",n=>{e.blur();const o=this.addPropertyInstance();o.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Ve(o),o.classList.remove("fadeIn")},200)});else{const n=document.createElement("ul"),o=document.createElement("li");o.innerHTML="&#xFF0B; Create new "+this.template.label+"...",o.dataset.value="new",o.classList.add("large"),n.appendChild(o);const a=document.createElement("li");a.classList.add("divider"),n.appendChild(a);const r=document.createElement("li");r.classList.add("header"),r.innerText="Or link existing:",n.appendChild(r);for(const l of t){const c=document.createElement("li"),f=typeof l.value=="string"?l.value:l.value.value;c.innerText=l.label?l.label:f,c.dataset.value=JSON.stringify(l.value),n.appendChild(c)}e.appendChild(n),e.collapsibleWidth="250px",e.collapsibleOrientationLeft="",e.addEventListener("change",()=>{if(e.value==="new")this.addPropertyInstance();else{const l=JSON.parse(e.value);this.container.insertBefore(q(this.template,l,!0,!0),e)}e.value=""})}return e}}function q(s,e,t=!1,i=!1){let n;if(s.nodeShapes.size){n=document.createElement("div"),n.classList.add("property-instance");for(const o of s.nodeShapes)n.appendChild(new I(o,e,s.nodeKind,s.label,i))}else{const o=et(s.path,s.datatype?.value);o?s.config.editMode&&!i?n=o.createEditor(s,e):n=o.createViewer(s,e):n=Ke(s,e||null,s.config.editMode&&!i),n.classList.add("property-instance"),i&&n.classList.add("linked")}return s.config.editMode&&xe(n,s.label,s.config.theme.dense,s.config.hierarchyColorsStyleSheet!==void 0,t),n.dataset.path=s.path,n}function xe(s,e,t,i,n=!1){const o=document.createElement("div");o.className="remove-button-wrapper",i&&o.classList.add("colorize");const a=new Pe;a.classList.add("remove-button","clear"),a.title="Remove "+e,a.dense=t,a.icon=!0,a.addEventListener("click",r=>{s.classList.remove("fadeIn"),s.classList.add("fadeOut"),setTimeout(()=>{const l=s.parentElement;s.remove(),l?.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0}))},200)}),n&&a.classList.add("persistent"),o.appendChild(a),s.appendChild(o)}window.customElements.define("shacl-property",V);function tt(s,e){let t=s;const i=e.store.getQuads(s,null,null,null),n=D(i,"label",Z,e.languages);n&&(t=n);let o;if(e.attributes.collapse!==null)o=new Y,o.classList.add("collapsible"),o.open=e.attributes.collapse==="open",o.label=t;else{o=document.createElement("div");const r=document.createElement("h1");r.innerText=t,o.appendChild(r)}o.dataset.subject=s,o.classList.add("shacl-group");const a=D(i,"order");return a&&(o.style.order=a),o}class I extends HTMLElement{constructor(e,t,i,n,o){super(),this.template=e,this.linked=o||!1;let a=t;a||(!i&&e.nodeKind&&(i=e.nodeKind),i===void 0&&e.config.attributes.valuesNamespace||i?.value===`${d}IRI`?a=u.namedNode(e.config.attributes.valuesNamespace+ae()):a=u.blankNode(ae())),this.nodeId=a;const r=JSON.stringify([e.id,t]);if(t&&e.config.renderedNodes.has(r)){n=n||"Link";const l=document.createElement("label");l.innerText=n,l.classList.add("linked"),this.appendChild(l);const c=document.createElement("a");let f=t.termType==="BlankNode"?"_:"+t.value:t.value;c.innerText=f,c.classList.add("ref-link"),c.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${f}']`)?.scrollIntoView()},this.appendChild(c),this.style.flexDirection="row"}else{if(t&&e.config.renderedNodes.add(r),this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){const l=document.createElement("div");l.innerText=`id: ${this.nodeId.id}`,l.classList.add("node-id-display"),this.appendChild(l)}(async()=>{for(const[l,c]of Object.entries(e.properties))for(const f of c)await this.addPropertyInstance(f,t);for(const l of e.extendedShapes)this.prepend(new I(l,t));if(e.or?.length&&await this.tryResolve(e.or,t,e.config),e.xone?.length&&await this.tryResolve(e.xone,t,e.config),n){const l=document.createElement("h1");l.innerText=n,this.prepend(l)}})()}}toRDF(e,t,i=""){if(t||(t=this.nodeId),!this.linked){for(const n of this.querySelectorAll(":scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property"))n.toRDF(e,t);this.template.targetClass&&e.addQuad(t,g,this.template.targetClass,this.template.config.valuesGraphId),i&&e.addQuad(t,u.namedNode(i),this.template.id,this.template.config.valuesGraphId)}return t}async addPropertyInstance(e,t){let i=this;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let o=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);o||(o=tt(e.group,e.config),this.appendChild(o)),i=o}else console.warn("ignoring unknown group reference",e.group,"existing groups:",e.config.groups);const n=new V(e,this);await n.bindValues(t),(e.config.editMode||n.instanceCount()>0)&&(i.appendChild(n),n.updateControls())}async tryResolve(e,t,i){let n=!1;if(t){const o=Ge(e,t,i);if(o.length){for(const a of o)await this.addPropertyInstance(i.getPropertyTemplate(a,this.template),t);n=!0}}n||this.appendChild(Ce(e,this,i))}}window.customElements.define("shacl-node",I);const st=`
64
+ `;class He{constructor(e){this.dense=!0;let s=Ue;e&&(s+=`
65
+ `+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(s)}apply(e){}setDense(e){this.dense=e}createViewer(e,s,i){const n=document.createElement("div"),o=document.createElement("label");o.innerHTML=e+":",i.description&&o.setAttribute("title",i.description.value),n.appendChild(o);let a=s.value,r=null;if(s instanceof $){const c=i.config.store.getQuads(a,null,null,null);if(c.length){const f=R(c,i.config.languages);f&&(a=f)}}else s instanceof S&&(s.language?(r=document.createElement("span"),r.classList.add("lang"),r.innerText=`@${s.language}`):s.datatype.value===`${E}date`?a=new Date(Date.parse(s.value)).toDateString():s.datatype.value===`${E}dateTime`&&(a=new Date(Date.parse(s.value)).toLocaleString()));let l;return J(s.value)?(l=document.createElement("a"),l.setAttribute("href",s.value)):l=document.createElement("div"),l.classList.add("d-flex"),l.innerText=a,r&&l.appendChild(r),n.appendChild(l),n}}function Ke(t,e,s){if(s){const i=t.aggregatedMinCount>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,e,i,ie(t.class,t),t);if(t.in){const n=t.config.lists[t.in];if(n?.length){const o=ye(n,t.config.store,t.config.languages);return t.config.theme.createListEditor(t.label,e,i,o,t)}else console.error("list not found:",t.in,"existing lists:",t.config.lists)}if(t.datatype?.equals(be)||t.languageIn?.length||t.datatype===void 0&&e instanceof S&&e.language)return t.config.theme.createLangStringEditor(t.label,e,i,t);switch(t.datatype?.value.replace(E,"")){case"integer":case"float":case"double":case"decimal":return t.config.theme.createNumberEditor(t.label,e,i,t);case"date":case"dateTime":return t.config.theme.createDateEditor(t.label,e,i,t);case"boolean":return t.config.theme.createBooleanEditor(t.label,e,i,t);case"base64Binary":return t.config.theme.createFileEditor(t.label,e,i,t)}return t.config.theme.createTextEditor(t.label,e,i,t)}else{if(e)return t.config.theme.createViewer(t.label,e,t);const i=document.createElement("div");return i.innerHTML="No value",i}}function We(t,e,s){if(e==="application/ld+json")return Xe(t);{const i=new Ie({format:e,prefixes:s});i.addQuads(t);let n="";return i.end((o,a)=>{o&&console.error(o),n=a}),n}}function Xe(t){const e=[];for(const s of t){const i={"@id":s.subject.id};if(s.predicate===g)i["@type"]=s.object.id;else{let n=s.object.value;s.object instanceof S?s.object.language?n={"@language":s.object.language,"@value":s.object.value}:s.object.datatype&&s.object.datatype.value!==`${E}#string`&&(n={"@type":s.object.datatype.value,"@value":s.object.value}):n={"@id":s.object.id},i[s.predicate.value]=n}e.push(i)}return JSON.stringify(e)}function Je(t){let e=t.shaclDatatype,s=t.dataset.value||t.value;if(s){if(s.startsWith("<")&&s.endsWith(">")&&s.indexOf(":")>-1)return u.namedNode(s.substring(1,s.length-1));if(t.dataset.class||t.dataset.nodeKind===d+"IRI")return u.namedNode(s);if(t.dataset.link)return JSON.parse(t.dataset.link);if(t.dataset.lang?e=t.dataset.lang:t.type==="number"?s=parseFloat(s):t.type==="file"&&t.binaryData?s=t.binaryData:t.type==="datetime-local"&&(s=new Date(s).toISOString().slice(0,19)),(!e||e instanceof $&&ke.equals(e))&&typeof s=="string"){let i=s.split("^^");i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')&&i[1].split(":").length===2?(s=i[0].substring(1,i[0].length-1),e=u.namedNode(i[1])):(i=s.split("@"),i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')?(s=i[0].substring(1,i[0].length-1),e=i[1]):s.startsWith('"')&&s.endsWith('"')&&(s=s.substring(1,s.length-1)))}return u.literal(s,e)}else if((t.type==="checkbox"||t.getAttribute("type")==="checkbox")&&(t.checked||parseInt(t.dataset.minCount||"0")>0))return u.literal(t.checked?"true":"false",e)}const D={};function Ye(t){t.predicate===void 0&&t.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',t):D[`${t.predicate}^${t.datatype}`]=t}function Ze(){return Object.entries(D).map(t=>t[1])}function et(t,e){let s=D[`${t}^${e}`];return s||(s=D[`${t}^undefined`],s)?s:D[`undefined^${e}`]}class mt{constructor(e,s){this.predicate=e.predicate,this.datatype=e.datatype,s&&(this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(s))}createViewer(e,s){return e.config.theme.createViewer(e.label,s,e)}}class M extends HTMLElement{constructor(e,s){if(super(),this.template=e,this.parent=s,this.container=this,this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){const i=new ee;i.classList.add("collapsible","shacl-group"),i.open=e.config.attributes.collapse==="open",i.label=this.template.label,this.container=i,this.appendChild(this.container)}this.template.order!==void 0&&(this.style.order=`${this.template.order}`),this.template.cssClass&&this.classList.add(this.template.cssClass),e.config.editMode&&!s.linked&&(this.addButton=this.createAddButton(),this.container.appendChild(this.addButton),this.addEventListener("change",()=>{this.updateControls()}))}async bindValues(e){if(this.template.path){let s=!1;if(e){let i=this.template.config.store.getQuads(e,this.template.path,null,this.parent.linked?null:b);i=await this.filterValidValues(i,e);for(const n of i)this.template.config.store.delete(n),this.addPropertyInstance(n.object),this.template.hasValue&&n.object.equals(this.template.hasValue)&&(s=!0)}this.template.config.editMode&&(this.template.hasValue&&!s&&!this.parent.linked&&this.addPropertyInstance(this.template.hasValue),this.updateControls())}}addPropertyInstance(e){let s;if(this.template.or?.length||this.template.xone?.length){const i=this.template.or?.length?this.template.or:this.template.xone;let n=!1;if(e){const o=ze(i,e,this.template.config);if(o.length){const a=oe(Ee(this.template),o);s=q(a,e,!0),n=!0}}n||(s=xe(i,this,this.template.config),Le(s,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else{let i=!1;if(e&&!(e instanceof S)){const n=this.getRdfClassToLinkOrCreate();n&&this.template.config.store.countQuads(e,g,n,b)===0&&(i=!0)}s=q(this.template,e,void 0,i||this.parent.linked)}return this.addButton?this.container.insertBefore(s,this.addButton):this.container.appendChild(s),s}updateControls(){let e=this.instanceCount();e===0&&(this.template.nodeShapes.size===0||this.template.aggregatedMinCount>0)&&(this.addPropertyInstance(),e=this.instanceCount());let s;this.template.aggregatedMinCount>0?s=e>this.template.aggregatedMinCount:s=this.template.nodeShapes.size>0||e>1;const i=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",s),this.classList.toggle("may-add",i)}instanceCount(){return this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length}toRDF(e,s){const i=u.namedNode(this.template.path);for(const n of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance"))if(n.firstChild instanceof I){const o=n.firstChild.toRDF(e);e.addQuad(s,i,o,this.template.config.valuesGraphId)}else for(const o of n.querySelectorAll(":scope > .editor")){const a=Je(o);a&&e.addQuad(s,i,a,this.template.config.valuesGraphId)}}getRdfClassToLinkOrCreate(){if(this.template.class&&this.template.nodeShapes.size)return this.template.class;for(const e of this.template.nodeShapes)if(e.targetClass)return e.targetClass}async filterValidValues(e,s){let i=this.template.id,n=[s];if(this.template.qualifiedValueShape){i=this.template.qualifiedValueShape.id,n=[];for(const r of e)n.push(r.object)}const o=await this.template.config.validator.validate({dataset:this.template.config.store,terms:n},[{terms:[i]}]),a=[];for(const r of o.results){const l=this.template.qualifiedValueShape?r.focusNode:r.value;l?.ptrs?.length&&a.push(l.ptrs[0]._term.id)}return e.filter(r=>a.indexOf(r.object.id)===-1)}createAddButton(){const e=new ge;e.dense=this.template.config.theme.dense,e.label="+ "+this.template.label,e.title="Add "+this.template.label,e.autoGrowLabelWidth=!0,e.classList.add("add-button");let s=[],i=this.getRdfClassToLinkOrCreate();if(i&&(s=ie(i,this.template)),s.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",n=>{e.blur();const o=this.addPropertyInstance();o.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Ve(o),o.classList.remove("fadeIn")},200)});else{const n=document.createElement("ul"),o=document.createElement("li");o.innerHTML="&#xFF0B; Create new "+this.template.label+"...",o.dataset.value="new",o.classList.add("large"),n.appendChild(o);const a=document.createElement("li");a.classList.add("divider"),n.appendChild(a);const r=document.createElement("li");r.classList.add("header"),r.innerText="Or link existing:",n.appendChild(r);for(const l of s){const c=document.createElement("li"),f=typeof l.value=="string"?l.value:l.value.value;c.innerText=l.label?l.label:f,c.dataset.value=JSON.stringify(l.value),n.appendChild(c)}e.appendChild(n),e.collapsibleWidth="250px",e.collapsibleOrientationLeft="",e.addEventListener("change",()=>{if(e.value==="new")this.addPropertyInstance();else{const l=JSON.parse(e.value);this.container.insertBefore(q(this.template,l,!0,!0),e)}e.value=""})}return e}}function q(t,e,s=!1,i=!1){let n;if(t.nodeShapes.size){n=document.createElement("div"),n.classList.add("property-instance");for(const o of t.nodeShapes)n.appendChild(new I(o,e,t.nodeKind,t.label,i))}else{const o=et(t.path,t.datatype?.value);o?t.config.editMode&&!i?n=o.createEditor(t,e):n=o.createViewer(t,e):n=Ke(t,e||null,t.config.editMode&&!i),n.classList.add("property-instance"),i&&n.classList.add("linked")}return t.config.editMode&&Le(n,t.label,t.config.theme.dense,t.config.hierarchyColorsStyleSheet!==void 0,s),n.dataset.path=t.path,n}function Le(t,e,s,i,n=!1){const o=document.createElement("div");o.className="remove-button-wrapper",i&&o.classList.add("colorize");const a=new $e;a.classList.add("remove-button","clear"),a.title="Remove "+e,a.dense=s,a.icon=!0,a.addEventListener("click",r=>{t.classList.remove("fadeIn"),t.classList.add("fadeOut"),setTimeout(()=>{const l=t.parentElement;t.remove(),l?.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0}))},200)}),n&&a.classList.add("persistent"),o.appendChild(a),t.appendChild(o)}window.customElements.define("shacl-property",M);function tt(t,e){let s=t;const i=e.store.getQuads(t,null,null,null),n=P(i,"label",B,e.languages);n&&(s=n);let o;if(e.attributes.collapse!==null)o=new ee,o.classList.add("collapsible"),o.open=e.attributes.collapse==="open",o.label=s;else{o=document.createElement("div");const r=document.createElement("h1");r.innerText=s,o.appendChild(r)}o.dataset.subject=t,o.classList.add("shacl-group");const a=P(i,"order");return a&&(o.style.order=a),o}class I extends HTMLElement{constructor(e,s,i,n,o){super(),this.template=e,this.linked=o||!1;let a=s;a||(!i&&e.nodeKind&&(i=e.nodeKind),i===void 0&&e.config.attributes.valuesNamespace||i?.value===`${d}IRI`?a=u.namedNode(e.config.attributes.valuesNamespace+re()):a=u.blankNode(re())),this.nodeId=a;const r=JSON.stringify([e.id,s]);if(s&&e.config.renderedNodes.has(r)){n=n||"Link";const l=document.createElement("label");l.innerText=n,l.classList.add("linked"),this.appendChild(l);const c=document.createElement("a");let f=s.termType==="BlankNode"?"_:"+s.value:s.value;c.innerText=f,c.classList.add("ref-link"),c.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${f}']`)?.scrollIntoView()},this.appendChild(c),this.style.flexDirection="row"}else{if(s&&e.config.renderedNodes.add(r),this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){const l=document.createElement("div");l.innerText=`id: ${this.nodeId.id}`,l.classList.add("node-id-display"),this.appendChild(l)}(async()=>{for(const[l,c]of Object.entries(e.properties))for(const f of c)await this.addPropertyInstance(f,s);for(const l of e.extendedShapes)this.prepend(new I(l,s));if(e.or?.length&&await this.tryResolve(e.or,s,e.config),e.xone?.length&&await this.tryResolve(e.xone,s,e.config),n){const l=document.createElement("h1");l.innerText=n,this.prepend(l)}})()}}toRDF(e,s,i=""){if(s||(s=this.nodeId),!this.linked){for(const n of this.querySelectorAll(":scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property"))n.toRDF(e,s);this.template.targetClass&&e.addQuad(s,g,this.template.targetClass,this.template.config.valuesGraphId),i&&e.addQuad(s,u.namedNode(i),this.template.id,this.template.config.valuesGraphId)}return s}async addPropertyInstance(e,s){let i=this;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let o=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);o||(o=tt(e.group,e.config),this.appendChild(o)),i=o}else console.warn("ignoring unknown group reference",e.group,"existing groups:",e.config.groups);const n=new M(e,this);await n.bindValues(s),(e.config.editMode||n.instanceCount()>0)&&(i.appendChild(n),n.updateControls())}async tryResolve(e,s,i){let n=!1;if(s){const o=Ge(e,s,i);if(o.length){for(const a of o)await this.addPropertyInstance(i.getPropertyTemplate(a,this.template),s);n=!0}}n||this.appendChild(xe(e,this,i))}}window.customElements.define("shacl-node",I);const st=`
65
66
  .editor:not([type='checkbox']) { border: 1px solid #DDD; }
66
67
  .property-instance label { display: inline-flex; word-break: break-word; line-height: 1em; padding-top: 0.15em; padding-right: 1em; flex-shrink: 0; position: relative; }
67
68
  .property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
68
69
  .mode-edit .property-instance label { width: var(--label-width); }
69
- `;class nt extends He{constructor(e){super(e||st),this.idCtr=0}createDefaultTemplate(e,t,i,n,o){if(n.id=`e${this.idCtr++}`,n.classList.add("editor"),o?.datatype?n.shaclDatatype=o.datatype:t instanceof S&&(n.shaclDatatype=t.datatype),o&&o.aggregatedMinCount>0&&(n.dataset.minCount=String(o.aggregatedMinCount)),o?.class&&(n.dataset.class=o.class.value),o?.nodeKind)n.dataset.nodeKind=o.nodeKind.value;else if(t&&(t instanceof R||o?.nodeKind?.equals(be))&&(n.dataset.nodeKind=d+"IRI",o)){const c=P(o.config.store.getQuads(t,null,null,null),o.config.languages);c&&(n.dataset.value="<"+t.value+">",t=u.literal(c))}(o?.hasValue&&t||o?.readonly)&&(n.disabled=!0),n.value=t?.value||o?.defaultValue?.value||"";const a=document.createElement("label");a.htmlFor=n.id,a.innerText=e,o?.description&&a.setAttribute("title",o.description.value);const r=o?.description?o.description.value:o?.pattern?o.pattern:null;r&&n.setAttribute("placeholder",r),i&&(n.setAttribute("required","true"),a.classList.add("required"));const l=document.createElement("div");return l.appendChild(a),l.appendChild(n),l}createDateEditor(e,t,i,n){const o=new B;n.datatype?.value===E+"dateTime"?(o.type="datetime-local",o.setAttribute("step","1")):o.type="date",o.clearable=!0,o.dense=this.dense,o.classList.add("pr-0");const a=this.createDefaultTemplate(e,null,i,o,n);if(t)try{let r=new Date(t.value).toISOString();n.datatype?.value===E+"dateTime"?r=r.slice(0,19):r=r.slice(0,10),o.value=r}catch(r){console.error(r,t)}return a}createTextEditor(e,t,i,n){let o;return n.singleLine===!1?(o=new Re,o.resize="auto"):o=new B,o.dense=this.dense,n.pattern&&(o.pattern=n.pattern),n.minLength&&(o.minLength=n.minLength),n.maxLength&&(o.maxLength=n.maxLength),this.createDefaultTemplate(e,t,i,o,n)}createLangStringEditor(e,t,i,n){const o=this.createTextEditor(e,t,i,n),a=o.querySelector(":scope .editor");let r;if(n.languageIn?.length){r=document.createElement("select");for(const l of n.languageIn){const c=document.createElement("option");c.innerText=l.value,r.appendChild(c)}}else r=document.createElement("input"),r.maxLength=5,r.size=5,r.placeholder="lang?";return r.title="Language of the text",r.classList.add("lang-chooser"),r.slot="suffix",r.addEventListener("change",l=>{l.stopPropagation(),a&&(a.dataset.lang=r.value,a.dispatchEvent(new Event("change",{bubbles:!0})))}),t instanceof S&&(r.value=t.language),a.dataset.lang=r.value,a.appendChild(r),o}createBooleanEditor(e,t,i,n){const o=document.createElement("input");o.type="checkbox",o.classList.add("ml-0");const a=this.createDefaultTemplate(e,null,i,o,n);return o.removeAttribute("required"),a.querySelector(":scope label")?.classList.remove("required"),t instanceof S&&(o.checked=t.value==="true"),a}createFileEditor(e,t,i,n){const o=document.createElement("input");return o.type="file",o.addEventListener("change",a=>{if(o.files?.length){a.stopPropagation();const r=new FileReader;r.readAsDataURL(o.files[0]),r.onload=()=>{o.binaryData=btoa(r.result),o.parentElement?.dispatchEvent(new Event("change",{bubbles:!0}))}}else o.binaryData=void 0}),this.createDefaultTemplate(e,t,i,o,n)}createNumberEditor(e,t,i,n){const o=new B;o.type="number",o.clearable=!0,o.dense=this.dense,o.classList.add("pr-0");const a=n.minInclusive!==void 0?n.minInclusive:n.minExclusive!==void 0?n.minExclusive+1:void 0,r=n.maxInclusive!==void 0?n.maxInclusive:n.maxExclusive!==void 0?n.maxExclusive-1:void 0;return a!==void 0&&(o.min=String(a)),r!==void 0&&(o.max=String(r)),n.datatype?.value!==E+"integer"&&(o.step="0.1"),this.createDefaultTemplate(e,t,i,o,n)}createListEditor(e,t,i,n,o){const a=new ge;a.clearable=!0,a.dense=this.dense;const r=this.createDefaultTemplate(e,null,i,a,o),l=document.createElement("ul");let c=!0;const f=(h,v)=>{const p=document.createElement("li");if(typeof h.value=="string"?(p.dataset.value=h.value,p.innerText=h.label?h.label:h.value):(p.dataset.value=h.value.id,h.value instanceof R&&(p.dataset.value="<"+p.dataset.value+">"),p.innerText=h.label?h.label:h.value.value),v.appendChild(p),h.children?.length){c=!1;const w=document.createElement("ul");p.appendChild(w);for(const C of h.children)f(C,w)}};for(const h of n)f(h,l);return c||(a.collapse=!0),a.appendChild(l),t&&(a.value=t.id,t instanceof R&&(a.value="<"+a.value+">")),r}createButton(e,t){const i=document.createElement("rokit-button");return i.innerHTML=e,i}}const it={[`${d}node`]:(s,e)=>{s.extendedShapes.add(new M(e,s.config,s))},[`${d}and`]:(s,e)=>{for(const t of s.config.lists[e.value])s.extendedShapes.add(new M(t,s.config,s))},[`${d}property`]:(s,e)=>{const t=s.config.getPropertyTemplate(e,s);if(t.path){let i=s.properties[t.path];if(i||(i=[],s.properties[t.path]=i),t.qualifiedValueShape)i.push(t);else{let n;for(let o=0;o<s.properties[t.path].length&&!n;o++)s.properties[t.path][o].qualifiedValueShape||(n=s.properties[t.path][o]);n?Ee(n,t):i.push(t)}}},[`${d}nodeKind`]:(s,e)=>{s.nodeKind=e},[`${d}targetClass`]:(s,e)=>{s.targetClass=e},[`${d}or`]:(s,e)=>{s.or=s.config.lists[e.value]},[`${d}xone`]:(s,e)=>{s.xone=s.config.lists[e.value]},[te.id]:(s,e)=>{s.owlImports.add(e)}};class M{constructor(e,t,i){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.id=e,this.config=t,this.parent=i,t.registerNodeTemplate(this),ot(this,this.config.store.getQuads(e,null,null,null))}}function ot(s,e){for(const t of e)it[t.predicate.id]?.call(s,s,t.object);return s}function at(s){for(const e of Object.values(s.properties))for(const t of e){const[i,n]=X(s,t.path);if(i.length>1&&n){const o=i[i.length-1];for(let a=i.length-2;a>=0;a--){const r=i[a];delete r.parent.properties[r.path],Ee(o,r)}}}}function X(s,e,t=new Set,i=[],n=!1){if(!t.has(s.id.value)){t.add(s.id.value);const o=s.properties[e];if(o?.length===1){i.push(o[0]),n=n||o[0].maxCount===1;for(const a of o[0].nodeShapes){const[r,l]=X(a,e,t,i,n);n=n||l}}for(const a of s.extendedShapes){const[r,l]=X(a,e,t,i,n);n=n||l}}return[i,n]}class U{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.view=null,this.language=null,this.loading="Loading…",this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=k.value,this.showNodeIds=null,this.dense="true"}}const rt="#4c93d785, #f85e9a85, #00327385, #87001f85";class fe{constructor(e){this.attributes=new U,this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new J,this._nodeTemplates={},this._propertyTemplates={},this.validator=new re(this._store,{details:!0,factory:u}),this.form=e,this._theme=new nt,this.languages=[...new Set(navigator.languages.flatMap(t=>t.length>2?[t.toLocaleLowerCase(),t.substring(0,2)]:t)),""]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){const t=new U;if(Object.keys(t).forEach(i=>{const n=e.dataset[i];n!==void 0&&(t[i]=n)}),this.editMode=t.view===null,this.theme.setDense(t.dense==="true"),this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){const i=this.languages.indexOf(t.language);i>-1&&this.languages.splice(i,1),this.languages.unshift(t.language)}if(t.valuesGraph&&(this.valuesGraphId=u.namedNode(t.valuesGraph)),t.hierarchyColors!=null){const i=t.hierarchyColors.length?t.hierarchyColors:rt;let n=`:host { --hierarchy-colors: ${i}; --hierarchy-colors-length: ${i.split(",").length}; --hierarchy-color-width: 3px }`;for(let o=8;o>=0;o--){let a=`shacl-property { --hierarchy-level: ${o} }`;for(let r=0;r<o;r++)a="shacl-property "+a;n=n+`
70
- `+a}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){const e=new U;return Object.keys(e).map(t=>(t=t.replace(/[A-Z]/g,i=>"-"+i.toLowerCase()),"data-"+t))}buildTemplateKey(e,t){let i=e.value;return t&&(t instanceof he?i+="*"+t.id.value:i+="*"+this.buildTemplateKey(t.id,t.parent)),i}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplate(e,t){const i=this.buildTemplateKey(e,t);let n=this._nodeTemplates[i];return n||(n=new M(e,this,t)),n}getPropertyTemplate(e,t){const i=this.buildTemplateKey(e,t);let n=this._propertyTemplates[i];return n||(n=new he(e,t)),n}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}set store(e){this._store=e,this.lists=Me(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(t=>{this.groups.push(t.id)},g,`${d}PropertyGroup`,null),this.validator=new re(e,{details:!0,factory:u})}}const lt=50;class ct extends HTMLElement{constructor(){super(),this.shape=null,this.attachShadow({mode:"open"}),this.form=document.createElement("form"),this.config=new fe(this.form),this.form.addEventListener("change",e=>{e.stopPropagation(),this.config.editMode&&this.validate(!0).then(t=>{this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:t.conforms,report:t}}))}).catch(t=>{console.warn(t)})})}static get observedAttributes(){return fe.dataAttributes()}connectedCallback(){this.shadowRoot.prepend(this.form)}attributeChangedCallback(){this.config.updateAttributes(this),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.setAttribute("loading",""),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await Qe({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,proxy:this.config.attributes.proxy}),this.form.replaceChildren();const e=this.findRootShaclShapeSubject();if(e){this.form.classList.forEach(n=>{this.form.classList.remove(n)}),this.form.classList.toggle("mode-edit",this.config.editMode),this.form.classList.toggle("mode-view",!this.config.editMode),this.config.theme.apply(this.form);const t=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&t.push(this.config.hierarchyColorsStyleSheet);for(const n of Ze())n.stylesheet&&t.push(n.stylesheet);this.shadowRoot.adoptedStyleSheets=t;const i=new M(e,this.config);for(const n of this.config.nodeTemplates)at(n);if(this.shape=new I(i,this.config.attributes.valuesSubject?u.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.editMode){if(this.config.attributes.submitButton!==null){const n=this.config.theme.createButton(this.config.attributes.submitButton||"Submit",!0);n.addEventListener("click",o=>{o.preventDefault(),this.form.reportValidity()&&this.validate().then(a=>{if(a?.conforms)this.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}));else{let r=this.form.querySelector(":scope .invalid > .editor");r?r.focus():this.form.querySelector(":scope .invalid")?.scrollIntoView()}})}),this.form.appendChild(n)}setTimeout(()=>{this.config.attributes.valuesSubject&&this.removeFromDataGraph(u.namedNode(this.config.attributes.valuesSubject)),this.validate(!0)})}}else if(this.config.store.countQuads(null,null,null,T)>0)throw new Error("shacl root node shape not found")}catch(e){console.error(e);const t=document.createElement("div");t.innerText=String(e),this.form.replaceChildren(t)}this.removeAttribute("loading"),this.dispatchEvent(new Event("ready"))},lt)}serialize(e="text/turtle",t=this.toRDF()){const i=t.getQuads(null,null,null,null);return We(i,e,j)}toRDF(e=new J){return this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),e}registerPlugin(e){Ye(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}async validate(e=!1){for(const t of this.form.querySelectorAll(":scope .validation-error"))t.remove();for(const t of this.form.querySelectorAll(":scope .property-instance"))t.classList.remove("invalid"),t.querySelector(":scope > .editor")?.value?t.classList.add("valid"):t.classList.remove("valid");if(this.config.store.deleteGraph(this.config.valuesGraphId||""),!this.shape)return{conforms:!0};this.shape.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{const t=await this.config.validator.validate({dataset:this.config.store,terms:[this.shape.nodeId]},[{terms:[this.shape.template.id]}]);for(const i of t.results)if(i.focusNode?.ptrs?.length)for(const n of i.focusNode.ptrs){const o=n._term;if(i.path?.length){const a=i.path[0].predicates[0];let r=this.form.querySelectorAll(`
70
+ `;class nt extends He{constructor(e){super(e||st),this.idCtr=0}createDefaultTemplate(e,s,i,n,o){if(n.id=`e${this.idCtr++}`,n.classList.add("editor"),o?.datatype?n.shaclDatatype=o.datatype:s instanceof S&&(n.shaclDatatype=s.datatype),o&&o.aggregatedMinCount>0&&(n.dataset.minCount=String(o.aggregatedMinCount)),o?.class&&(n.dataset.class=o.class.value),o?.nodeKind)n.dataset.nodeKind=o.nodeKind.value;else if(s&&(s instanceof $||o?.nodeKind?.equals(ve))&&(n.dataset.nodeKind=d+"IRI",o)){const c=R(o.config.store.getQuads(s,null,null,null),o.config.languages);c&&(n.dataset.value="<"+s.value+">",s=u.literal(c))}(o?.hasValue&&s||o?.readonly)&&(n.disabled=!0),n.value=s?.value||o?.defaultValue?.value||"";const a=document.createElement("label");a.htmlFor=n.id,a.innerText=e,o?.description&&a.setAttribute("title",o.description.value);const r=o?.description?o.description.value:o?.pattern?o.pattern:null;r&&n.setAttribute("placeholder",r),i&&(n.setAttribute("required","true"),a.classList.add("required"));const l=document.createElement("div");return l.appendChild(a),l.appendChild(n),l}createDateEditor(e,s,i,n){const o=new G;n.datatype?.value===E+"dateTime"?(o.type="datetime-local",o.setAttribute("step","1")):o.type="date",o.clearable=!0,o.dense=this.dense,o.classList.add("pr-0");const a=this.createDefaultTemplate(e,null,i,o,n);if(s)try{let r=new Date(s.value).toISOString();n.datatype?.value===E+"dateTime"?r=r.slice(0,19):r=r.slice(0,10),o.value=r}catch(r){console.error(r,s)}return a}createTextEditor(e,s,i,n){let o;return n.singleLine===!1?(o=new Pe,o.resize="auto"):o=new G,o.dense=this.dense,n.pattern&&(o.pattern=n.pattern),n.minLength&&(o.minLength=n.minLength),n.maxLength&&(o.maxLength=n.maxLength),this.createDefaultTemplate(e,s,i,o,n)}createLangStringEditor(e,s,i,n){const o=this.createTextEditor(e,s,i,n),a=o.querySelector(":scope .editor");let r;if(n.languageIn?.length){r=document.createElement("select");for(const l of n.languageIn){const c=document.createElement("option");c.innerText=l.value,r.appendChild(c)}}else r=document.createElement("input"),r.maxLength=5,r.size=5,r.placeholder="lang?";return r.title="Language of the text",r.classList.add("lang-chooser"),r.slot="suffix",r.addEventListener("change",l=>{l.stopPropagation(),a&&(a.dataset.lang=r.value,a.dispatchEvent(new Event("change",{bubbles:!0})))}),s instanceof S&&(r.value=s.language),a.dataset.lang=r.value,a.appendChild(r),o}createBooleanEditor(e,s,i,n){const o=document.createElement("input");o.type="checkbox",o.classList.add("ml-0");const a=this.createDefaultTemplate(e,null,i,o,n);return o.removeAttribute("required"),a.querySelector(":scope label")?.classList.remove("required"),s instanceof S&&(o.checked=s.value==="true"),a}createFileEditor(e,s,i,n){const o=document.createElement("input");return o.type="file",o.addEventListener("change",a=>{if(o.files?.length){a.stopPropagation();const r=new FileReader;r.readAsDataURL(o.files[0]),r.onload=()=>{o.binaryData=btoa(r.result),o.parentElement?.dispatchEvent(new Event("change",{bubbles:!0}))}}else o.binaryData=void 0}),this.createDefaultTemplate(e,s,i,o,n)}createNumberEditor(e,s,i,n){const o=new G;o.type="number",o.clearable=!0,o.dense=this.dense,o.classList.add("pr-0");const a=n.minInclusive!==void 0?n.minInclusive:n.minExclusive!==void 0?n.minExclusive+1:void 0,r=n.maxInclusive!==void 0?n.maxInclusive:n.maxExclusive!==void 0?n.maxExclusive-1:void 0;return a!==void 0&&(o.min=String(a)),r!==void 0&&(o.max=String(r)),n.datatype?.value!==E+"integer"&&(o.step="0.1"),this.createDefaultTemplate(e,s,i,o,n)}createListEditor(e,s,i,n,o){const a=new ge;a.clearable=!0,a.dense=this.dense;const r=this.createDefaultTemplate(e,null,i,a,o),l=document.createElement("ul");let c=!0;const f=(h,v)=>{const p=document.createElement("li");if(typeof h.value=="string"?(p.dataset.value=h.value,p.innerText=h.label?h.label:h.value):(p.dataset.value=h.value.id,h.value instanceof $&&(p.dataset.value="<"+p.dataset.value+">"),p.innerText=h.label?h.label:h.value.value),v.appendChild(p),h.children?.length){c=!1;const w=document.createElement("ul");p.appendChild(w);for(const C of h.children)f(C,w)}};for(const h of n)f(h,l);return c||(a.collapse=!0),a.appendChild(l),s&&(a.value=s.id,s instanceof $&&(a.value="<"+a.value+">")),r}createButton(e,s){const i=document.createElement("rokit-button");return i.innerHTML=e,i}}const it={[`${d}node`]:(t,e)=>{t.extendedShapes.add(new Q(e,t.config,t))},[`${d}and`]:(t,e)=>{for(const s of t.config.lists[e.value])t.extendedShapes.add(new Q(s,t.config,t))},[`${d}property`]:(t,e)=>{const s=t.config.getPropertyTemplate(e,t);if(s.path){let i=t.properties[s.path];if(i||(i=[],t.properties[s.path]=i),s.qualifiedValueShape)i.push(s);else{let n;for(let o=0;o<t.properties[s.path].length&&!n;o++)t.properties[s.path][o].qualifiedValueShape||(n=t.properties[s.path][o]);n?Ce(n,s):i.push(s)}}},[`${d}nodeKind`]:(t,e)=>{t.nodeKind=e},[`${d}targetClass`]:(t,e)=>{t.targetClass=e},[`${d}or`]:(t,e)=>{t.or=t.config.lists[e.value]},[`${d}xone`]:(t,e)=>{t.xone=t.config.lists[e.value]},[se.id]:(t,e)=>{t.owlImports.add(e)},[`${me}title`]:(t,e)=>{const s=e;t.label=F(t.config.languages,t.label,s)},[`${B}label`]:(t,e)=>{const s=e;t.label=F(t.config.languages,t.label,s)}};class Q{constructor(e,s,i){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.id=e,this.config=s,this.parent=i,s.registerNodeTemplate(this),ot(this,this.config.store.getQuads(e,null,null,null))}}function ot(t,e){for(const s of e)it[s.predicate.id]?.call(t,t,s.object);return t}function at(t){for(const e of Object.values(t.properties))for(const s of e){const[i,n]=Y(t,s.path);if(i.length>1&&n){const o=i[i.length-1];for(let a=i.length-2;a>=0;a--){const r=i[a];delete r.parent.properties[r.path],Ce(o,r)}}}}function Y(t,e,s=new Set,i=[],n=!1){if(!s.has(t.id.value)){s.add(t.id.value);const o=t.properties[e];if(o?.length===1){i.push(o[0]),n=n||o[0].maxCount===1;for(const a of o[0].nodeShapes){const[r,l]=Y(a,e,s,i,n);n=n||l}}for(const a of t.extendedShapes){const[r,l]=Y(a,e,s,i,n);n=n||l}}return[i,n]}class K{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.view=null,this.language=null,this.loading="Loading…",this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=k.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense="true"}}const rt="#4c93d785, #f85e9a85, #00327385, #87001f85";class fe{constructor(e){this.attributes=new K,this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new Z,this._nodeTemplates={},this._propertyTemplates={},this.validator=new le(this._store,{details:!0,factory:u}),this.form=e,this._theme=new nt,this.languages=[...new Set(navigator.languages.flatMap(s=>s.length>2?[s.toLocaleLowerCase(),s.substring(0,2)]:s)),""]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){const s=new K;if(Object.keys(s).forEach(i=>{const n=e.dataset[i];n!==void 0&&(s[i]=n)}),this.editMode=s.view===null,this.theme.setDense(s.dense==="true"),this.attributes=s,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),s.language){const i=this.languages.indexOf(s.language);i>-1&&this.languages.splice(i,1),this.languages.unshift(s.language)}if(s.valuesGraph&&(this.valuesGraphId=u.namedNode(s.valuesGraph)),s.hierarchyColors!=null){const i=s.hierarchyColors.length?s.hierarchyColors:rt;let n=`:host { --hierarchy-colors: ${i}; --hierarchy-colors-length: ${i.split(",").length}; --hierarchy-color-width: 3px }`;for(let o=8;o>=0;o--){let a=`shacl-property { --hierarchy-level: ${o} }`;for(let r=0;r<o;r++)a="shacl-property "+a;n=n+`
71
+ `+a}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){const e=new K;return Object.keys(e).map(s=>(s=s.replace(/[A-Z]/g,i=>"-"+i.toLowerCase()),"data-"+s))}buildTemplateKey(e,s){let i=e.value;return s&&(s instanceof he?i+="*"+s.id.value:i+="*"+this.buildTemplateKey(s.id,s.parent)),i}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplate(e,s){const i=this.buildTemplateKey(e,s);let n=this._nodeTemplates[i];return n||(n=new Q(e,this,s)),n}getPropertyTemplate(e,s){const i=this.buildTemplateKey(e,s);let n=this._propertyTemplates[i];return n||(n=new he(e,s)),n}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}set store(e){this._store=e,this.lists=Me(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(s=>{this.groups.push(s.id)},g,`${d}PropertyGroup`,null),this.validator=new le(e,{details:!0,factory:u})}}const lt=50;class ct extends HTMLElement{constructor(){super(),this.shape=null,this.attachShadow({mode:"open"}),this.form=document.createElement("form"),this.config=new fe(this.form),this.form.addEventListener("change",e=>{e.stopPropagation(),this.config.editMode&&this.validate(!0).then(s=>{this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:s.conforms,report:s}}))}).catch(s=>{console.warn(s)})})}static get observedAttributes(){return fe.dataAttributes()}connectedCallback(){this.shadowRoot.prepend(this.form)}attributeChangedCallback(){this.config.updateAttributes(this),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.setAttribute("loading",""),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await Qe({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,proxy:this.config.attributes.proxy}),this.form.replaceChildren();const e=this.findRootShaclShapeSubject();if(e){this.form.classList.forEach(n=>{this.form.classList.remove(n)}),this.form.classList.toggle("mode-edit",this.config.editMode),this.form.classList.toggle("mode-view",!this.config.editMode),this.config.theme.apply(this.form);const s=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&s.push(this.config.hierarchyColorsStyleSheet);for(const n of Ze())n.stylesheet&&s.push(n.stylesheet);this.shadowRoot.adoptedStyleSheets=s;const i=new Q(e,this.config);for(const n of this.config.nodeTemplates)at(n);if(this.shape=new I(i,this.config.attributes.valuesSubject?u.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&i.label){const n=document.createElement("h3");n.innerText=i.label.value,this.form.prepend(n)}if(this.config.editMode){if(this.config.attributes.submitButton!==null){const n=this.config.theme.createButton(this.config.attributes.submitButton||"Submit",!0);n.addEventListener("click",o=>{o.preventDefault(),this.form.reportValidity()&&this.validate().then(a=>{if(a?.conforms)this.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}));else{let r=this.form.querySelector(":scope .invalid > .editor");r?r.focus():this.form.querySelector(":scope .invalid")?.scrollIntoView()}})}),this.form.appendChild(n)}setTimeout(()=>{this.config.attributes.valuesSubject&&this.removeFromDataGraph(u.namedNode(this.config.attributes.valuesSubject)),this.validate(!0)})}}else if(this.config.store.countQuads(null,null,null,T)>0)throw new Error("shacl root node shape not found")}catch(e){console.error(e);const s=document.createElement("div");s.innerText=String(e),this.form.replaceChildren(s)}this.removeAttribute("loading"),this.dispatchEvent(new Event("ready"))},lt)}serialize(e="text/turtle",s=this.toRDF()){const i=s.getQuads(null,null,null,null);return We(i,e,j)}toRDF(e=new Z){return this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),e}registerPlugin(e){Ye(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}async validate(e=!1){for(const s of this.form.querySelectorAll(":scope .validation-error"))s.remove();for(const s of this.form.querySelectorAll(":scope .property-instance"))s.classList.remove("invalid"),s.querySelector(":scope > .editor")?.value?s.classList.add("valid"):s.classList.remove("valid");if(this.config.store.deleteGraph(this.config.valuesGraphId||""),!this.shape)return{conforms:!0};this.shape.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{const s=await this.config.validator.validate({dataset:this.config.store,terms:[this.shape.nodeId]},[{terms:[this.shape.template.id]}]);for(const i of s.results)if(i.focusNode?.ptrs?.length)for(const n of i.focusNode.ptrs){const o=n._term;if(i.path?.length){const a=i.path[0].predicates[0];let r=this.form.querySelectorAll(`
71
72
  :scope shacl-node[data-node-id='${o.id}'] > shacl-property > .property-instance[data-path='${a.id}'] > .editor,
72
73
  :scope shacl-node[data-node-id='${o.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${a.id}'] > .editor,
73
74
  :scope shacl-node[data-node-id='${o.id}'] > .shacl-group > shacl-property > .property-instance[data-path='${a.id}'] > .editor,
74
75
  :scope shacl-node[data-node-id='${o.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[data-path='${a.id}'] > .editor`);r.length===0&&(r=this.form.querySelectorAll(`
75
76
  :scope [data-node-id='${o.id}'] > shacl-property > .property-instance[data-path='${a.id}'],
76
- :scope [data-node-id='${o.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${a.id}']`));for(const l of r)if(l.classList.contains("editor")){if(!e||l.value){let c=l.parentElement;c.classList.add("invalid"),c.classList.remove("valid"),c.appendChild(this.createValidationErrorDisplay(i));do c instanceof Y&&(c.open=!0),c=c.parentElement;while(c)}}else e||(l.classList.add("invalid"),l.classList.remove("valid"),l.appendChild(this.createValidationErrorDisplay(i,"node")))}else e||this.form.querySelector(`:scope [data-node-id='${o.id}']`)?.prepend(this.createValidationErrorDisplay(i,"node"))}return t}catch(t){return console.error(t),!1}}createValidationErrorDisplay(e,t){const i=document.createElement("span");if(i.classList.add("validation-error"),t&&i.classList.add(t),e)if(e.message?.length>0)for(const n of e.message)i.title+=n.value+`
77
- `;else i.title=e.sourceConstraintComponent?.value;return i}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=u.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,g,z,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,b)>0){const t=u.namedNode(this.config.attributes.valuesSubject),i=[...this.config.store.getQuads(t,g,null,b),...this.config.store.getQuads(t,k,null,b)];if(i.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${g.id} nor ${k.id} statement`);else for(const o of i)if(this.config.store.getQuads(o.object,g,z,null).length>0)return o.object;const n=this.config.store.getObjects(t,g,b);for(const o of n)for(const a of this.config.store.getQuads(null,Q,o,null))return a.subject}const e=this.config.store.getQuads(null,g,z,null);if(e.length==0){console.warn("shapes graph does not contain any node shapes");return}return e.length>1&&(console.warn("shapes graph contains",e.length,"node shapes. choosing first found which is",e[0].subject.value),console.info('hint: set the node shape to use with element attribute "data-shape-subject"')),e[0].subject}}removeFromDataGraph(e){this.config.attributes.valuesSubject;for(const t of this.config.store.getQuads(e,null,null,b))this.config.store.delete(t),(t.object.termType==="NamedNode"||t.object.termType==="BlankNode")&&this.removeFromDataGraph(t.object)}}window.customElements.define("shacl-form",ct);export{fe as Config,nt as DefaultTheme,mt as Plugin,ct as ShaclForm,He as Theme,P as findLabel,lt as initTimeout,Qe as loadGraphs,j as prefixes,Ye as registerPlugin};
77
+ :scope [data-node-id='${o.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${a.id}']`));for(const l of r)if(l.classList.contains("editor")){if(!e||l.value){let c=l.parentElement;c.classList.add("invalid"),c.classList.remove("valid"),c.appendChild(this.createValidationErrorDisplay(i));do c instanceof ee&&(c.open=!0),c=c.parentElement;while(c)}}else e||(l.classList.add("invalid"),l.classList.remove("valid"),l.appendChild(this.createValidationErrorDisplay(i,"node")))}else e||this.form.querySelector(`:scope [data-node-id='${o.id}']`)?.prepend(this.createValidationErrorDisplay(i,"node"))}return s}catch(s){return console.error(s),!1}}createValidationErrorDisplay(e,s){const i=document.createElement("span");if(i.classList.add("validation-error"),s&&i.classList.add(s),e)if(e.message?.length>0)for(const n of e.message)i.title+=n.value+`
78
+ `;else i.title=e.sourceConstraintComponent?.value;return i}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=u.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,g,U,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,b)>0){const s=u.namedNode(this.config.attributes.valuesSubject),i=[...this.config.store.getQuads(s,g,null,b),...this.config.store.getQuads(s,k,null,b)];if(i.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${g.id} nor ${k.id} statement`);else for(const o of i)if(this.config.store.getQuads(o.object,g,U,null).length>0)return o.object;const n=this.config.store.getObjects(s,g,b);for(const o of n)for(const a of this.config.store.getQuads(null,z,o,null))return a.subject}const e=this.config.store.getQuads(null,g,U,null);if(e.length==0){console.warn("shapes graph does not contain any node shapes");return}return e.length>1&&(console.warn("shapes graph contains",e.length,"node shapes. choosing first found which is",e[0].subject.value),console.info('hint: set the node shape to use with element attribute "data-shape-subject"')),e[0].subject}}removeFromDataGraph(e){this.config.attributes.valuesSubject;for(const s of this.config.store.getQuads(e,null,null,b))this.config.store.delete(s),(s.object.termType==="NamedNode"||s.object.termType==="BlankNode")&&this.removeFromDataGraph(s.object)}}window.customElements.define("shacl-form",ct);export{fe as Config,nt as DefaultTheme,mt as Plugin,ct as ShaclForm,He as Theme,H as classesCache,R as findLabel,lt as initTimeout,Qe as loadGraphs,j as prefixes,O as rdfCache,Ye as registerPlugin};
package/dist/loader.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Store, Quad, Prefixes } from 'n3';
2
2
  import { ClassInstanceProvider } from './plugin';
3
+ export declare const rdfCache: Record<string, Promise<Quad[]>>;
4
+ export declare const classesCache: Record<string, Promise<string>>;
3
5
  export declare const prefixes: Prefixes;
4
6
  export interface LoaderAttributes {
5
7
  loadOwlImports: boolean;
@@ -1,9 +1,10 @@
1
- import type { NamedNode, Quad } from 'n3';
1
+ import type { Literal, NamedNode, Quad } from 'n3';
2
2
  import { Term } from '@rdfjs/types';
3
3
  import { Config } from './config';
4
4
  import { ShaclPropertyTemplate } from './property-template';
5
5
  export declare class ShaclNodeTemplate {
6
6
  id: Term;
7
+ label?: Literal | undefined;
7
8
  parent?: ShaclNodeTemplate | ShaclPropertyTemplate;
8
9
  nodeKind?: NamedNode;
9
10
  targetClass?: NamedNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulb-darmstadt/shacl-form",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "SHACL form generator",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",