@ulb-darmstadt/shacl-form 3.0.2 → 3.0.3
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/bundle.js +25 -25
- package/dist/index.js +6 -6
- package/dist/node.d.ts +2 -1
- package/dist/property.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{DataFactory as h,StreamParser as Pe,Store as ee,Literal as T,NamedNode as k,Writer as ke}from"n3";import{RdfXmlParser as De}from"rdfxml-streaming-parser";import $e from"jsonld";import{RokitDialog as Ne,RokitCollapsible as te,RokitButton as me,RokitInput as U,RokitTextArea as qe,RokitSelect as _e}from"@ro-kit/ui-widgets";import{v4 as le}from"uuid";import{Validator as ce}from"shacl-engine";const d="http://www.w3.org/ns/shacl#",de="http://datashapes.org/dash#",E="http://www.w3.org/2001/XMLSchema#",R="http://www.w3.org/1999/02/22-rdf-syntax-ns#",B="http://www.w3.org/2000/01/rdf-schema#",se="http://www.w3.org/2004/02/skos/core#",Oe="http://www.w3.org/2002/07/owl#",Fe="http://www.w3.org/ns/oa#",ne="http://purl.org/dc/terms/",Ve="http://xmlns.com/foaf/0.1/",y=h.namedNode("loaded-shapes"),m=h.namedNode("loaded-data"),b=h.namedNode(R+"type"),ve=h.namedNode(R+"langString"),O=h.namedNode(ne+"conformsTo"),ue=h.namedNode(B+"subClassOf"),ie=h.namedNode(Oe+"imports"),Qe=h.namedNode(se+"broader"),ze=h.namedNode(se+"narrower"),K=h.namedNode(d+"NodeShape"),ye=h.namedNode(d+"IRI"),X=h.namedNode(d+"property"),oe=h.namedNode(d+"class"),Me=h.namedNode(d+"node"),G=h.namedNode(d+"targetClass"),Be=h.namedNode(d+"nodeKind"),Ge=h.namedNode(E+"string"),Ue=h.namedNode(E+"boolean");function A(t,e,s=d,o){let n="";const i=Ke(t,e,s,o);return i&&(n=i.value),n}function Ke(t,e,s=d,o){let n;const i=s+e;if(o?.length){for(const a of o)for(const r of t)if(r.predicate.value===i){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===i)return a.object;return n}function He(t){t.querySelector(".editor")?.focus()}function C(t,e){return A(t,"prefLabel",se,e)||A(t,"label",B,e)||A(t,"title",ne,e)||A(t,"name",Ve,e)}function we(t,e,s){const o=[];for(const n of t)o.push({value:n,label:C(e.getQuads(n,null,null,null),s),children:[]});return o}function J(t,e){for(const s in e){const o=e[s];t.startsWith(o)&&(t=t.slice(o.length))}return t}function Se(t,e,s,o,n=new Set){for(const i of e.owlImports)n.has(i.id)||(n.add(i.id),o.push(...s.getSubjects(b,t,i)));e.parent&&Se(t,e.parent,s,o,n)}function Ee(t,e){if(e.in){const s=e.config.lists[e.in];return we(s?.length?s:[],e.config.store,e.config.languages)}else{const s=e.config.store.getSubjects(b,t,y);s.push(...e.config.store.getSubjects(b,t,m)),Se(t,e,e.config.store,s);const o=new Map,n=new Map;for(const a of s)o.set(a.id,{value:a,label:C(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,Qe,null))o.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,ze,null))o.has(r.id)&&n.set(r.id,a.id);for(const r of e.config.store.getObjects(a,ue,null))o.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())o.get(r)?.children?.push(o.get(a));const i=[];for(const[a,r]of o.entries())n.has(a)||i.push(r);for(const a of e.config.store.getSubjects(ue,t,null))i.push(...Ee(a,e));return i}}function Y(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 o=t.indexOf(e.language);if(o<0)return s;const n=t.indexOf(s.language);return n<0||n>o?e:s}function We(t){const e=new Set;for(const s of t.getObjects(null,oe,y))e.add(s.value);for(const s of t.getObjects(null,G,y))e.add(s.value);return e}function Xe(t,e){return t instanceof Set?[...e].filter(s=>!t.has(s)):[...e].filter(s=>!t.includes(s))}function Je(t,{remove:e=!1,ignoreErrors:s=!1}={}){const o={},n=s?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),i=t.getQuads(null,R+"rest",R+"nil",null),a=e?[...i]:[];return i.forEach(r=>{const l=[];let c=!1,f,u;const g=r.graph;let p=r.subject;for(;p&&!c;){const x=t.getQuads(null,null,p,null),L=t.getQuads(p,null,null,null).filter(w=>!w.predicate.equals(b));let v,$=null,re=null,N=null;for(let w=0;w<L.length&&!c;w++)v=L[w],v.graph.equals(g)?f?c=n(p,"has non-list arcs out"):v.predicate.value===R+"first"?$?c=n(p,"has multiple rdf:first arcs"):a.push($=v):v.predicate.value===R+"rest"?re?c=n(p,"has multiple rdf:rest arcs"):a.push(re=v):x.length?c=n(p,"can't be subject and object"):(f=v,u="subject"):c=n(p,"not confined to single graph");for(let w=0;w<x.length&&!c;++w)v=x[w],f?c=n(p,"can't have coreferences"):v.predicate.value===R+"rest"?N?c=n(p,"has incoming rdf:rest arcs"):N=v:(f=v,u="object");$?l.unshift($.object):c=n(p,"has no list head"),p=N&&N.subject}c?e=!1:f&&(o[f[u].value]=l)}),e&&t.removeQuads(a),o}const q={},P={};async function Ye(t){const e={store:new ee,importedUrls:[],atts:t},s=[];if(t.shapes?s.push(S(j(t.shapes),e,y)):t.shapesUrl&&s.push(S(_(t.shapesUrl,e.atts.proxy),e,y)),t.values?s.push(S(j(t.values),e,m)):t.valuesUrl&&s.push(S(_(t.valuesUrl,e.atts.proxy),e,m)),await Promise.all(s),t.classInstanceProvider)try{const o=We(e.store),n=await t.classInstanceProvider(o);n&&await S(j(n),e,y)}catch(o){console.error("failed loading class instances",o)}if(t.valuesSubject&&e.store.countQuads(null,null,null,y)===0){const o=[...e.store.getObjects(t.valuesSubject,b,m),...e.store.getObjects(t.valuesSubject,O,m)],n=[];for(const i of o){let a=xe(i.value);!a&&i.value.startsWith("urn:")&&e.atts.proxy&&(a=i.value),a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(S(_(a,e.atts.proxy),e,y)))}try{await Promise.allSettled(n)}catch(i){console.warn(i)}}return e.store}async function S(t,e,s){const o=await t,n=[];for(const i of o){let a=s;if(e.atts.valuesSubject&&m.equals(s)&&i.graph.id&&i.graph.id!==e.atts.valuesSubject&&(a=i.graph),e.store.add(h.quad(i.subject,i.predicate,i.object,a)),e.atts.loadOwlImports&&ie.equals(i.predicate)){const r=xe(i.object.value);r&&e.importedUrls.indexOf(r)<0&&(e.importedUrls.push(r),n.push(S(_(r,e.atts.proxy),e,h.namedNode(r))))}}await Promise.allSettled(n)}async function _(t,e){return t in q||(q[t]=(async()=>{let s=t;e&&(s=e+encodeURIComponent(t));const o=await fetch(s,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}});if(o.ok){const n=await o.text();return j(n)}else return console.warn("failed fetching RDF from",t),[]})()),q[t]}async function j(t){if(!t.trim())return[];const e=Ze(t);if(e==="json")try{t=await $e.toRDF(JSON.parse(t),{format:"application/n-quads"})}catch(o){console.error(o)}const s=[];return await new Promise((o,n)=>{const i=e==="xml"?new De:new Pe;i.on("data",a=>{s.push(h.quad(a.subject,a.predicate,a.object,a.graph))}).on("error",a=>{n(a)}).on("prefix",(a,r)=>{a&&(P[a]=r)}).on("end",()=>{o(null)}),i.write(t),i.end()}),s}function xe(t){if(Y(t))return t;const e=t.split(":");if(e.length===2){const s=P[e[0]];if(s&&(t=t.replace(`${e[0]}:`,s),Y(t)))return t}return null}function Ze(t){return/^\s*[\\[{]/.test(t)?"json":/^\s*<\?xml/.test(t)?"xml":"ttl"}const et={[`${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)},[`${de}singleLine`]:(t,e)=>{t.singleLine=e.value==="true"},[`${de}readonly`]:(t,e)=>{t.readonly=e.value==="true"},[`${Fe}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=ve},[`${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 o of s)t.nodeShapes.add(t.config.getNodeTemplate(o,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)},[ie.id]:(t,e)=>{t.owlImports.add(e)},[oe.id]:(t,e)=>{t.class=e;const s=t.config.store.getSubjects(G,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),ae(this,this.config.store.getQuads(e,null,null,null))}}function V(t){return Math.max(t.minCount??0,t.qualifiedMinCount??0)}function tt(t){return Math.min(t.maxCount??Number.MAX_SAFE_INTEGER,t.qualifiedMaxCount??Number.MAX_SAFE_INTEGER)}function Ce(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 ae(t,e){for(const s of e)et[s.predicate.id]?.call(t,t,s.object);return t.label=t.name?.value||C(e,t.config.languages),t.label||(t.label=t.path?J(t.path,P):"unknown"),t}function Le(t,e){const s=e,o=t;for(const n in e)if(n!=="parent"&&n!=="config"&&n!=="id"){const i=s[n];if(i!==void 0&&i!=="")if(Array.isArray(i)){const a=o[n];Array.isArray(a)?a.push(...i):o[n]=[...i]}else if(i instanceof Set&&i.size){const a=o[n];o[n]=new Set([...a instanceof Set?a:[],...i])}else o[n]=i}}function Re(t,e,s){const o=document.createElement("div");o.classList.add("shacl-or-constraint"),o.setAttribute("part","constraint");const n=[];if(e instanceof I){const i=[];let a=!1;t.length&&(a=s.store.countQuads(t[0],X,null,null)>0);for(let c=0;c<t.length;c++)if(a){const f=s.store.getObjects(t[c],X,null),u=[];let g="";for(const p of f){const x=s.getPropertyTemplate(p,e.template),L=new Q(x,e);u.push(L),g+=(g.length>1?" / ":"")+L.template.label}i.push(u),n.push({label:g,value:c.toString()})}else{const f=t[c],u=s.getPropertyTemplate(f,e.template),g=new Q(u,e);i.push([g]),n.push({label:g.template.label,value:c.toString()})}const r=s.theme.createListEditor("Please choose",null,!1,n);r.setAttribute("part","constraint-editor");const l=r.querySelector(".editor");l.onchange=()=>{if(l.value){const c=i[parseInt(l.value)];let f;c.length&&(f=c[0],o.replaceWith(c[0]));for(let u=1;u<c.length;u++)f.after(c[u]),f=c[u]}},o.appendChild(r)}else{const i=[];for(let l=0;l<t.length;l++){const c=s.store.getQuads(t[l],null,null,null);if(c.length){i.push(c);let f=C(c,s.languages);for(const u of c)u.predicate.equals(Me)&&(f=C(s.store.getQuads(u.object,null,null,null),s.languages));n.push({label:f||J(c[0].predicate.value,P)+" = "+J(c[0].object.value,P),value:l.toString()})}}const a=s.theme.createListEditor(e.template.label+"?",null,!1,n,e.template);a.setAttribute("part","constraint-editor");const r=a.querySelector(".editor");r.onchange=async()=>{if(r.value){const l=ae(Ce(e.template),i[parseInt(r.value)]),c=await z(l,void 0,!0),f=c.querySelector(":scope > label");f&&f.classList.add("persistent"),o.replaceWith(c)}},o.appendChild(a)}return o}function st(t,e,s){if(e.termType==="Literal"){const o=e.datatype;for(const n of t){const i=s.store.getQuads(n,null,null,null);for(const a of i)if(a.predicate.value===`${d}datatype`&&a.object.equals(o))return i}}else{const o=s.store.getObjects(e,b,null);for(const n of t){const i=s.store.getQuads(n,null,null,null);for(const a of i)if(o.length>0){if(a.predicate.value===`${d}node`){for(const r of o)if(s.store.getQuads(a.object,G,r,null).length>0)return i}if(a.predicate.equals(oe)){for(const r of o)if(a.object.equals(r))return i}}else if(a.predicate.equals(Be)&&a.object.equals(ye))return i}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function nt(t,e,s){for(const o of t){let n=!1;const i=s.store.getObjects(o,X,null);for(const a of i){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 i}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const it=`:host {
|
|
1
|
+
import{DataFactory as h,StreamParser as Pe,Store as ee,Literal as R,NamedNode as k,Writer as ke}from"n3";import{RdfXmlParser as De}from"rdfxml-streaming-parser";import $e from"jsonld";import{RokitDialog as Ne,RokitCollapsible as te,RokitButton as me,RokitInput as U,RokitTextArea as qe,RokitSelect as _e}from"@ro-kit/ui-widgets";import{v4 as le}from"uuid";import{Validator as ce}from"shacl-engine";const u="http://www.w3.org/ns/shacl#",de="http://datashapes.org/dash#",x="http://www.w3.org/2001/XMLSchema#",I="http://www.w3.org/1999/02/22-rdf-syntax-ns#",B="http://www.w3.org/2000/01/rdf-schema#",se="http://www.w3.org/2004/02/skos/core#",Oe="http://www.w3.org/2002/07/owl#",Fe="http://www.w3.org/ns/oa#",ne="http://purl.org/dc/terms/",Ve="http://xmlns.com/foaf/0.1/",y=h.namedNode("loaded-shapes"),m=h.namedNode("loaded-data"),b=h.namedNode(I+"type"),ve=h.namedNode(I+"langString"),O=h.namedNode(ne+"conformsTo"),ue=h.namedNode(B+"subClassOf"),ie=h.namedNode(Oe+"imports"),Qe=h.namedNode(se+"broader"),ze=h.namedNode(se+"narrower"),K=h.namedNode(u+"NodeShape"),ye=h.namedNode(u+"IRI"),X=h.namedNode(u+"property"),oe=h.namedNode(u+"class"),Me=h.namedNode(u+"node"),G=h.namedNode(u+"targetClass"),Be=h.namedNode(u+"nodeKind"),Ge=h.namedNode(x+"string"),Ue=h.namedNode(x+"boolean");function A(t,e,s=u,o){let n="";const i=Ke(t,e,s,o);return i&&(n=i.value),n}function Ke(t,e,s=u,o){let n;const i=s+e;if(o?.length){for(const a of o)for(const r of t)if(r.predicate.value===i){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===i)return a.object;return n}function He(t){t.querySelector(".editor")?.focus()}function C(t,e){return A(t,"prefLabel",se,e)||A(t,"label",B,e)||A(t,"title",ne,e)||A(t,"name",Ve,e)}function we(t,e,s){const o=[];for(const n of t)o.push({value:n,label:C(e.getQuads(n,null,null,null),s),children:[]});return o}function J(t,e){for(const s in e){const o=e[s];t.startsWith(o)&&(t=t.slice(o.length))}return t}function Se(t,e,s,o,n=new Set){for(const i of e.owlImports)n.has(i.id)||(n.add(i.id),o.push(...s.getSubjects(b,t,i)));e.parent&&Se(t,e.parent,s,o,n)}function Ee(t,e){if(e.in){const s=e.config.lists[e.in];return we(s?.length?s:[],e.config.store,e.config.languages)}else{const s=e.config.store.getSubjects(b,t,y);s.push(...e.config.store.getSubjects(b,t,m)),Se(t,e,e.config.store,s);const o=new Map,n=new Map;for(const a of s)o.set(a.id,{value:a,label:C(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,Qe,null))o.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,ze,null))o.has(r.id)&&n.set(r.id,a.id);for(const r of e.config.store.getObjects(a,ue,null))o.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())o.get(r)?.children?.push(o.get(a));const i=[];for(const[a,r]of o.entries())n.has(a)||i.push(r);for(const a of e.config.store.getSubjects(ue,t,null))i.push(...Ee(a,e));return i}}function Y(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 o=t.indexOf(e.language);if(o<0)return s;const n=t.indexOf(s.language);return n<0||n>o?e:s}function We(t){const e=new Set;for(const s of t.getObjects(null,oe,y))e.add(s.value);for(const s of t.getObjects(null,G,y))e.add(s.value);return e}function Xe(t,e){return t instanceof Set?[...e].filter(s=>!t.has(s)):[...e].filter(s=>!t.includes(s))}function Je(t,{remove:e=!1,ignoreErrors:s=!1}={}){const o={},n=s?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),i=t.getQuads(null,I+"rest",I+"nil",null),a=e?[...i]:[];return i.forEach(r=>{const l=[];let c=!1,f,d;const p=r.graph;let g=r.subject;for(;g&&!c;){const w=t.getQuads(null,null,g,null),L=t.getQuads(g,null,null,null).filter(S=>!S.predicate.equals(b));let v,$=null,re=null,N=null;for(let S=0;S<L.length&&!c;S++)v=L[S],v.graph.equals(p)?f?c=n(g,"has non-list arcs out"):v.predicate.value===I+"first"?$?c=n(g,"has multiple rdf:first arcs"):a.push($=v):v.predicate.value===I+"rest"?re?c=n(g,"has multiple rdf:rest arcs"):a.push(re=v):w.length?c=n(g,"can't be subject and object"):(f=v,d="subject"):c=n(g,"not confined to single graph");for(let S=0;S<w.length&&!c;++S)v=w[S],f?c=n(g,"can't have coreferences"):v.predicate.value===I+"rest"?N?c=n(g,"has incoming rdf:rest arcs"):N=v:(f=v,d="object");$?l.unshift($.object):c=n(g,"has no list head"),g=N&&N.subject}c?e=!1:f&&(o[f[d].value]=l)}),e&&t.removeQuads(a),o}const q={},P={};async function Ye(t){const e={store:new ee,importedUrls:[],atts:t},s=[];if(t.shapes?s.push(E(j(t.shapes),e,y)):t.shapesUrl&&s.push(E(_(t.shapesUrl,e.atts.proxy),e,y)),t.values?s.push(E(j(t.values),e,m)):t.valuesUrl&&s.push(E(_(t.valuesUrl,e.atts.proxy),e,m)),await Promise.all(s),t.classInstanceProvider)try{const o=We(e.store),n=await t.classInstanceProvider(o);n&&await E(j(n),e,y)}catch(o){console.error("failed loading class instances",o)}if(t.valuesSubject&&e.store.countQuads(null,null,null,y)===0){const o=[...e.store.getObjects(t.valuesSubject,b,m),...e.store.getObjects(t.valuesSubject,O,m)],n=[];for(const i of o){let a=xe(i.value);!a&&i.value.startsWith("urn:")&&e.atts.proxy&&(a=i.value),a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(E(_(a,e.atts.proxy),e,y)))}try{await Promise.allSettled(n)}catch(i){console.warn(i)}}return e.store}async function E(t,e,s){const o=await t,n=[];for(const i of o){let a=s;if(e.atts.valuesSubject&&m.equals(s)&&i.graph.id&&i.graph.id!==e.atts.valuesSubject&&(a=i.graph),e.store.add(h.quad(i.subject,i.predicate,i.object,a)),e.atts.loadOwlImports&&ie.equals(i.predicate)){const r=xe(i.object.value);r&&e.importedUrls.indexOf(r)<0&&(e.importedUrls.push(r),n.push(E(_(r,e.atts.proxy),e,h.namedNode(r))))}}await Promise.allSettled(n)}async function _(t,e){return t in q||(q[t]=(async()=>{let s=t;e&&(s=e+encodeURIComponent(t));const o=await fetch(s,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}});if(o.ok){const n=await o.text();return j(n)}else return console.warn("failed fetching RDF from",t),[]})()),q[t]}async function j(t){if(!t.trim())return[];const e=Ze(t);if(e==="json")try{t=await $e.toRDF(JSON.parse(t),{format:"application/n-quads"})}catch(o){console.error(o)}const s=[];return await new Promise((o,n)=>{const i=e==="xml"?new De:new Pe;i.on("data",a=>{s.push(h.quad(a.subject,a.predicate,a.object,a.graph))}).on("error",a=>{n(a)}).on("prefix",(a,r)=>{a&&(P[a]=r)}).on("end",()=>{o(null)}),i.write(t),i.end()}),s}function xe(t){if(Y(t))return t;const e=t.split(":");if(e.length===2){const s=P[e[0]];if(s&&(t=t.replace(`${e[0]}:`,s),Y(t)))return t}return null}function Ze(t){return/^\s*[\\[{]/.test(t)?"json":/^\s*<\?xml/.test(t)?"xml":"ttl"}const et={[`${u}name`]:(t,e)=>{const s=e;t.name=F(t.config.languages,t.name,s)},[`${u}description`]:(t,e)=>{const s=e;t.description=F(t.config.languages,t.description,s)},[`${u}path`]:(t,e)=>{t.path=e.value},[`${u}group`]:(t,e)=>{t.group=e.id},[`${u}datatype`]:(t,e)=>{t.datatype=e},[`${u}nodeKind`]:(t,e)=>{t.nodeKind=e},[`${u}minCount`]:(t,e)=>{t.minCount=parseInt(e.value)},[`${u}maxCount`]:(t,e)=>{t.maxCount=parseInt(e.value)},[`${u}minLength`]:(t,e)=>{t.minLength=parseInt(e.value)},[`${u}maxLength`]:(t,e)=>{t.maxLength=parseInt(e.value)},[`${u}minInclusive`]:(t,e)=>{t.minInclusive=parseInt(e.value)},[`${u}maxInclusive`]:(t,e)=>{t.maxInclusive=parseInt(e.value)},[`${u}minExclusive`]:(t,e)=>{t.minExclusive=parseInt(e.value)},[`${u}maxExclusive`]:(t,e)=>{t.maxExclusive=parseInt(e.value)},[`${u}pattern`]:(t,e)=>{t.pattern=e.value},[`${u}order`]:(t,e)=>{t.order=parseInt(e.value)},[`${de}singleLine`]:(t,e)=>{t.singleLine=e.value==="true"},[`${de}readonly`]:(t,e)=>{t.readonly=e.value==="true"},[`${Fe}styleClass`]:(t,e)=>{t.cssClass=e.value},[`${u}in`]:(t,e)=>{t.in=e.value},[`${u}languageIn`]:(t,e)=>{t.languageIn=t.config.lists[e.value],t.datatype=ve},[`${u}defaultValue`]:(t,e)=>{t.defaultValue=e},[`${u}hasValue`]:(t,e)=>{t.hasValue=e},[`${u}node`]:(t,e)=>{t.node=e,t.nodeShapes.add(t.config.getNodeTemplate(e,t))},[`${u}and`]:(t,e)=>{t.and=e.value;const s=t.config.lists[t.and];if(s?.length)for(const o of s)t.nodeShapes.add(t.config.getNodeTemplate(o,t))},[`${u}qualifiedValueShape`]:(t,e)=>{const s=t.config.getNodeTemplate(e,t);t.qualifiedValueShape=s,t.nodeShapes.add(s)},[`${u}qualifiedMinCount`]:(t,e)=>{t.qualifiedMinCount=parseInt(e.value)},[`${u}qualifiedMaxCount`]:(t,e)=>{t.qualifiedMaxCount=parseInt(e.value)},[ie.id]:(t,e)=>{t.owlImports.add(e)},[oe.id]:(t,e)=>{t.class=e;const s=t.config.store.getSubjects(G,e,null);s.length>0&&(t.node=s[0])},[`${u}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)},[`${u}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),ae(this,this.config.store.getQuads(e,null,null,null))}}function V(t){return Math.max(t.minCount??0,t.qualifiedMinCount??0)}function tt(t){return Math.min(t.maxCount??Number.MAX_SAFE_INTEGER,t.qualifiedMaxCount??Number.MAX_SAFE_INTEGER)}function Ce(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 ae(t,e){for(const s of e)et[s.predicate.id]?.call(t,t,s.object);return t.label=t.name?.value||C(e,t.config.languages),t.label||(t.label=t.path?J(t.path,P):"unknown"),t}function Le(t,e){const s=e,o=t;for(const n in e)if(n!=="parent"&&n!=="config"&&n!=="id"){const i=s[n];if(i!==void 0&&i!=="")if(Array.isArray(i)){const a=o[n];Array.isArray(a)?a.push(...i):o[n]=[...i]}else if(i instanceof Set&&i.size){const a=o[n];o[n]=new Set([...a instanceof Set?a:[],...i])}else o[n]=i}}function Ie(t,e,s){const o=document.createElement("div");o.classList.add("shacl-or-constraint"),o.setAttribute("part","constraint");const n=[];if(e instanceof T){const i=[];let a=!1;t.length&&(a=s.store.countQuads(t[0],X,null,null)>0);for(let c=0;c<t.length;c++)if(a){const f=s.store.getObjects(t[c],X,null),d=[];let p="";for(const g of f){const w=s.getPropertyTemplate(g,e.template),L=new Q(w,e);d.push(L),p+=(p.length>0?" / ":"")+L.template.label}i.push(d),n.push({label:p,value:c.toString()})}else{const f=t[c],d=s.getPropertyTemplate(f,e.template),p=new Q(d,e);i.push([p]),n.push({label:p.template.label,value:c.toString()})}const r=s.theme.createListEditor("Please choose",null,!1,n);r.setAttribute("part","constraint-editor");const l=r.querySelector(".editor");l.onchange=()=>{if(l.value){const c=i[parseInt(l.value)];let f;c.length&&(f=c[0],o.replaceWith(c[0]),f.updateControls());for(let d=1;d<c.length;d++)f.after(c[d]),f=c[d],f.updateControls()}},o.appendChild(r)}else{const i=[];for(let l=0;l<t.length;l++){const c=s.store.getQuads(t[l],null,null,null);if(c.length){i.push(c);let f=C(c,s.languages);for(const d of c)d.predicate.equals(Me)&&(f=C(s.store.getQuads(d.object,null,null,null),s.languages));n.push({label:f||J(c[0].predicate.value,P)+" = "+J(c[0].object.value,P),value:l.toString()})}}const a=s.theme.createListEditor(e.template.label+"?",null,!1,n,e.template);a.setAttribute("part","constraint-editor");const r=a.querySelector(".editor");r.onchange=async()=>{if(r.value){const l=ae(Ce(e.template),i[parseInt(r.value)]),c=await z(l,void 0,!0),f=c.querySelector(":scope > label");f&&f.classList.add("persistent"),o.replaceWith(c)}},o.appendChild(a)}return o}function st(t,e,s){if(e.termType==="Literal"){const o=e.datatype;for(const n of t){const i=s.store.getQuads(n,null,null,null);for(const a of i)if(a.predicate.value===`${u}datatype`&&a.object.equals(o))return i}}else{const o=s.store.getObjects(e,b,null);for(const n of t){const i=s.store.getQuads(n,null,null,null);for(const a of i)if(o.length>0){if(a.predicate.value===`${u}node`){for(const r of o)if(s.store.getQuads(a.object,G,r,null).length>0)return i}if(a.predicate.equals(oe)){for(const r of o)if(a.object.equals(r))return i}}else if(a.predicate.equals(Be)&&a.object.equals(ye))return i}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function nt(t,e,s){for(const o of t){let n=!1;const i=s.store.getObjects(o,X,null);for(const a of i){const r=s.store.getObjects(a,`${u}path`,null);for(const l of r)if(n=s.store.countQuads(e,l,null,null)>0,n)break}if(n)return i}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const it=`:host {
|
|
2
2
|
--shacl-font-family: inherit;
|
|
3
3
|
--shacl-font-size: 14px;
|
|
4
4
|
--shacl-text-color: #333;
|
|
@@ -80,13 +80,13 @@ h3 { margin-top: 0; }
|
|
|
80
80
|
.link-option:hover { background-color: #F5F5F5; cursor: pointer; }
|
|
81
81
|
rokit-dialog.link-chooser::part(dialog) { min-height: min(434px, 90vh); width: min(90vw, 600px); }
|
|
82
82
|
`;class ot{constructor(e){this.dense=!0;let s=it;e&&(s+=`
|
|
83
|
-
`+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(s)}apply(e){}setDense(e){this.dense=e}createViewer(e,s,o){const n=document.createElement("div"),i=document.createElement("label");i.innerHTML=e+":",o.description&&i.setAttribute("title",o.description.value),n.appendChild(i);let a=s.value,r=null;if(s instanceof k){const c=o.config.store.getQuads(a,null,null,null);if(c.length){const f=C(c,o.config.languages);f&&(a=f)}}else s instanceof T&&(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 Y(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 at(t,e,s){if(s){const o=V(t)>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,e,o,Ee(t.class,t),t);if(t.in){const n=t.config.lists[t.in];if(n?.length){const i=we(n,t.config.store,t.config.languages);return t.config.theme.createListEditor(t.label,e,o,i,t)}else console.error("list not found:",t.in,"existing lists:",t.config.lists)}if(t.datatype?.equals(ve)||t.languageIn?.length||t.datatype===void 0&&e instanceof T&&e.language)return t.config.theme.createLangStringEditor(t.label,e,o,t);switch(t.datatype?.value.replace(E,"")){case"integer":case"float":case"double":case"decimal":return t.config.theme.createNumberEditor(t.label,e,o,t);case"date":case"dateTime":return t.config.theme.createDateEditor(t.label,e,o,t);case"boolean":return t.config.theme.createBooleanEditor(t.label,e,o,t);case"base64Binary":return t.config.theme.createFileEditor(t.label,e,o,t)}return t.config.theme.createTextEditor(t.label,e,o,t)}else return e?t.config.theme.createViewer(t.label,e,t):document.createElement("div")}function rt(t,e,s){if(e==="application/ld+json")return lt(t);{const o=new ke({format:e,prefixes:s});o.addQuads(t);let n="";return o.end((i,a)=>{i&&console.error(i),n=a}),n}}function lt(t){const e=[];for(const s of t){const o={"@id":s.subject.id};if(s.predicate===b)o["@type"]=s.object.id;else{let n=s.object.value;s.object instanceof T?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},o[s.predicate.value]=n}e.push(o)}return JSON.stringify(e)}function fe(t){let e=t.shaclDatatype,s=t.dataset.value||t.value;if(t.type==="checkbox"||t.getAttribute("type")==="checkbox"){if(t.checked||parseInt(t.dataset.minCount||"0")>0)return h.literal(t.checked?"true":"false",e)}else if(s){if(s.startsWith("<")&&s.endsWith(">")&&s.indexOf(":")>-1)return h.namedNode(s.substring(1,s.length-1));if(t.dataset.class||t.dataset.nodeKind===d+"IRI")return h.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 k&&Ge.equals(e))&&typeof s=="string"){let o=s.split("^^");o.length===2&&o[0].startsWith('"')&&o[0].endsWith('"')&&o[1].split(":").length===2?(s=o[0].substring(1,o[0].length-1),e=h.namedNode(o[1])):(o=s.split("@"),o.length===2&&o[0].startsWith('"')&&o[0].endsWith('"')?(s=o[0].substring(1,o[0].length-1),e=o[1]):s.startsWith('"')&&s.endsWith('"')&&(s=s.substring(1,s.length-1)))}return h.literal(s,e)}}const D={};function ct(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 dt(){return Object.entries(D).map(t=>t[1])}function ut(t,e){let s=D[`${t}^${e}`];return s||(s=D[`${t}^undefined`],s)?s:D[`undefined^${e}`]}class kt{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)}}async function ht(t){if(t.template.nodeShapes.size===0)return;const e=t.template.config.resourceLinkProvider;if((!e||e&&!e.lazyLoad)&&(await ge(t.template),pe(t).length===0))return;const s=t.template.config.theme.createButton(t.template.label,!1);s.title="Link existing "+t.template.label,s.classList.add("link-button"),s.setAttribute("text","");const o=s.getAttribute("part");return s.setAttribute("part",`${o?o+" ":""}link-button`),s.addEventListener("click",async()=>{e?.lazyLoad&&(s.classList.add("loading"),await ge(t.template),s.classList.remove("loading"));const n=pe(t);if(n.length===0)s.innerText="No linkable resources found",s.setAttribute("disabled",""),setTimeout(()=>s.remove(),2e3);else{let i=t.template.config.form.querySelector("#dialog");i||(i=new Ne,i.classList.add("link-chooser"),i.closable=!0,t.template.config.form.appendChild(i)),i.title="Link existing "+t.template.label,ft(i,t,n),i.open=!0}}),s}function ft(t,e,s){const o=document.createElement("div");for(const n of s){const i=document.createElement("div");i.classList.add("link-option"),i.title="Link this resource",i.innerText=n.label||n.value,i.addEventListener("click",()=>{pt(n.value,e),t.open=!1}),o.appendChild(i)}t.replaceChildren(o)}function pe(t){const e=[];if(t.template.config.resourceLinkProvider){for(const s of t.template.nodeShapes)if(t.template.config.providedConformingResourceIds[s.id.value])for(const o of t.template.config.providedConformingResourceIds[s.id.value])t.querySelector(`:scope > .property-instance > shacl-node[data-node-id='${o}'], :scope > .collapsible > .property-instance > shacl-node[data-node-id='${o}']`)===null&&e.push({value:o,label:C(t.template.config.store.getQuads(h.namedNode(o),null,null,null),t.template.config.languages),children:[]})}return e}async function pt(t,e){const s=h.namedNode(t);if(Ie(s,e.template.config.store)){if(e.template.config.providedResources[t]?.length>0){const n={store:e.template.config.store,importedUrls:[],atts:{loadOwlImports:!1}};await S(j(e.template.config.providedResources[t]),n,y),e.template.config.providedResources[t]=""}const o=await z(e.template,s,!0,!0);e.container.insertBefore(o,e.querySelector(":scope > .add-button-wrapper")),await e.updateControls()}}async function ge(t){const e=t.config.resourceLinkProvider;if(!e)return;const s=new Set(Array.from(t.nodeShapes).map(n=>n.id.value));if(s.size===0)return;const o=Xe(Object.keys(t.config.providedConformingResourceIds),s);if(o.length!==0)try{const n=await e.listConformingResources(o,t);if(n){for(const i of Object.keys(n)){const a=new Set(n[i]);t.config.providedConformingResourceIds[i]=a,await Te(a,!1,t.config)}for(const i of o)t.config.providedConformingResourceIds[i]||(t.config.providedConformingResourceIds[i]=new Set)}}catch(n){console.error("failed loading conforming resources",n)}}async function Te(t,e,s){if(s.resourceLinkProvider&&t.size>0){const o=[];for(const n of t)s.providedResources[n]||o.push(n);if(o.length===0)return[];try{const n=await s.resourceLinkProvider.loadResources(o);if(n){const i={store:s.store,importedUrls:[],atts:{loadOwlImports:!1}};for(const a of n)s.providedResources[a.resourceId]=a.resourceRDF,e&&await S(j(a.resourceRDF),i,y);return n}for(const i of o)s.providedResources[i]||(s.providedResources[i]="")}catch(n){console.error("failed loading resources",n)}}return[]}async function gt(t){const e=new Set;for(const s of t.store.getQuads(null,null,null,m))Ie(s.object,t.store)&&e.add(s.object.value);await Te(e,!0,t)}function Ie(t,e){return t.termType==="NamedNode"&&e.countQuads(t,null,null,null)===0}const H=":scope > .add-button-wrapper, :scope > .collapsible > .add-button-wrapper",bt=":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance";class Q extends HTMLElement{constructor(e,s){if(super(),this.template=e,this.parent=s,this.container=this,this.setAttribute("part","property"),this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){const o=new te;o.classList.add("collapsible","shacl-group"),o.open=e.config.attributes.collapse==="open",o.label=this.template.label,o.setAttribute("part","collapsible"),this.container=o,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.addEventListener("change",async()=>{await this.updateControls()})}async bindValues(e,s){if(this.template.path){let o=!1;if(e){let n=this.template.config.store.getQuads(e,this.template.path,null,this.parent.linked?null:m);s&&(n=await this.filterValidValues(n,e));for(const i of n)this.parent.linked||this.template.config.store.delete(i),await this.addPropertyInstance(i.object,!m.equals(i.graph)||this.template.config.providedResources[i.object.value]!==void 0,this.template.config.providedResources[i.object.value]!==void 0),this.template.hasValue&&i.object.equals(this.template.hasValue)&&(o=!0)}this.template.config.editMode&&this.template.hasValue&&!o&&!this.parent.linked&&await this.addPropertyInstance(this.template.hasValue)}}async addPropertyInstance(e,s,o=!1){let n;if(this.template.or?.length||this.template.xone?.length){const i=this.template.or?.length?this.template.or:this.template.xone;let a=!1;if(e){const r=st(i,e,this.template.config);if(r.length){const l=ae(Ce(this.template),r);n=await z(l,e,!this.parent.linked,this.parent.linked),a=!0}}!a&&this.template.config.editMode&&(n=Re(i,this,this.template.config),Ae(n,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else n=await z(this.template,e,o,s||this.parent.linked);return n&&this.container.insertBefore(n,this.querySelector(H)),n}async updateControls(){this.template.config.editMode&&!this.parent.linked&&!this.querySelector(H)&&this.container.appendChild(await this.createAddControls());const e=V(this.template),s=this.template.nodeShapes.size===0,o=this.querySelector(":scope > .add-button-wrapper > .link-button, :scope > .collapsible > .add-button-wrapper > .link-button")===null;let n=this.instanceCount();n===0&&(s||o&&e>0)&&(await this.addPropertyInstance(),n=1),s||this.querySelector(H)?.classList.toggle("required",n<e);let i;e>0?i=n>e:i=!s||n>1;const a=n<tt(this.template);this.classList.toggle("may-remove",i),this.classList.toggle("may-add",a)}instanceCount(){return this.querySelectorAll(bt).length}toRDF(e,s){const o=h.namedNode(this.template.path);for(const n of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance"))if(n.firstChild instanceof I){const i=n.firstChild.toRDF(e);e.addQuad(s,o,i,this.template.config.valuesGraphId)}else if(this.template.config.editMode)for(const i of n.querySelectorAll(":scope > .editor")){const a=fe(i);a&&e.addQuad(s,o,a,this.template.config.valuesGraphId)}else{const i=fe(n);i&&e.addQuad(s,o,i,this.template.config.valuesGraphId)}}async filterValidValues(e,s){let o=this.template.id,n=[s];if(this.template.qualifiedValueShape){o=this.template.qualifiedValueShape.id,n=[];for(const r of e)n.push(r.object)}const i=await this.template.config.validator.validate({dataset:this.template.config.store,terms:n},[{terms:[o]}]),a=new Set;for(const r of i.results){const l=this.template.qualifiedValueShape?r.focusNode:r.value;l?.ptrs?.length&&a.add(l.ptrs[0]._term.id)}return e.filter(r=>!a.has(r.object.id))}async createAddControls(){const e=document.createElement("div");e.classList.add("add-button-wrapper"),e.setAttribute("part","add-controls");const s=await ht(this);s&&e.appendChild(s);const o=this.template.config.theme.createButton(this.template.label,!1);o.title="Add "+this.template.label,o.classList.add("add-button"),o.setAttribute("text","");const n=o.getAttribute("part");return o.setAttribute("part",`${n?n+" ":""}add-button`),o.addEventListener("click",async()=>{const i=await this.addPropertyInstance();i&&(i.classList.add("fadeIn"),await this.updateControls(),setTimeout(()=>{He(i),i.classList.remove("fadeIn")},200))}),e.appendChild(o),e}}async function z(t,e,s=!1,o=!1){let n;if(t.nodeShapes.size){n=document.createElement("div"),n.classList.add("property-instance"),n.setAttribute("part","property-instance");for(const i of t.nodeShapes){const a=new I(i,e,t.nodeKind,t.label,o);n.appendChild(a),await a.ready}}else{const i=ut(t.path,t.datatype?.value);i?t.config.editMode&&!o?n=i.createEditor(t,e):n=i.createViewer(t,e):n=at(t,e||null,t.config.editMode&&!o),n.childNodes.length>0&&(n.classList.add("property-instance"),n.setAttribute("part","property-instance")),o&&n.classList.add("linked")}return t.config.editMode&&(!o||s)?Ae(n,t.label,t.config.theme.dense,t.config.hierarchyColorsStyleSheet!==void 0,s):t.config.hierarchyColorsStyleSheet!==void 0&&n.appendChild(je(!0)),e&&!t.config.editMode&&(e instanceof T?(n.dataset.value=e.value,e.language.length>0?n.dataset.lang=e.language:n.shaclDatatype=e.datatype):n.dataset.value="<"+e.value+">"),n.dataset.path=t.path,n}function Ae(t,e,s,o,n=!1){const i=je(o),a=new me;a.classList.add("remove-button","clear"),a.title="Remove "+e,a.dense=s,a.icon=!0;const r=a.getAttribute("part");a.setAttribute("part",`${r?r+" ":""}remove-button`),a.addEventListener("click",()=>{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"),i.appendChild(a),t.appendChild(i)}function je(t){const e=document.createElement("div");return e.className="remove-button-wrapper",e.setAttribute("part","remove-controls"),t&&e.classList.add("colorize"),e}window.customElements.define("shacl-property",Q);function mt(t,e){let s=t;const o=e.store.getQuads(t,null,null,null),n=A(o,"label",B,e.languages);n&&(s=n);let i;if(e.attributes.collapse!==null)i=new te,i.classList.add("collapsible"),i.open=e.attributes.collapse==="open",i.label=s,i.setAttribute("part","group collapsible");else{i=document.createElement("div");const r=document.createElement("h1");r.innerText=s,r.setAttribute("part","group-title"),i.appendChild(r),i.setAttribute("part","group")}i.dataset.subject=t,i.classList.add("shacl-group");const a=A(o,"order");return a&&(i.style.order=a),i}class I extends HTMLElement{constructor(e,s,o,n,i){super(),this.template=e,this.linked=i??!1,this.setAttribute("part","node");let a=s;a||(!o&&e.nodeKind&&(o=e.nodeKind),o===void 0&&e.config.attributes.valuesNamespace||o?.value===`${d}IRI`?a=h.namedNode(e.config.attributes.valuesNamespace+le()):a=h.blankNode(le())),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=this.getAttribute("part");this.setAttribute("part",`${c?c+" ":""}linked-node`);const f=document.createElement("a"),u=s.termType==="BlankNode"?"_:"+s.value:s.value;f.innerText=u,f.classList.add("ref-link"),f.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${u}']`)?.scrollIntoView()},this.appendChild(f),this.style.flexDirection="row",this.ready=Promise.resolve()}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)}this.ready=(async()=>{for(const[l,c]of Object.entries(e.properties))for(const f of c)await this.addPropertyInstance(f,s,c.length>1);for(const l of e.extendedShapes){const c=new I(l,s,void 0,void 0,i);this.prepend(c),await c.ready}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,l.setAttribute("part","node-title"),this.prepend(l)}})()}}toRDF(e,s,o=""){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,b,this.template.targetClass,this.template.config.valuesGraphId),o&&e.addQuad(s,h.namedNode(o),this.template.id,this.template.config.valuesGraphId)}return s}async addPropertyInstance(e,s,o){let n=null;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let a=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);a||(a=mt(e.group,e.config),this.appendChild(a)),n=a}else console.warn("ignoring unknown group reference",e.group,"existing groups:",e.config.groups);const i=new Q(e,this);await i.bindValues(s,o),(e.config.editMode||i.instanceCount()>0)&&(n?n.appendChild(i):this.appendChild(i),await i.updateControls())}async tryResolve(e,s,o){let n=!1;if(s){const i=nt(e,s,o);if(i.length){for(const a of i)await this.addPropertyInstance(o.getPropertyTemplate(a,this.template),s);n=!0}}n||this.appendChild(Re(e,this,o))}}window.customElements.define("shacl-node",I);const vt=`
|
|
83
|
+
`+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(s)}apply(e){}setDense(e){this.dense=e}createViewer(e,s,o){const n=document.createElement("div"),i=document.createElement("label");i.textContent=`${e}:`,o.description&&i.setAttribute("title",o.description.value),n.appendChild(i);let a=s.value,r=null;if(s instanceof k){const c=o.config.store.getQuads(a,null,null,null);if(c.length){const f=C(c,o.config.languages);f&&(a=f)}}else s instanceof R&&(s.language?(r=document.createElement("span"),r.classList.add("lang"),r.innerText=`@${s.language}`):s.datatype.value===`${x}date`?a=new Date(Date.parse(s.value)).toDateString():s.datatype.value===`${x}dateTime`&&(a=new Date(Date.parse(s.value)).toLocaleString()));let l;return Y(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 at(t,e,s){if(s){const o=V(t)>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,e,o,Ee(t.class,t),t);if(t.in){const n=t.config.lists[t.in];if(n?.length){const i=we(n,t.config.store,t.config.languages);return t.config.theme.createListEditor(t.label,e,o,i,t)}else console.error("list not found:",t.in,"existing lists:",t.config.lists)}if(t.datatype?.equals(ve)||t.languageIn?.length||t.datatype===void 0&&e instanceof R&&e.language)return t.config.theme.createLangStringEditor(t.label,e,o,t);switch(t.datatype?.value.replace(x,"")){case"integer":case"float":case"double":case"decimal":return t.config.theme.createNumberEditor(t.label,e,o,t);case"date":case"dateTime":return t.config.theme.createDateEditor(t.label,e,o,t);case"boolean":return t.config.theme.createBooleanEditor(t.label,e,o,t);case"base64Binary":return t.config.theme.createFileEditor(t.label,e,o,t)}return t.config.theme.createTextEditor(t.label,e,o,t)}else return e?t.config.theme.createViewer(t.label,e,t):document.createElement("div")}function rt(t,e,s){if(e==="application/ld+json")return lt(t);{const o=new ke({format:e,prefixes:s});o.addQuads(t);let n="";return o.end((i,a)=>{i&&console.error(i),n=a}),n}}function lt(t){const e=[];for(const s of t){const o={"@id":s.subject.id};if(s.predicate===b)o["@type"]=s.object.id;else{let n=s.object.value;s.object instanceof R?s.object.language?n={"@language":s.object.language,"@value":s.object.value}:s.object.datatype&&s.object.datatype.value!==`${x}#string`&&(n={"@type":s.object.datatype.value,"@value":s.object.value}):n={"@id":s.object.id},o[s.predicate.value]=n}e.push(o)}return JSON.stringify(e)}function fe(t){let e=t.shaclDatatype,s=t.dataset.value||t.value;if(t.type==="checkbox"||t.getAttribute("type")==="checkbox"){if(t.checked||parseInt(t.dataset.minCount||"0")>0)return h.literal(t.checked?"true":"false",e)}else if(s){if(s.startsWith("<")&&s.endsWith(">")&&s.indexOf(":")>-1)return h.namedNode(s.substring(1,s.length-1));if(t.dataset.class||t.dataset.nodeKind===u+"IRI")return h.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 k&&Ge.equals(e))&&typeof s=="string"){let o=s.split("^^");o.length===2&&o[0].startsWith('"')&&o[0].endsWith('"')&&o[1].split(":").length===2?(s=o[0].substring(1,o[0].length-1),e=h.namedNode(o[1])):(o=s.split("@"),o.length===2&&o[0].startsWith('"')&&o[0].endsWith('"')?(s=o[0].substring(1,o[0].length-1),e=o[1]):s.startsWith('"')&&s.endsWith('"')&&(s=s.substring(1,s.length-1)))}return h.literal(s,e)}}const D={};function ct(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 dt(){return Object.entries(D).map(t=>t[1])}function ut(t,e){let s=D[`${t}^${e}`];return s||(s=D[`${t}^undefined`],s)?s:D[`undefined^${e}`]}class kt{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)}}async function ht(t){if(t.template.nodeShapes.size===0)return;const e=t.template.config.resourceLinkProvider;if((!e||e&&!e.lazyLoad)&&(await ge(t.template),pe(t).length===0))return;const s=t.template.config.theme.createButton(t.template.label,!1);s.title="Link existing "+t.template.label,s.classList.add("link-button"),s.setAttribute("text","");const o=s.getAttribute("part");return s.setAttribute("part",`${o?o+" ":""}link-button`),s.addEventListener("click",async()=>{e?.lazyLoad&&(s.classList.add("loading"),await ge(t.template),s.classList.remove("loading"));const n=pe(t);if(n.length===0)s.innerText="No linkable resources found",s.setAttribute("disabled",""),setTimeout(()=>s.remove(),2e3);else{let i=t.template.config.form.querySelector("#dialog");i||(i=new Ne,i.classList.add("link-chooser"),i.closable=!0,t.template.config.form.appendChild(i)),i.title="Link existing "+t.template.label,ft(i,t,n),i.open=!0}}),s}function ft(t,e,s){const o=document.createElement("div");for(const n of s){const i=document.createElement("div");i.classList.add("link-option"),i.title="Link this resource",i.innerText=n.label||n.value,i.addEventListener("click",()=>{pt(n.value,e),t.open=!1}),o.appendChild(i)}t.replaceChildren(o)}function pe(t){const e=[];if(t.template.config.resourceLinkProvider){for(const s of t.template.nodeShapes)if(t.template.config.providedConformingResourceIds[s.id.value])for(const o of t.template.config.providedConformingResourceIds[s.id.value])t.querySelector(`:scope > .property-instance > shacl-node[data-node-id='${o}'], :scope > .collapsible > .property-instance > shacl-node[data-node-id='${o}']`)===null&&e.push({value:o,label:C(t.template.config.store.getQuads(h.namedNode(o),null,null,null),t.template.config.languages),children:[]})}return e}async function pt(t,e){const s=h.namedNode(t);if(Te(s,e.template.config.store)){if(e.template.config.providedResources[t]?.length>0){const n={store:e.template.config.store,importedUrls:[],atts:{loadOwlImports:!1}};await E(j(e.template.config.providedResources[t]),n,y),e.template.config.providedResources[t]=""}const o=await z(e.template,s,!0,!0);e.container.insertBefore(o,e.querySelector(":scope > .add-button-wrapper")),await e.updateControls()}}async function ge(t){const e=t.config.resourceLinkProvider;if(!e)return;const s=new Set(Array.from(t.nodeShapes).map(n=>n.id.value));if(s.size===0)return;const o=Xe(Object.keys(t.config.providedConformingResourceIds),s);if(o.length!==0)try{const n=await e.listConformingResources(o,t);if(n){for(const i of Object.keys(n)){const a=new Set(n[i]);t.config.providedConformingResourceIds[i]=a,await Re(a,!1,t.config)}for(const i of o)t.config.providedConformingResourceIds[i]||(t.config.providedConformingResourceIds[i]=new Set)}}catch(n){console.error("failed loading conforming resources",n)}}async function Re(t,e,s){if(s.resourceLinkProvider&&t.size>0){const o=[];for(const n of t)s.providedResources[n]||o.push(n);if(o.length===0)return[];try{const n=await s.resourceLinkProvider.loadResources(o);if(n){const i={store:s.store,importedUrls:[],atts:{loadOwlImports:!1}};for(const a of n)s.providedResources[a.resourceId]=a.resourceRDF,e&&await E(j(a.resourceRDF),i,y);return n}for(const i of o)s.providedResources[i]||(s.providedResources[i]="")}catch(n){console.error("failed loading resources",n)}}return[]}async function gt(t){const e=new Set;for(const s of t.store.getQuads(null,null,null,m))Te(s.object,t.store)&&e.add(s.object.value);await Re(e,!0,t)}function Te(t,e){return t.termType==="NamedNode"&&e.countQuads(t,null,null,null)===0}const H=":scope > .add-button-wrapper, :scope > .collapsible > .add-button-wrapper",bt=":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance";class Q extends HTMLElement{constructor(e,s){if(super(),this.template=e,this.parent=s,this.container=this,this.setAttribute("part","property"),this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){const o=new te;o.classList.add("collapsible","shacl-group"),o.open=e.config.attributes.collapse==="open",o.label=this.template.label,o.setAttribute("part","collapsible"),this.container=o,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.addEventListener("change",async()=>{await this.updateControls()})}async bindValues(e,s){if(this.template.path){let o=!1;if(e){let n=this.template.config.store.getQuads(e,this.template.path,null,this.parent.linked?null:m);s&&(n=await this.filterValidValues(n,e));for(const i of n)this.parent.linked||this.template.config.store.delete(i),await this.addPropertyInstance(i.object,!m.equals(i.graph)||this.template.config.providedResources[i.object.value]!==void 0,this.template.config.providedResources[i.object.value]!==void 0),this.template.hasValue&&i.object.equals(this.template.hasValue)&&(o=!0)}this.template.config.editMode&&this.template.hasValue&&!o&&!this.parent.linked&&await this.addPropertyInstance(this.template.hasValue)}}async addPropertyInstance(e,s,o=!1){let n;if(this.template.or?.length||this.template.xone?.length){const i=this.template.or?.length?this.template.or:this.template.xone;let a=!1;if(e){const r=st(i,e,this.template.config);if(r.length){const l=ae(Ce(this.template),r);n=await z(l,e,!this.parent.linked,this.parent.linked,this.parent),a=!0}}!a&&this.template.config.editMode&&(n=Ie(i,this,this.template.config),Ae(n,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else n=await z(this.template,e,o,s||this.parent.linked,this.parent);return n&&this.container.insertBefore(n,this.querySelector(H)),n}async updateControls(){this.template.config.editMode&&!this.parent.linked&&!this.querySelector(H)&&this.container.appendChild(await this.createAddControls());const e=V(this.template),s=this.template.nodeShapes.size===0,o=this.querySelector(":scope > .add-button-wrapper > .link-button, :scope > .collapsible > .add-button-wrapper > .link-button")===null,n=s||!this.hasRecursiveNodeShape();let i=this.instanceCount();i===0&&n&&(s||o&&e>0)&&(await this.addPropertyInstance(),i=1),s||this.querySelector(H)?.classList.toggle("required",i<e);let a;e>0?a=i>e:a=!s||i>1;const r=i<tt(this.template);this.classList.toggle("may-remove",a),this.classList.toggle("may-add",r)}instanceCount(){return this.querySelectorAll(bt).length}hasRecursiveNodeShape(){const e=new Set;this.parent.ancestorShapeIds.forEach(s=>e.add(s)),e.add(this.parent.template.id.value);for(const s of this.template.nodeShapes)if(e.has(s.id.value))return!0;return!1}toRDF(e,s){const o=h.namedNode(this.template.path);for(const n of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance"))if(n.firstChild instanceof T){const i=n.firstChild.toRDF(e);e.addQuad(s,o,i,this.template.config.valuesGraphId)}else if(this.template.config.editMode)for(const i of n.querySelectorAll(":scope > .editor")){const a=fe(i);a&&e.addQuad(s,o,a,this.template.config.valuesGraphId)}else{const i=fe(n);i&&e.addQuad(s,o,i,this.template.config.valuesGraphId)}}async filterValidValues(e,s){let o=this.template.id,n=[s];if(this.template.qualifiedValueShape){o=this.template.qualifiedValueShape.id,n=[];for(const r of e)n.push(r.object)}const i=await this.template.config.validator.validate({dataset:this.template.config.store,terms:n},[{terms:[o]}]),a=new Set;for(const r of i.results){const l=this.template.qualifiedValueShape?r.focusNode:r.value;l?.ptrs?.length&&a.add(l.ptrs[0]._term.id)}return e.filter(r=>!a.has(r.object.id))}async createAddControls(){const e=document.createElement("div");e.classList.add("add-button-wrapper"),e.setAttribute("part","add-controls");const s=await ht(this);s&&e.appendChild(s);const o=this.template.config.theme.createButton(this.template.label,!1);o.title="Add "+this.template.label,o.classList.add("add-button"),o.setAttribute("text","");const n=o.getAttribute("part");return o.setAttribute("part",`${n?n+" ":""}add-button`),o.addEventListener("click",async()=>{const i=await this.addPropertyInstance();i&&(i.classList.add("fadeIn"),await this.updateControls(),setTimeout(()=>{He(i),i.classList.remove("fadeIn")},200))}),e.appendChild(o),e}}async function z(t,e,s=!1,o=!1,n){let i;if(t.nodeShapes.size){i=document.createElement("div"),i.classList.add("property-instance"),i.setAttribute("part","property-instance");const a=new Set(n?.ancestorShapeIds??[]);n&&a.add(n.template.id.value);for(const r of t.nodeShapes){const l=new T(r,e,t.nodeKind,t.label,o,a);i.appendChild(l),await l.ready}}else{const a=ut(t.path,t.datatype?.value);a?t.config.editMode&&!o?i=a.createEditor(t,e):i=a.createViewer(t,e):i=at(t,e||null,t.config.editMode&&!o),i.childNodes.length>0&&(i.classList.add("property-instance"),i.setAttribute("part","property-instance")),o&&i.classList.add("linked")}return t.config.editMode&&(!o||s)?Ae(i,t.label,t.config.theme.dense,t.config.hierarchyColorsStyleSheet!==void 0,s):t.config.hierarchyColorsStyleSheet!==void 0&&i.appendChild(je(!0)),e&&!t.config.editMode&&(e instanceof R?(i.dataset.value=e.value,e.language.length>0?i.dataset.lang=e.language:i.shaclDatatype=e.datatype):i.dataset.value="<"+e.value+">"),i.dataset.path=t.path,i}function Ae(t,e,s,o,n=!1){const i=je(o),a=new me;a.classList.add("remove-button","clear"),a.title="Remove "+e,a.dense=s,a.icon=!0;const r=a.getAttribute("part");a.setAttribute("part",`${r?r+" ":""}remove-button`),a.addEventListener("click",()=>{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"),i.appendChild(a),t.appendChild(i)}function je(t){const e=document.createElement("div");return e.className="remove-button-wrapper",e.setAttribute("part","remove-controls"),t&&e.classList.add("colorize"),e}window.customElements.define("shacl-property",Q);function mt(t,e){let s=t;const o=e.store.getQuads(t,null,null,null),n=A(o,"label",B,e.languages);n&&(s=n);let i;if(e.attributes.collapse!==null)i=new te,i.classList.add("collapsible"),i.open=e.attributes.collapse==="open",i.label=s,i.setAttribute("part","group collapsible");else{i=document.createElement("div");const r=document.createElement("h1");r.innerText=s,r.setAttribute("part","group-title"),i.appendChild(r),i.setAttribute("part","group")}i.dataset.subject=t,i.classList.add("shacl-group");const a=A(o,"order");return a&&(i.style.order=a),i}class T extends HTMLElement{constructor(e,s,o,n,i,a=new Set){super(),this.template=e,this.linked=i??!1,this.ancestorShapeIds=a,this.setAttribute("part","node");let r=s;r||(!o&&e.nodeKind&&(o=e.nodeKind),o===void 0&&e.config.attributes.valuesNamespace||o?.value===`${u}IRI`?r=h.namedNode(e.config.attributes.valuesNamespace+le()):r=h.blankNode(le())),this.nodeId=r;const l=JSON.stringify([e.id,s]);if(s&&e.config.renderedNodes.has(l)){n=n||"Link";const c=document.createElement("label");c.innerText=n,c.classList.add("linked"),this.appendChild(c);const f=this.getAttribute("part");this.setAttribute("part",`${f?f+" ":""}linked-node`);const d=document.createElement("a"),p=s.termType==="BlankNode"?"_:"+s.value:s.value;d.innerText=p,d.classList.add("ref-link"),d.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${p}']`)?.scrollIntoView()},this.appendChild(d),this.style.flexDirection="row",this.ready=Promise.resolve()}else{s&&e.config.renderedNodes.add(l);const c=this.ancestorShapeIds,f=this.template.id.value;if(this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){const d=document.createElement("div");d.innerText=`id: ${this.nodeId.id}`,d.classList.add("node-id-display"),this.appendChild(d)}this.ready=(async()=>{const d=new Set(c);d.add(f);for(const[p,g]of Object.entries(e.properties))for(const w of g)await this.addPropertyInstance(w,s,g.length>1);for(const p of e.extendedShapes){const g=new T(p,s,void 0,void 0,i,d);this.prepend(g),await g.ready}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 p=document.createElement("h1");p.innerText=n,p.setAttribute("part","node-title"),this.prepend(p)}})()}}toRDF(e,s,o=""){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,b,this.template.targetClass,this.template.config.valuesGraphId),o&&e.addQuad(s,h.namedNode(o),this.template.id,this.template.config.valuesGraphId)}return s}async addPropertyInstance(e,s,o){let n=null;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let a=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);a||(a=mt(e.group,e.config),this.appendChild(a)),n=a}else console.warn("ignoring unknown group reference",e.group,"existing groups:",e.config.groups);const i=new Q(e,this);await i.bindValues(s,o),(e.config.editMode||i.instanceCount()>0)&&(n?n.appendChild(i):this.appendChild(i),await i.updateControls())}async tryResolve(e,s,o){let n=!1;if(s){const i=nt(e,s,o);if(i.length){for(const a of i)await this.addPropertyInstance(o.getPropertyTemplate(a,this.template),s);n=!0}}n||this.appendChild(Ie(e,this,o))}}window.customElements.define("shacl-node",T);const vt=`
|
|
84
84
|
.editor:not([type='checkbox']) { border: 1px solid var(--shacl-border-color, #DDD); }
|
|
85
85
|
.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; }
|
|
86
86
|
.property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
|
|
87
87
|
.mode-edit .property-instance label { width: var(--label-width); }
|
|
88
|
-
`;class yt extends ot{constructor(e){super(e||vt),this.idCtr=0}createDefaultTemplate(e,s,o,n,i){if(n.id=`e${this.idCtr++}`,n.classList.add("editor"),n.setAttribute("part","editor"),i?.datatype?n.shaclDatatype=i.datatype:s instanceof
|
|
89
|
-
`+a}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){const e=new W;return Object.keys(e).map(s=>(s=s.replace(/[A-Z]/g,o=>"-"+o.toLowerCase()),"data-"+s))}buildTemplateKey(e,s){let o=e.value;return s&&(s instanceof he?o+="*"+s.id.value:o+="*"+this.buildTemplateKey(s.id,s.parent)),o}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){const e=new Set;for(const s of Object.values(this._nodeTemplates))e.add(s.id.value);return e}getNodeTemplate(e,s){const o=this.buildTemplateKey(e,s);let n=this._nodeTemplates[o];return n||(n=new M(e,this,s)),n}getPropertyTemplate(e,s){const o=this.buildTemplateKey(e,s);let n=this._propertyTemplates[o];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=Je(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(s=>{this.groups.push(s.id)},b,`${
|
|
88
|
+
`;class yt extends ot{constructor(e){super(e||vt),this.idCtr=0}createDefaultTemplate(e,s,o,n,i){if(n.id=`e${this.idCtr++}`,n.classList.add("editor"),n.setAttribute("part","editor"),i?.datatype?n.shaclDatatype=i.datatype:s instanceof R&&(n.shaclDatatype=s.datatype),i&&V(i)>0&&(n.dataset.minCount=String(V(i))),i?.class&&(n.dataset.class=i.class.value),i?.nodeKind)n.dataset.nodeKind=i.nodeKind.value;else if(s&&(s instanceof k||i?.nodeKind?.equals(ye))&&(n.dataset.nodeKind=u+"IRI",i)){const c=C(i.config.store.getQuads(s,null,null,null),i.config.languages);c&&(n.dataset.value="<"+s.value+">",s=h.literal(c))}(i?.hasValue&&s||i?.readonly)&&(n.disabled=!0),i?.datatype?.equals(Ue)?n.checked=s?.value==="true"||i?.defaultValue?.value==="true":n.value=s?.value||i?.defaultValue?.value||"";const a=document.createElement("label");a.htmlFor=n.id,a.innerText=e,a.setAttribute("part","label"),i?.description&&a.setAttribute("title",i.description.value);const r=i?.description?i.description.value:i?.pattern?i.pattern:null;r&&n.setAttribute("placeholder",r),o&&(n.setAttribute("required","true"),a.classList.add("required"));const l=document.createElement("div");return l.setAttribute("part","field"),l.appendChild(a),l.appendChild(n),l}createDateEditor(e,s,o,n){const i=new U;n.datatype?.value===x+"dateTime"?(i.type="datetime-local",i.setAttribute("step","1")):i.type="date",i.clearable=!0,i.dense=this.dense,i.classList.add("pr-0");const a=this.createDefaultTemplate(e,null,o,i,n);if(s)try{let r=new Date(s.value).toISOString();n.datatype?.value===x+"dateTime"?r=r.slice(0,19):r=r.slice(0,10),i.value=r}catch(r){console.error(r,s)}return a}createTextEditor(e,s,o,n){let i;return n.singleLine===!1?(i=new qe,i.resize="auto"):i=new U,i.dense=this.dense,n.pattern&&(i.pattern=n.pattern),n.minLength&&(i.minLength=n.minLength),n.maxLength&&(i.maxLength=n.maxLength),this.createDefaultTemplate(e,s,o,i,n)}createLangStringEditor(e,s,o,n){const i=this.createTextEditor(e,s,o,n),a=i.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.setAttribute("part","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 R&&(r.value=s.language),a.dataset.lang=r.value,a.appendChild(r),i}createBooleanEditor(e,s,o,n){const i=document.createElement("input");i.type="checkbox",i.classList.add("ml-0");const a=this.createDefaultTemplate(e,null,o,i,n);return i.removeAttribute("required"),a.querySelector(":scope label")?.classList.remove("required"),s instanceof R&&(i.checked=s.value==="true"),a}createFileEditor(e,s,o,n){const i=document.createElement("input");return i.type="file",i.addEventListener("change",a=>{if(i.files?.length){a.stopPropagation();const r=new FileReader;r.readAsDataURL(i.files[0]),r.onload=()=>{i.binaryData=btoa(r.result),i.parentElement?.dispatchEvent(new Event("change",{bubbles:!0}))}}else i.binaryData=void 0}),this.createDefaultTemplate(e,s,o,i,n)}createNumberEditor(e,s,o,n){const i=new U;i.type="number",i.clearable=!0,i.dense=this.dense,i.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&&(i.min=String(a)),r!==void 0&&(i.max=String(r)),n.datatype?.value!==x+"integer"&&(i.step="0.1"),this.createDefaultTemplate(e,s,o,i,n)}createListEditor(e,s,o,n,i){const a=new _e;a.clearable=!0,a.dense=this.dense;const r=this.createDefaultTemplate(e,null,o,a,i),l=document.createElement("ul");let c=!0;const f=(d,p)=>{const g=document.createElement("li");if(typeof d.value=="string"?(g.dataset.value=d.value,g.innerText=d.label?d.label:d.value):(g.dataset.value=d.value.id,d.value instanceof k&&(g.dataset.value="<"+g.dataset.value+">"),g.innerText=d.label?d.label:d.value.value),p.appendChild(g),d.children?.length){c=!1;const w=document.createElement("ul");g.appendChild(w);for(const L of d.children)f(L,w)}};for(const d of n)f(d,l);return c||(a.collapse=!0),a.appendChild(l),s&&(a.value=s.id,s instanceof k&&(a.value="<"+a.value+">")),r}createButton(e,s){const o=new me;return o.dense=this.dense,o.innerHTML=e,s?(o.setAttribute("primary",""),o.setAttribute("part","button primary")):o.setAttribute("part","button"),o}}const wt={[`${u}node`]:(t,e)=>{t.extendedShapes.add(new M(e,t.config,t))},[`${u}and`]:(t,e)=>{for(const s of t.config.lists[e.value])t.extendedShapes.add(new M(s,t.config,t))},[`${u}property`]:(t,e)=>{const s=t.config.getPropertyTemplate(e,t);if(s.path){let o=t.properties[s.path];if(o||(o=[],t.properties[s.path]=o),s.qualifiedValueShape)o.push(s);else{let n;for(let i=0;i<t.properties[s.path].length&&!n;i++)t.properties[s.path][i].qualifiedValueShape||(n=t.properties[s.path][i]);n?Le(n,s):o.push(s)}}},[`${u}nodeKind`]:(t,e)=>{t.nodeKind=e},[`${u}targetClass`]:(t,e)=>{t.targetClass=e},[`${u}or`]:(t,e)=>{t.or=t.config.lists[e.value]},[`${u}xone`]:(t,e)=>{t.xone=t.config.lists[e.value]},[ie.id]:(t,e)=>{t.owlImports.add(e)},[`${ne}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 M{constructor(e,s,o){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.id=e,this.config=s,this.parent=o,s.registerNodeTemplate(this),St(this,this.config.store.getQuads(e,null,null,null))}}function St(t,e){for(const s of e)wt[s.predicate.id]?.call(t,t,s.object);return t}function Et(t){for(const e of Object.values(t.properties))for(const s of e){const[o,n]=Z(t,s.path);if(o.length>1&&n){const i=o[o.length-1];for(let a=o.length-2;a>=0;a--){const r=o[a];delete r.parent.properties[r.path],Le(i,r)}}}}function Z(t,e,s=new Set,o=[],n=!1){if(!s.has(t.id.value)){s.add(t.id.value);const i=t.properties[e];if(i?.length===1){o.push(i[0]),n=n||i[0].maxCount===1;for(const a of i[0].nodeShapes){const[r,l]=Z(a,e,s,o,n);n=n||l}}for(const a of t.extendedShapes){const[r,l]=Z(a,e,s,o,n);n=n||l}}return[o,n]}class W{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=O.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense="true",this.useShadowRoot="true"}}const xt="#4c93d785, #f85e9a85, #00327385, #87001f85";class be{constructor(e){this.attributes=new W,this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new ee,this._nodeTemplates={},this._propertyTemplates={},this.validator=new ce(this._store,{details:!0,factory:h}),this.providedConformingResourceIds={},this.providedResources={},this.form=e,this._theme=new yt,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.providedConformingResourceIds={},this.providedResources={},this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){const s=new W;if(Object.keys(s).forEach(o=>{const n=e.dataset[o];n!==void 0&&(s[o]=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 o=this.languages.indexOf(s.language);o>-1&&this.languages.splice(o,1),this.languages.unshift(s.language)}if(s.valuesGraph&&(this.valuesGraphId=h.namedNode(s.valuesGraph)),s.hierarchyColors!=null){const o=s.hierarchyColors.length?s.hierarchyColors:xt;let n=`:host { --hierarchy-colors: ${o}; --hierarchy-colors-length: ${o.split(",").length} }`;for(let i=8;i>=0;i--){let a=`shacl-property { --hierarchy-level: ${i} }`;for(let r=0;r<i;r++)a="shacl-property "+a;n=n+`
|
|
89
|
+
`+a}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){const e=new W;return Object.keys(e).map(s=>(s=s.replace(/[A-Z]/g,o=>"-"+o.toLowerCase()),"data-"+s))}buildTemplateKey(e,s){let o=e.value;return s&&(s instanceof he?o+="*"+s.id.value:o+="*"+this.buildTemplateKey(s.id,s.parent)),o}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){const e=new Set;for(const s of Object.values(this._nodeTemplates))e.add(s.id.value);return e}getNodeTemplate(e,s){const o=this.buildTemplateKey(e,s);let n=this._nodeTemplates[o];return n||(n=new M(e,this,s)),n}getPropertyTemplate(e,s){const o=this.buildTemplateKey(e,s);let n=this._propertyTemplates[o];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=Je(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(s=>{this.groups.push(s.id)},b,`${u}PropertyGroup`,null),this.validator=new ce(e,{details:!0,factory:h})}}const Ct=200;class Lt extends HTMLElement{constructor(){super(),this.shape=null,this.styleElement=null,this.form=document.createElement("form"),this.form.setAttribute("part","form"),this.config=new be(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 be.dataAttributes()}connectedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}attributeChangedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),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 Ye({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.config.resourceLinkProvider&&await gt(this.config),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 dt())n.stylesheet&&s.push(n.stylesheet);this.applyStyles(s);const o=new M(e,this.config);for(const n of this.config.nodeTemplates)Et(n);if(this.shape=new T(o,this.config.attributes.valuesSubject?h.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&o.label){const n=document.createElement("h3");n.innerText=o.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.classList.add("submit-button");const i=n.getAttribute("part");n.setAttribute("part",`${i?i+" ":""}submit-button`),n.addEventListener("click",a=>{a.preventDefault(),this.form.reportValidity()&&this.validate().then(r=>{if(r?.conforms)this.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}));else{const l=this.form.querySelector(":scope .invalid > .editor");l?l.focus():this.form.querySelector(":scope .invalid")?.scrollIntoView()}})}),this.form.appendChild(n)}(async()=>(await this.shape?.ready,this.config.attributes.valuesSubject&&this.removeFromDataGraph(h.namedNode(this.config.attributes.valuesSubject)),this.validate(!0)))()}}else if(this.config.store.countQuads(null,null,null,y)>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"),await this.shape?.ready,this.dispatchEvent(new Event("ready"))},Ct)}ensureRenderRoot(){this.config.attributes.useShadowRoot!=="false"?(this.shadowRoot||this.attachShadow({mode:"open"}),this.shadowRoot.contains(this.form)||this.shadowRoot.prepend(this.form)):(this.shadowRoot?.contains(this.form)&&this.shadowRoot.removeChild(this.form),this.contains(this.form)||this.prepend(this.form))}applyStyles(e){if(this.config.attributes.useShadowRoot!=="false"&&this.shadowRoot){this.shadowRoot.adoptedStyleSheets=e,this.styleElement&&(this.styleElement.remove(),this.styleElement=null);return}const o=e.map(n=>Array.from(n.cssRules).map(a=>a.cssText).join(`
|
|
90
90
|
`).replace(/:host\b/g,"shacl-form")).join(`
|
|
91
91
|
`);this.styleElement||(this.styleElement=document.createElement("style"),this.prepend(this.styleElement)),this.styleElement.textContent=o}serialize(e="text/turtle",s=this.toRDF()){const o=s.getQuads(null,null,null,null);return rt(o,e,P)}toRDF(e=new ee){return this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),e}registerPlugin(e){ct(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}setResourceLinkProvider(e){this.config.resourceLinkProvider=e,this.initialize()}async validate(e=!1){for(const n of this.form.querySelectorAll(":scope .validation-error"))n.remove();for(const n of this.form.querySelectorAll(":scope .property-instance"))n.classList.remove("invalid"),n.querySelector(":scope > .editor")?.value?n.classList.add("valid"):n.classList.remove("valid");for(const n of this.form.querySelectorAll(".add-button-wrapper"))n.classList.remove("invalid","validation-error");if(!this.shape)return{conforms:!0,results:[]};if(!e){const n=this.form.querySelectorAll(".add-button-wrapper.required");for(const i of n)i.classList.add("invalid"),i.after(this.createValidationErrorDisplay("Value is required","node"));if(n.length>0)return{conforms:!1,results:[]}}const s=this.shape;return new Promise(n=>{this.config.store.deleteGraph(this.config.valuesGraphId||"").on("end",async()=>{s.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{const i=await this.config.validator.validate({dataset:this.config.store,terms:[s.nodeId]},[{terms:[s.template.id]}]);for(const a of i.results)if(a.focusNode?.ptrs?.length)for(const r of a.focusNode.ptrs){const l=r._term;if(a.path?.length){const c=a.path[0].predicates[0];let f=this.form.querySelectorAll(`
|
|
92
92
|
:scope shacl-node[data-node-id='${l.id}'] > shacl-property > .property-instance[data-path='${c.id}'] > .editor,
|
|
@@ -94,5 +94,5 @@ rokit-dialog.link-chooser::part(dialog) { min-height: min(434px, 90vh); width: m
|
|
|
94
94
|
:scope shacl-node[data-node-id='${l.id}'] > .shacl-group > shacl-property > .property-instance[data-path='${c.id}'] > .editor,
|
|
95
95
|
:scope shacl-node[data-node-id='${l.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[data-path='${c.id}'] > .editor`);f.length===0&&(f=this.form.querySelectorAll(`
|
|
96
96
|
:scope [data-node-id='${l.id}'] > shacl-property > .property-instance[data-path='${c.id}'],
|
|
97
|
-
:scope [data-node-id='${l.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${c.id}']`));for(const
|
|
98
|
-
`;else n.sourceConstraintComponent?.value&&(o.title=n.sourceConstraintComponent.value);else typeof e=="string"&&(o.title=e);return o}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=h.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,b,K,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,m)>0){const s=h.namedNode(this.config.attributes.valuesSubject),o=[...this.config.store.getQuads(s,b,null,m),...this.config.store.getQuads(s,O,null,m)];if(o.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${b.id} nor ${O.id} statement`);else for(const i of o)if(this.config.store.getQuads(i.object,b,K,null).length>0)return i.object;const n=this.config.store.getObjects(s,b,m);for(const i of n)for(const a of this.config.store.getQuads(null,G,i,null))return a.subject}const e=this.config.store.getQuads(null,b,K,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){for(const s of this.config.store.getQuads(e,null,null,m))this.config.store.delete(s),(s.object.termType==="NamedNode"||s.object.termType==="BlankNode")&&this.removeFromDataGraph(s.object)}}window.customElements.define("shacl-form",Lt);export{be as Config,yt as DefaultTheme,kt as Plugin,Lt as ShaclForm,he as ShaclPropertyTemplate,ot as Theme,_ as fetchRDF,C as findLabel,
|
|
97
|
+
:scope [data-node-id='${l.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${c.id}']`));for(const d of f)if(d.classList.contains("editor")){if(!e||d.value){let p=d.parentElement;p.classList.add("invalid"),p.classList.remove("valid"),p.appendChild(this.createValidationErrorDisplay(a));do p instanceof te&&(p.open=!0),p=p.parentElement;while(p)}}else e||(d.classList.add("invalid"),d.classList.remove("valid"),d.appendChild(this.createValidationErrorDisplay(a,"node")))}else e||this.form.querySelector(`:scope [data-node-id='${l.id}']`)?.prepend(this.createValidationErrorDisplay(a,"node"))}n(i)}catch(i){console.error(i),n({conforms:!1,results:[]})}})})}createValidationErrorDisplay(e,s){const o=document.createElement("span");o.classList.add("validation-error"),s&&o.classList.add(s);const n=typeof e=="object"&&e!==null?e:null;if(n)if(n.message?.length)for(const i of n.message)o.title+=i.value+`
|
|
98
|
+
`;else n.sourceConstraintComponent?.value&&(o.title=n.sourceConstraintComponent.value);else typeof e=="string"&&(o.title=e);return o}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=h.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,b,K,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,m)>0){const s=h.namedNode(this.config.attributes.valuesSubject),o=[...this.config.store.getQuads(s,b,null,m),...this.config.store.getQuads(s,O,null,m)];if(o.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${b.id} nor ${O.id} statement`);else for(const i of o)if(this.config.store.getQuads(i.object,b,K,null).length>0)return i.object;const n=this.config.store.getObjects(s,b,m);for(const i of n)for(const a of this.config.store.getQuads(null,G,i,null))return a.subject}const e=this.config.store.getQuads(null,b,K,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){for(const s of this.config.store.getQuads(e,null,null,m))this.config.store.delete(s),(s.object.termType==="NamedNode"||s.object.termType==="BlankNode")&&this.removeFromDataGraph(s.object)}}window.customElements.define("shacl-form",Lt);export{be as Config,yt as DefaultTheme,kt as Plugin,Lt as ShaclForm,he as ShaclPropertyTemplate,ot as Theme,_ as fetchRDF,C as findLabel,E as importRDF,Ct as initTimeout,Ye as loadGraphs,j as parseRDF,P as prefixes,et as propertyMappers,q as rdfCache,ct as registerPlugin};
|
package/dist/node.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export declare class ShaclNode extends HTMLElement {
|
|
|
8
8
|
template: ShaclNodeTemplate;
|
|
9
9
|
linked: boolean;
|
|
10
10
|
ready: Promise<void>;
|
|
11
|
-
|
|
11
|
+
ancestorShapeIds: Set<string>;
|
|
12
|
+
constructor(template: ShaclNodeTemplate, valueSubject: NamedNode | BlankNode | undefined, nodeKind?: NamedNode, label?: string, linked?: boolean, ancestorShapeIds?: Set<string>);
|
|
12
13
|
toRDF(graph: Store, subject?: NamedNode | BlankNode, generateNodeShapeReference?: string): (NamedNode | BlankNode);
|
|
13
14
|
addPropertyInstance(template: ShaclPropertyTemplate, valueSubject: NamedNode | BlankNode | undefined, multiValuedPath?: boolean): Promise<void>;
|
|
14
15
|
tryResolve(options: Term[], valueSubject: NamedNode | BlankNode | undefined, config: Config): Promise<void>;
|
package/dist/property.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ export declare class ShaclProperty extends HTMLElement {
|
|
|
11
11
|
addPropertyInstance(value?: Term, linked?: boolean, forceRemovable?: boolean): Promise<HTMLElement | undefined>;
|
|
12
12
|
updateControls(): Promise<void>;
|
|
13
13
|
instanceCount(): number;
|
|
14
|
+
hasRecursiveNodeShape(): boolean;
|
|
14
15
|
toRDF(graph: Store, subject: NamedNode | BlankNode): void;
|
|
15
16
|
filterValidValues(values: Quad[], valueSubject: NamedNode | BlankNode): Promise<Quad[]>;
|
|
16
17
|
createAddControls(): Promise<HTMLDivElement>;
|
|
17
18
|
}
|
|
18
|
-
export declare function createPropertyInstance(template: ShaclPropertyTemplate, value?: Term, forceRemovable?: boolean, linked?: boolean): Promise<HTMLElement>;
|
|
19
|
+
export declare function createPropertyInstance(template: ShaclPropertyTemplate, value?: Term, forceRemovable?: boolean, linked?: boolean, parentNode?: ShaclNode): Promise<HTMLElement>;
|