@ulb-darmstadt/shacl-form 2.0.5 → 2.0.7
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/README.md +1 -1
- package/dist/bundle.js +36 -35
- package/dist/exports.d.ts +1 -0
- package/dist/index.js +8 -7
- package/dist/property-template.d.ts +1 -0
- package/package.json +2 -2
package/dist/exports.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{DataFactory as u,Store as ee,Quad as ge,StreamParser as Ie,Literal as S,NamedNode as R,Writer as je}from"n3";import{RdfXmlParser as $e}from"rdfxml-streaming-parser";import Pe from"jsonld";import{RokitCollapsible as te,RokitSelect as be,RokitButton as Re,RokitInput as U,RokitTextArea as De}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#",x="http://www.w3.org/1999/02/22-rdf-syntax-ns#",z="http://www.w3.org/2000/01/rdf-schema#",se="http://www.w3.org/2004/02/skos/core#",Ne="http://www.w3.org/2002/07/owl#",Ae="http://www.w3.org/ns/oa#",me="http://purl.org/dc/terms/",Oe="http://xmlns.com/foaf/0.1/",T=u.namedNode("loaded-shapes"),b=u.namedNode("loaded-data"),g=u.namedNode(x+"type"),ve=u.namedNode(x+"langString"),F=u.namedNode(me+"conformsTo"),ue=u.namedNode(z+"subClassOf"),ne=u.namedNode(Ne+"imports"),_e=u.namedNode(se+"broader"),qe=u.namedNode(se+"narrower"),K=u.namedNode(d+"NodeShape"),ye=u.namedNode(d+"IRI"),X=u.namedNode(d+"property"),ie=u.namedNode(d+"class");u.namedNode(d+"node");const G=u.namedNode(d+"targetClass"),ke=u.namedNode(d+"nodeKind"),Fe=u.namedNode(E+"string");function D(t,e,s=d,o){let n="";const i=Ve(t,e,s,o);return i&&(n=i.value),n}function Ve(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 Qe(t){t.querySelector(".editor")?.focus()}function P(t,e){return D(t,"prefLabel",se,e)||D(t,"label",z,e)||D(t,"name",Oe,e)}function we(t,e,s){const o=[];for(const n of t)o.push({value:n,label:P(e.getQuads(n,null,null,null),s),children:[]});return o}function J(t,e){for(const s in e)t=t.replace(e[s],"");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(g,t,i)));e.parent&&Se(t,e.parent,s,o,n)}function oe(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(g,t,T);s.push(...e.config.store.getSubjects(g,t,b)),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:P(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,_e,null))o.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,qe,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(...oe(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 V(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 Be(t,{remove:e=!1,ignoreErrors:s=!1}={}){const o={},n=s?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),i=t.getQuads(null,x+"rest",x+"nil",null),a=e?[...i]:[];return i.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,A=null,re=null,O=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"?A?c=n(p,"has multiple rdf:first arcs"):a.push(A=m):m.predicate.value===x+"rest"?re?c=n(p,"has multiple rdf:rest arcs"):a.push(re=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"?O?c=n(p,"has incoming rdf:rest arcs"):O=m:(f=m,h="object");A?l.unshift(A.object):c=n(p,"has no list head"),p=O&&O.subject}c?e=!1:f&&(o[f[h].value]=l)}),e&&t.removeQuads(a),o}const _={},H={},$={};async function Me(t){const e={store:new ee,importedUrls:[],importedClasses:[],atts:t},s=[];if(t.shapes?s.push(L(Q(t.shapes),e,T)):t.shapesUrl&&s.push(L(q(t.shapesUrl,e.atts.proxy),e,T)),t.values?s.push(L(Q(t.values),e,b)):t.valuesUrl&&s.push(L(q(t.valuesUrl,e.atts.proxy),e,b)),await Promise.all(s),t.valuesSubject&&e.store.countQuads(null,null,null,T)===0){const o=[...e.store.getObjects(t.valuesSubject,g,b),...e.store.getObjects(t.valuesSubject,F,b)],n=[];for(const i of o){const a=Ee(i.value);a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(L(q(a,e.atts.proxy),e,T)))}try{await Promise.allSettled(n)}catch(i){console.warn(i)}}return e.store}async function L(t,e,s){const o=await t,n=[];for(const i of o){let a=s;if(e.atts.valuesSubject&&b.equals(s)&&i.graph.id&&i.graph.id!==e.atts.valuesSubject&&(a=i.graph),e.store.add(new ge(i.subject,i.predicate,i.object,a)),ne.equals(i.predicate)&&e.atts.loadOwlImports){const r=Ee(i.object.value);r&&e.importedUrls.indexOf(r)<0&&(e.importedUrls.push(r),n.push(L(q(r,e.atts.proxy),e,u.namedNode(r))))}if(e.atts.classInstanceProvider&&(ie.equals(i.predicate)||G.equals(i.predicate))){const r=i.object.value;if(e.importedClasses.indexOf(r)<0){let l;r in H?l=H[r]:(l=e.atts.classInstanceProvider(r),H[r]=l),e.importedClasses.push(r),n.push(L(Q(await l),e,T))}}}await Promise.allSettled(n)}async function q(t,e){return t in _||(_[t]=new Promise(async(s,o)=>{try{let n=t;e&&(n=e+encodeURIComponent(t));const i=await fetch(n,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(a=>a.text());s(await Q(i))}catch(n){o(n)}})),_[t]}async function Q(t){if(he(t)==="json")try{t=await Pe.toRDF(JSON.parse(t),{format:"application/n-quads"})}catch(s){console.error(s)}const e=[];return await new Promise((s,o)=>{const n=he(t)==="xml"?new $e:new Ie;n.on("data",i=>{e.push(new ge(i.subject,i.predicate,i.object,i.graph))}).on("error",i=>{o(i)}).on("prefix",(i,a)=>{i&&($[i]=a)}).on("end",()=>{s(null)}),n.write(t),n.end()}),e}function Ee(t){if(Y(t))return t;const e=t.split(":");if(e.length===2){const s=$[e[0]];if(s&&(t=t.replace(`${e[0]}:`,s),Y(t)))return t}return null}function he(t){return/^\s*\{/.test(t)?"json":/^\s*<\?xml/.test(t)?"xml":"ttl"}const ze={[`${d}name`]:(t,e)=>{const s=e;t.name=V(t.config.languages,t.name,s)},[`${d}description`]:(t,e)=>{const s=e;t.description=V(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"},[`${Ae}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)},[ne.id]:(t,e)=>{t.owlImports.add(e)},[ie.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 fe{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 j(t){return Math.max(t.minCount||0,t.qualifiedMinCount||0)}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)ze[s.predicate.id]?.call(t,t,s.object);return t.label=t.name?.value||P(e,t.config.languages),t.label||(t.label=t.path?J(t.path,$):"unknown"),t}function xe(t,e){const s=e,o=t;for(const n in e)n!=="parent"&&n!=="config"&&n!=="id"&&s[n]!==void 0&&s[n]!==""&&(Array.isArray(s[n])?o[n].push(...s[n]):s[n]instanceof Set&&s[n].size?o[n]=new Set([...o[n],...s[n]]):o[n]=s[n])}function Le(t,e,s){const o=document.createElement("div");o.classList.add("shacl-or-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),h=[];let v="";for(const p of f){const w=s.getPropertyTemplate(p,e.template),C=new B(w,e);h.push(C),v+=(v.length>1?" / ":"")+C.template.label}i.push(h),n.push({label:v,value:c.toString()})}else{const f=t[c],h=s.getPropertyTemplate(f,e.template),v=new B(h,e);i.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=i[parseInt(l.value)];let f;c.length&&(f=c[0],o.replaceWith(c[0]));for(let h=1;h<c.length;h++)f.after(c[h]),f=c[h]}},o.appendChild(r)}else{const i=[];for(let l=0;l<t.length;l++){const c=s.store.getQuads(t[l],null,null,null);c.length&&(i.push(c),n.push({label:P(c,s.languages)||J(c[0].predicate.value,$)+" = "+J(c[0].object.value,$),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=ae(Ce(e.template),i[parseInt(r.value)]);o.replaceWith(k(l,void 0,!0))}},o.appendChild(a)}return o}function Ge(t,e,s){if(e instanceof S){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,g,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(ie)){for(const r of o)if(a.object.equals(r))return i}}else if(a.predicate.equals(ke)&&a.object.equals(ye))return i}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Ue(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 Ke=`form { display:block; --label-width: 8em; --caret-size: 10px; }
|
|
1
|
+
import{DataFactory as u,Store as ee,Quad as ge,StreamParser as je,Literal as S,NamedNode as R,Writer as $e}from"n3";import{RdfXmlParser as Pe}from"rdfxml-streaming-parser";import Re from"jsonld";import{RokitCollapsible as te,RokitSelect as be,RokitButton as De,RokitInput as U,RokitTextArea as Ne}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#",x="http://www.w3.org/1999/02/22-rdf-syntax-ns#",z="http://www.w3.org/2000/01/rdf-schema#",se="http://www.w3.org/2004/02/skos/core#",Ae="http://www.w3.org/2002/07/owl#",Oe="http://www.w3.org/ns/oa#",me="http://purl.org/dc/terms/",_e="http://xmlns.com/foaf/0.1/",T=u.namedNode("loaded-shapes"),b=u.namedNode("loaded-data"),g=u.namedNode(x+"type"),ve=u.namedNode(x+"langString"),F=u.namedNode(me+"conformsTo"),ue=u.namedNode(z+"subClassOf"),ne=u.namedNode(Ae+"imports"),qe=u.namedNode(se+"broader"),ke=u.namedNode(se+"narrower"),K=u.namedNode(d+"NodeShape"),ye=u.namedNode(d+"IRI"),X=u.namedNode(d+"property"),ie=u.namedNode(d+"class");u.namedNode(d+"node");const G=u.namedNode(d+"targetClass"),Fe=u.namedNode(d+"nodeKind"),Ve=u.namedNode(E+"string");function D(t,e,s=d,o){let n="";const i=Qe(t,e,s,o);return i&&(n=i.value),n}function Qe(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 Be(t){t.querySelector(".editor")?.focus()}function P(t,e){return D(t,"prefLabel",se,e)||D(t,"label",z,e)||D(t,"name",_e,e)}function we(t,e,s){const o=[];for(const n of t)o.push({value:n,label:P(e.getQuads(n,null,null,null),s),children:[]});return o}function J(t,e){for(const s in e)t=t.replace(e[s],"");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(g,t,i)));e.parent&&Se(t,e.parent,s,o,n)}function oe(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(g,t,T);s.push(...e.config.store.getSubjects(g,t,b)),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:P(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,ke,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(...oe(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 V(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 Me(t,{remove:e=!1,ignoreErrors:s=!1}={}){const o={},n=s?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),i=t.getQuads(null,x+"rest",x+"nil",null),a=e?[...i]:[];return i.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,A=null,re=null,O=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"?A?c=n(p,"has multiple rdf:first arcs"):a.push(A=m):m.predicate.value===x+"rest"?re?c=n(p,"has multiple rdf:rest arcs"):a.push(re=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"?O?c=n(p,"has incoming rdf:rest arcs"):O=m:(f=m,h="object");A?l.unshift(A.object):c=n(p,"has no list head"),p=O&&O.subject}c?e=!1:f&&(o[f[h].value]=l)}),e&&t.removeQuads(a),o}const _={},H={},$={};async function ze(t){const e={store:new ee,importedUrls:[],importedClasses:[],atts:t},s=[];if(t.shapes?s.push(L(Q(t.shapes),e,T)):t.shapesUrl&&s.push(L(q(t.shapesUrl,e.atts.proxy),e,T)),t.values?s.push(L(Q(t.values),e,b)):t.valuesUrl&&s.push(L(q(t.valuesUrl,e.atts.proxy),e,b)),await Promise.all(s),t.valuesSubject&&e.store.countQuads(null,null,null,T)===0){const o=[...e.store.getObjects(t.valuesSubject,g,b),...e.store.getObjects(t.valuesSubject,F,b)],n=[];for(const i of o){const a=Ee(i.value);a&&e.importedUrls.indexOf(a)<0&&(e.importedUrls.push(a),n.push(L(q(a,e.atts.proxy),e,T)))}try{await Promise.allSettled(n)}catch(i){console.warn(i)}}return e.store}async function L(t,e,s){const o=await t,n=[];for(const i of o){let a=s;if(e.atts.valuesSubject&&b.equals(s)&&i.graph.id&&i.graph.id!==e.atts.valuesSubject&&(a=i.graph),e.store.add(new ge(i.subject,i.predicate,i.object,a)),ne.equals(i.predicate)&&e.atts.loadOwlImports){const r=Ee(i.object.value);r&&e.importedUrls.indexOf(r)<0&&(e.importedUrls.push(r),n.push(L(q(r,e.atts.proxy),e,u.namedNode(r))))}if(e.atts.classInstanceProvider&&(ie.equals(i.predicate)||G.equals(i.predicate))){const r=i.object.value;if(e.importedClasses.indexOf(r)<0){let l;r in H?l=H[r]:(l=e.atts.classInstanceProvider(r),H[r]=l),e.importedClasses.push(r),n.push(L(Q(await l),e,T))}}}await Promise.allSettled(n)}async function q(t,e){return t in _||(_[t]=new Promise(async(s,o)=>{try{let n=t;e&&(n=e+encodeURIComponent(t));const i=await fetch(n,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(a=>a.text());s(await Q(i))}catch(n){o(n)}})),_[t]}async function Q(t){if(he(t)==="json")try{t=await Re.toRDF(JSON.parse(t),{format:"application/n-quads"})}catch(s){console.error(s)}const e=[];return await new Promise((s,o)=>{const n=he(t)==="xml"?new Pe:new je;n.on("data",i=>{e.push(new ge(i.subject,i.predicate,i.object,i.graph))}).on("error",i=>{o(i)}).on("prefix",(i,a)=>{i&&($[i]=a)}).on("end",()=>{s(null)}),n.write(t),n.end()}),e}function Ee(t){if(Y(t))return t;const e=t.split(":");if(e.length===2){const s=$[e[0]];if(s&&(t=t.replace(`${e[0]}:`,s),Y(t)))return t}return null}function he(t){return/^\s*\{/.test(t)?"json":/^\s*<\?xml/.test(t)?"xml":"ttl"}const Ge={[`${d}name`]:(t,e)=>{const s=e;t.name=V(t.config.languages,t.name,s)},[`${d}description`]:(t,e)=>{const s=e;t.description=V(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"},[`${Oe}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)},[ne.id]:(t,e)=>{t.owlImports.add(e)},[ie.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 fe{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 j(t){return Math.max(t.minCount||0,t.qualifiedMinCount||0)}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)Ge[s.predicate.id]?.call(t,t,s.object);return t.label=t.name?.value||P(e,t.config.languages),t.label||(t.label=t.path?J(t.path,$):"unknown"),t}function xe(t,e){const s=e,o=t;for(const n in e)n!=="parent"&&n!=="config"&&n!=="id"&&s[n]!==void 0&&s[n]!==""&&(Array.isArray(s[n])?o[n].push(...s[n]):s[n]instanceof Set&&s[n].size?o[n]=new Set([...o[n],...s[n]]):o[n]=s[n])}function Le(t,e,s){const o=document.createElement("div");o.classList.add("shacl-or-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),h=[];let v="";for(const p of f){const w=s.getPropertyTemplate(p,e.template),C=new B(w,e);h.push(C),v+=(v.length>1?" / ":"")+C.template.label}i.push(h),n.push({label:v,value:c.toString()})}else{const f=t[c],h=s.getPropertyTemplate(f,e.template),v=new B(h,e);i.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=i[parseInt(l.value)];let f;c.length&&(f=c[0],o.replaceWith(c[0]));for(let h=1;h<c.length;h++)f.after(c[h]),f=c[h]}},o.appendChild(r)}else{const i=[];for(let l=0;l<t.length;l++){const c=s.store.getQuads(t[l],null,null,null);c.length&&(i.push(c),n.push({label:P(c,s.languages)||J(c[0].predicate.value,$)+" = "+J(c[0].object.value,$),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=ae(Ce(e.template),i[parseInt(r.value)]);o.replaceWith(k(l,void 0,!0))}},o.appendChild(a)}return o}function Ue(t,e,s){if(e instanceof S){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,g,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(ie)){for(const r of o)if(a.object.equals(r))return i}}else if(a.predicate.equals(Fe)&&a.object.equals(ye))return i}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Ke(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 He=`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; }
|
|
@@ -51,7 +51,7 @@ h3 { margin-top: 0; }
|
|
|
51
51
|
.ref-link:hover { text-decoration: underline; }
|
|
52
52
|
.node-id-display { color: #999; font-size: 11px; }
|
|
53
53
|
/* hierarchy colors */
|
|
54
|
-
.remove-button-wrapper { padding: 0 1px 0 calc(1px + var(--hierarchy-color-width)); align-self: stretch; position: relative; }
|
|
54
|
+
.remove-button-wrapper { --hierarchy-color-width: 3px; padding: 0 1px 0 calc(1px + var(--hierarchy-color-width)); align-self: stretch; position: relative; }
|
|
55
55
|
.remove-button-wrapper.colorize::before {
|
|
56
56
|
content: '';
|
|
57
57
|
position: absolute;
|
|
@@ -60,19 +60,20 @@ h3 { margin-top: 0; }
|
|
|
60
60
|
--index: mod(var(--hierarchy-level), var(--hierarchy-colors-length));
|
|
61
61
|
background: linear-gradient(var(--hierarchy-colors)) no-repeat 0 calc(var(--index) * 100% / (var(--hierarchy-colors-length) - 1)) / 100% calc(1px * infinity);
|
|
62
62
|
}
|
|
63
|
+
.remove-button-wrapper:not(:has(.remove-button)) { padding-left: calc(8px + var(--hierarchy-color-width)) }
|
|
63
64
|
.property-instance:not(:has(shacl-node)) > .remove-button-wrapper.colorize::before { background: 0; }
|
|
64
|
-
`;class
|
|
65
|
-
`+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 R){const c=o.config.store.getQuads(a,null,null,null);if(c.length){const f=P(c,o.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 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 We(t,e,s){if(s){const o=j(t)>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,e,o,oe(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 S&&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 Xe(t,e,s){if(e==="application/ld+json")return Je(t);{const o=new je({format:e,prefixes:s});o.addQuads(t);let n="";return o.end((i,a)=>{i&&console.error(i),n=a}),n}}function Je(t){const e=[];for(const s of t){const o={"@id":s.subject.id};if(s.predicate===g)o["@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},o[s.predicate.value]=n}e.push(o)}return JSON.stringify(e)}function Ye(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 R&&Fe.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=u.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 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 N={};function Ze(t){t.predicate===void 0&&t.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',t):N[`${t.predicate}^${t.datatype}`]=t}function et(){return Object.entries(N).map(t=>t[1])}function tt(t,e){let s=N[`${t}^${e}`];return s||(s=N[`${t}^undefined`],s)?s:N[`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 B 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 o=new te;o.classList.add("collapsible","shacl-group"),o.open=e.config.attributes.collapse==="open",o.label=this.template.label,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.addButton=this.createAddButton(),this.container.appendChild(this.addButton),this.addEventListener("change",()=>{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:b);s&&(n=await this.filterValidValues(n,e));for(const i of n)this.parent.linked||this.template.config.store.delete(i),this.addPropertyInstance(i.object),this.template.hasValue&&i.object.equals(this.template.hasValue)&&(o=!0)}this.template.config.editMode&&(this.template.hasValue&&!o&&!this.parent.linked&&this.addPropertyInstance(this.template.hasValue),this.updateControls())}}addPropertyInstance(e){let s;if(this.template.or?.length||this.template.xone?.length){const o=this.template.or?.length?this.template.or:this.template.xone;let n=!1;if(e){const i=Ge(o,e,this.template.config);if(i.length){const a=ae(Ce(this.template),i);s=k(a,e,!0),n=!0}}n||(s=Le(o,this,this.template.config),Te(s,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else{let o=!1;if(e&&!(e instanceof S)){const n=this.getRdfClassToLinkOrCreate();n&&this.template.config.store.countQuads(e,g,n,b)===0&&(o=!0)}s=k(this.template,e,void 0,o||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||j(this.template)>0)&&(this.addPropertyInstance(),e=this.instanceCount());let s;j(this.template)>0?s=e>j(this.template):s=this.template.nodeShapes.size>0||e>1;const o=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",s),this.classList.toggle("may-add",o)}instanceCount(){return this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length}toRDF(e,s){const o=u.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 for(const i of n.querySelectorAll(":scope > .editor")){const a=Ye(i);a&&e.addQuad(s,o,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 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=[];for(const r of i.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 be;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=[],o=this.getRdfClassToLinkOrCreate();if(o&&(s=oe(o,this.template)),s.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",n=>{e.blur();const i=this.addPropertyInstance();i.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Qe(i),i.classList.remove("fadeIn")},200)});else{const n=document.createElement("ul"),i=document.createElement("li");i.innerHTML="+ Create new "+this.template.label+"...",i.dataset.value="new",i.classList.add("large"),n.appendChild(i);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(k(this.template,l,!0,!0),e)}e.value=""})}return e}}function k(t,e,s=!1,o=!1){let n;if(t.nodeShapes.size){n=document.createElement("div"),n.classList.add("property-instance");for(const i of t.nodeShapes)n.appendChild(new I(i,e,t.nodeKind,t.label,o));o&&(s=!0)}else{const i=tt(t.path,t.datatype?.value);i?t.config.editMode&&!o?n=i.createEditor(t,e):n=i.createViewer(t,e):n=We(t,e||null,t.config.editMode&&!o),n.childNodes.length>0&&n.classList.add("property-instance"),o&&n.classList.add("linked")}return t.config.editMode&&(!o||s)&&Te(n,t.label,t.config.theme.dense,t.config.hierarchyColorsStyleSheet!==void 0,s),n.dataset.path=t.path,n}function Te(t,e,s,o,n=!1){const i=document.createElement("div");i.className="remove-button-wrapper",o&&i.classList.add("colorize");const a=new Re;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"),i.appendChild(a),t.appendChild(i)}window.customElements.define("shacl-property",B);function st(t,e){let s=t;const o=e.store.getQuads(t,null,null,null),n=D(o,"label",z,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;else{i=document.createElement("div");const r=document.createElement("h1");r.innerText=s,i.appendChild(r)}i.dataset.subject=t,i.classList.add("shacl-group");const a=D(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;let a=s;a||(!o&&e.nodeKind&&(o=e.nodeKind),o===void 0&&e.config.attributes.valuesNamespace||o?.value===`${d}IRI`?a=u.namedNode(e.config.attributes.valuesNamespace+le()):a=u.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=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,c.length>1);for(const l of e.extendedShapes)this.prepend(new I(l,s,void 0,void 0,i));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,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,g,this.template.targetClass,this.template.config.valuesGraphId),o&&e.addQuad(s,u.namedNode(o),this.template.id,this.template.config.valuesGraphId)}return s}async addPropertyInstance(e,s,o){let n=this;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let a=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);a||(a=st(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 B(e,this);await i.bindValues(s,o),(e.config.editMode||i.instanceCount()>0)&&(n.appendChild(i),i.updateControls())}async tryResolve(e,s,o){let n=!1;if(s){const i=Ue(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(Le(e,this,o))}}window.customElements.define("shacl-node",I);const nt=`
|
|
65
|
+
`;class We{constructor(e){this.dense=!0;let s=He;e&&(s+=`
|
|
66
|
+
`+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 R){const c=o.config.store.getQuads(a,null,null,null);if(c.length){const f=P(c,o.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 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 Xe(t,e,s){if(s){const o=j(t)>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,e,o,oe(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 S&&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 Je(t,e,s){if(e==="application/ld+json")return Ye(t);{const o=new $e({format:e,prefixes:s});o.addQuads(t);let n="";return o.end((i,a)=>{i&&console.error(i),n=a}),n}}function Ye(t){const e=[];for(const s of t){const o={"@id":s.subject.id};if(s.predicate===g)o["@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},o[s.predicate.value]=n}e.push(o)}return JSON.stringify(e)}function Ze(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 R&&Ve.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=u.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 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 N={};function et(t){t.predicate===void 0&&t.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',t):N[`${t.predicate}^${t.datatype}`]=t}function tt(){return Object.entries(N).map(t=>t[1])}function st(t,e){let s=N[`${t}^${e}`];return s||(s=N[`${t}^undefined`],s)?s:N[`undefined^${e}`]}class vt{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 B 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 o=new te;o.classList.add("collapsible","shacl-group"),o.open=e.config.attributes.collapse==="open",o.label=this.template.label,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.addButton=this.createAddButton(),this.container.appendChild(this.addButton),this.addEventListener("change",()=>{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:b);s&&(n=await this.filterValidValues(n,e));for(const i of n)this.parent.linked||this.template.config.store.delete(i),this.addPropertyInstance(i.object),this.template.hasValue&&i.object.equals(this.template.hasValue)&&(o=!0)}this.template.config.editMode&&(this.template.hasValue&&!o&&!this.parent.linked&&this.addPropertyInstance(this.template.hasValue),this.updateControls())}}addPropertyInstance(e){let s;if(this.template.or?.length||this.template.xone?.length){const o=this.template.or?.length?this.template.or:this.template.xone;let n=!1;if(e){const i=Ue(o,e,this.template.config);if(i.length){const a=ae(Ce(this.template),i);s=k(a,e,!0),n=!0}}n||(s=Le(o,this,this.template.config),Te(s,"",this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else{let o=!1;if(e&&!(e instanceof S)){const n=this.getRdfClassToLinkOrCreate();n&&this.template.config.store.countQuads(e,g,n,b)===0&&(o=!0)}s=k(this.template,e,void 0,o||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||j(this.template)>0)&&(this.addPropertyInstance(),e=this.instanceCount());let s;j(this.template)>0?s=e>j(this.template):s=this.template.nodeShapes.size>0||e>1;const o=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",s),this.classList.toggle("may-add",o)}instanceCount(){return this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length}toRDF(e,s){const o=u.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 for(const i of n.querySelectorAll(":scope > .editor")){const a=Ze(i);a&&e.addQuad(s,o,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 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=[];for(const r of i.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 be;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=[],o=this.getRdfClassToLinkOrCreate();if(o&&(s=oe(o,this.template)),s.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",n=>{e.blur();const i=this.addPropertyInstance();i.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Be(i),i.classList.remove("fadeIn")},200)});else{const n=document.createElement("ul"),i=document.createElement("li");i.innerHTML="+ Create new "+this.template.label+"...",i.dataset.value="new",i.classList.add("large"),n.appendChild(i);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(k(this.template,l,!0,!0),e)}e.value=""})}return e}}function k(t,e,s=!1,o=!1){let n;if(t.nodeShapes.size){n=document.createElement("div"),n.classList.add("property-instance");for(const i of t.nodeShapes)n.appendChild(new I(i,e,t.nodeKind,t.label,o));o&&(s=!0)}else{const i=st(t.path,t.datatype?.value);i?t.config.editMode&&!o?n=i.createEditor(t,e):n=i.createViewer(t,e):n=Xe(t,e||null,t.config.editMode&&!o),n.childNodes.length>0&&n.classList.add("property-instance"),o&&n.classList.add("linked")}return t.config.editMode&&(!o||s)?Te(n,t.label,t.config.theme.dense,t.config.hierarchyColorsStyleSheet!==void 0,s):!t.config.editMode&&t.config.hierarchyColorsStyleSheet!==void 0&&n.appendChild(Ie(!0)),n.dataset.path=t.path,n}function Te(t,e,s,o,n=!1){const i=Ie(o),a=new De;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"),i.appendChild(a),t.appendChild(i)}function Ie(t){const e=document.createElement("div");return e.className="remove-button-wrapper",t&&e.classList.add("colorize"),e}window.customElements.define("shacl-property",B);function nt(t,e){let s=t;const o=e.store.getQuads(t,null,null,null),n=D(o,"label",z,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;else{i=document.createElement("div");const r=document.createElement("h1");r.innerText=s,i.appendChild(r)}i.dataset.subject=t,i.classList.add("shacl-group");const a=D(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;let a=s;a||(!o&&e.nodeKind&&(o=e.nodeKind),o===void 0&&e.config.attributes.valuesNamespace||o?.value===`${d}IRI`?a=u.namedNode(e.config.attributes.valuesNamespace+le()):a=u.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=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,c.length>1);for(const l of e.extendedShapes)this.prepend(new I(l,s,void 0,void 0,i));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,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,g,this.template.targetClass,this.template.config.valuesGraphId),o&&e.addQuad(s,u.namedNode(o),this.template.id,this.template.config.valuesGraphId)}return s}async addPropertyInstance(e,s,o){let n=this;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let a=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);a||(a=nt(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 B(e,this);await i.bindValues(s,o),(e.config.editMode||i.instanceCount()>0)&&(n.appendChild(i),i.updateControls())}async tryResolve(e,s,o){let n=!1;if(s){const i=Ke(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(Le(e,this,o))}}window.customElements.define("shacl-node",I);const it=`
|
|
66
67
|
.editor:not([type='checkbox']) { border: 1px solid #DDD; }
|
|
67
68
|
.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; }
|
|
68
69
|
.property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
|
|
69
70
|
.mode-edit .property-instance label { width: var(--label-width); }
|
|
70
|
-
`;class
|
|
71
|
-
`+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 fe?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}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 fe(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=
|
|
71
|
+
`;class ot extends We{constructor(e){super(e||it),this.idCtr=0}createDefaultTemplate(e,s,o,n,i){if(n.id=`e${this.idCtr++}`,n.classList.add("editor"),i?.datatype?n.shaclDatatype=i.datatype:s instanceof S&&(n.shaclDatatype=s.datatype),i&&j(i)>0&&(n.dataset.minCount=String(j(i))),i?.class&&(n.dataset.class=i.class.value),i?.nodeKind)n.dataset.nodeKind=i.nodeKind.value;else if(s&&(s instanceof R||i?.nodeKind?.equals(ye))&&(n.dataset.nodeKind=d+"IRI",i)){const c=P(i.config.store.getQuads(s,null,null,null),i.config.languages);c&&(n.dataset.value="<"+s.value+">",s=u.literal(c))}(i?.hasValue&&s||i?.readonly)&&(n.disabled=!0),n.value=s?.value||i?.defaultValue?.value||"";const a=document.createElement("label");a.htmlFor=n.id,a.innerText=e,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.appendChild(a),l.appendChild(n),l}createDateEditor(e,s,o,n){const i=new U;n.datatype?.value===E+"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===E+"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 Ne,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.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),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 S&&(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!==E+"integer"&&(i.step="0.1"),this.createDefaultTemplate(e,s,o,i,n)}createListEditor(e,s,o,n,i){const a=new be;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=(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),s&&(a.value=s.id,s instanceof R&&(a.value="<"+a.value+">")),r}createButton(e,s){const o=document.createElement("rokit-button");return o.innerHTML=e,o}}const at={[`${d}node`]:(t,e)=>{t.extendedShapes.add(new M(e,t.config,t))},[`${d}and`]:(t,e)=>{for(const s of t.config.lists[e.value])t.extendedShapes.add(new M(s,t.config,t))},[`${d}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?xe(n,s):o.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]},[ne.id]:(t,e)=>{t.owlImports.add(e)},[`${me}title`]:(t,e)=>{const s=e;t.label=V(t.config.languages,t.label,s)},[`${z}label`]:(t,e)=>{const s=e;t.label=V(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),rt(this,this.config.store.getQuads(e,null,null,null))}}function rt(t,e){for(const s of e)at[s.predicate.id]?.call(t,t,s.object);return t}function lt(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],xe(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=F.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense="true"}}const ct="#4c93d785, #f85e9a85, #00327385, #87001f85";class pe{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:u}),this.form=e,this._theme=new ot,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 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=u.namedNode(s.valuesGraph)),s.hierarchyColors!=null){const o=s.hierarchyColors.length?s.hierarchyColors:ct;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+`
|
|
72
|
+
`+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 fe?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}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 fe(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 ce(e,{details:!0,factory:u})}}const dt=50;class ut extends HTMLElement{constructor(){super(),this.shape=null,this.attachShadow({mode:"open"}),this.form=document.createElement("form"),this.config=new pe(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 pe.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 ze({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 tt())n.stylesheet&&s.push(n.stylesheet);this.shadowRoot.adoptedStyleSheets=s;const o=new M(e,this.config);for(const n of this.config.nodeTemplates)lt(n);if(this.shape=new I(o,this.config.attributes.valuesSubject?u.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.addEventListener("click",i=>{i.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"))},dt)}serialize(e="text/turtle",s=this.toRDF()){const o=s.getQuads(null,null,null,null);return Je(o,e,$)}toRDF(e=new ee){return this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),e}registerPlugin(e){et(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 o of s.results)if(o.focusNode?.ptrs?.length)for(const n of o.focusNode.ptrs){const i=n._term;if(o.path?.length){const a=o.path[0].predicates[0];let r=this.form.querySelectorAll(`
|
|
72
73
|
:scope shacl-node[data-node-id='${i.id}'] > shacl-property > .property-instance[data-path='${a.id}'] > .editor,
|
|
73
74
|
:scope shacl-node[data-node-id='${i.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${a.id}'] > .editor,
|
|
74
75
|
:scope shacl-node[data-node-id='${i.id}'] > .shacl-group > shacl-property > .property-instance[data-path='${a.id}'] > .editor,
|
|
75
76
|
:scope shacl-node[data-node-id='${i.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[data-path='${a.id}'] > .editor`);r.length===0&&(r=this.form.querySelectorAll(`
|
|
76
77
|
:scope [data-node-id='${i.id}'] > shacl-property > .property-instance[data-path='${a.id}'],
|
|
77
78
|
:scope [data-node-id='${i.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(o));do c instanceof te&&(c.open=!0),c=c.parentElement;while(c)}}else e||(l.classList.add("invalid"),l.classList.remove("valid"),l.appendChild(this.createValidationErrorDisplay(o,"node")))}else e||this.form.querySelector(`:scope [data-node-id='${i.id}']`)?.prepend(this.createValidationErrorDisplay(o,"node"))}return s}catch(s){return console.error(s),!1}}createValidationErrorDisplay(e,s){const o=document.createElement("span");if(o.classList.add("validation-error"),s&&o.classList.add(s),e)if(e.message?.length>0)for(const n of e.message)o.title+=n.value+`
|
|
78
|
-
`;else o.title=e.sourceConstraintComponent?.value;return o}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=u.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,g,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,b)>0){const s=u.namedNode(this.config.attributes.valuesSubject),o=[...this.config.store.getQuads(s,g,null,b),...this.config.store.getQuads(s,F,null,b)];if(o.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${g.id} nor ${F.id} statement`);else for(const i of o)if(this.config.store.getQuads(i.object,g,K,null).length>0)return i.object;const n=this.config.store.getObjects(s,g,b);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,g,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){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",
|
|
79
|
+
`;else o.title=e.sourceConstraintComponent?.value;return o}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){const e=u.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,g,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,b)>0){const s=u.namedNode(this.config.attributes.valuesSubject),o=[...this.config.store.getQuads(s,g,null,b),...this.config.store.getQuads(s,F,null,b)];if(o.length===0)console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${g.id} nor ${F.id} statement`);else for(const i of o)if(this.config.store.getQuads(i.object,g,K,null).length>0)return i.object;const n=this.config.store.getObjects(s,g,b);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,g,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){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",ut);export{pe as Config,ot as DefaultTheme,vt as Plugin,ut as ShaclForm,We as Theme,H as classesCache,P as findLabel,dt as initTimeout,ze as loadGraphs,$ as prefixes,Ge as propertyMappers,_ as rdfCache,et as registerPlugin};
|
|
@@ -2,6 +2,7 @@ import { Literal, NamedNode, Quad } from 'n3';
|
|
|
2
2
|
import { Term } from '@rdfjs/types';
|
|
3
3
|
import { Config } from './config';
|
|
4
4
|
import { ShaclNodeTemplate } from './node-template';
|
|
5
|
+
export declare const mappers: Record<string, (template: ShaclPropertyTemplate, term: Term) => void>;
|
|
5
6
|
export declare class ShaclPropertyTemplate {
|
|
6
7
|
label: string;
|
|
7
8
|
name: Literal | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulb-darmstadt/shacl-form",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "SHACL form generator",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"vite": "^7.3.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@ro-kit/ui-widgets": "^1.0.
|
|
64
|
+
"@ro-kit/ui-widgets": "^1.0.34",
|
|
65
65
|
"jsonld": "^8.3.3",
|
|
66
66
|
"leaflet": "^1.9.4",
|
|
67
67
|
"leaflet-editable": "^1.3.2",
|