@ulb-darmstadt/shacl-form 2.0.0-rc7 → 2.0.0-rc9
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 +75 -75
- package/dist/config.d.ts +6 -1
- package/dist/index.js +11 -11
- package/dist/node-template.d.ts +19 -0
- package/dist/node.d.ts +6 -8
- package/dist/plugins/leaflet.js +3 -3
- package/dist/property-template.d.ts +13 -11
- package/dist/property.d.ts +2 -2
- package/dist/theme.default.d.ts +1 -1
- package/package.json +3 -2
package/dist/config.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Term } from '@rdfjs/types';
|
|
|
3
3
|
import { ClassInstanceProvider } from './plugin';
|
|
4
4
|
import { Loader } from './loader';
|
|
5
5
|
import { Theme } from './theme';
|
|
6
|
+
import { ShaclNodeTemplate } from './node-template';
|
|
7
|
+
import { ShaclPropertyTemplate } from './property-template';
|
|
6
8
|
export declare class ElementAttributes {
|
|
7
9
|
shapes: string | null;
|
|
8
10
|
shapesUrl: string | null;
|
|
@@ -34,13 +36,16 @@ export declare class Config {
|
|
|
34
36
|
editMode: boolean;
|
|
35
37
|
languages: string[];
|
|
36
38
|
lists: Record<string, Term[]>;
|
|
37
|
-
groups:
|
|
39
|
+
groups: string[];
|
|
38
40
|
theme: Theme;
|
|
39
41
|
form: HTMLElement;
|
|
40
42
|
renderedNodes: Set<string>;
|
|
41
43
|
valuesGraphId: NamedNode | undefined;
|
|
44
|
+
nodeShapes: Record<string, ShaclNodeTemplate>;
|
|
45
|
+
propertyShapes: Record<string, ShaclPropertyTemplate>;
|
|
42
46
|
private _store;
|
|
43
47
|
constructor(theme: Theme, form: HTMLElement);
|
|
48
|
+
reset(): void;
|
|
44
49
|
updateAttributes(elem: HTMLElement): void;
|
|
45
50
|
static dataAttributes(): Array<string>;
|
|
46
51
|
get store(): Store;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{DataFactory as f,Literal as C,NamedNode as N,Writer as ue,Store as H,StreamParser as he,Quad as ae}from"n3";import{RokitCollapsible as k,RokitSelect as oe,RokitButton as fe,RokitInput as q,RokitTextArea as pe}from"@ro-kit/ui-widgets";import{v4 as Z}from"uuid";import{RdfXmlParser as ge}from"rdfxml-streaming-parser";import{toRDF as me}from"jsonld";import{Validator as be}from"shacl-engine";const h="http://www.w3.org/ns/shacl#",ee="http://datashapes.org/dash#",x="http://www.w3.org/2001/XMLSchema#",E="http://www.w3.org/1999/02/22-rdf-syntax-ns#",X="http://www.w3.org/2000/01/rdf-schema#",W="http://www.w3.org/2004/02/skos/core#",ve="http://www.w3.org/2002/07/owl#",ye="http://www.w3.org/ns/oa#",we="http://purl.org/dc/terms/",Ee="http://xmlns.com/foaf/0.1/",L=f.namedNode("loaded-shapes"),w=f.namedNode("loaded-data"),m=f.namedNode(E+"type"),B=f.namedNode(we+"conformsTo"),te=f.namedNode(X+"subClassOf"),z=f.namedNode(ve+"imports"),xe=f.namedNode(W+"broader"),Se=f.namedNode(W+"narrower"),A=f.namedNode(h+"NodeShape"),Ce=f.namedNode(h+"IRI"),F=f.namedNode(h+"property"),K=f.namedNode(h+"class"),Ie=f.namedNode(h+"node"),I=f.namedNode(h+"targetClass"),Le=f.namedNode(h+"nodeKind");f.namedNode(x+"string");function j(s,e,t=h,n){let i="";const a=je(s,e,t,n);return a&&(i=a.value),i}function je(s,e,t=h,n){let i;const a=t+e;if(n?.length){for(const o of n)for(const l of s)if(l.predicate.value===a){if(l.object.id.endsWith(`@${o}`))return l.object;l.object.id.indexOf("@")<0?i=l.object:i||(i=l.object)}}else for(const o of s)if(o.predicate.value===a)return o.object;return i}function Re(s){s.querySelector(".editor")?.focus()}function D(s,e){return j(s,"prefLabel",W,e)||j(s,"label",X,e)||j(s,"name",Ee,e)}function le(s,e,t){const n=[];for(const i of s)n.push({value:i,label:D(e.getQuads(i,null,null,null),t),children:[]});return n}function U(s,e){for(const t in e)s=s.replace(e[t],"");return s}function re(s,e,t,n,i=new Set){for(const a of e.owlImports)i.has(a.id)||(i.add(a.id),n.push(...t.getSubjects(m,s,a)));e.parent&&re(s,e.parent,t,n,i)}function J(s,e){if(e.shaclIn){const t=e.config.lists[e.shaclIn];return le(t?.length?t:[],e.config.store,e.config.languages)}else{const t=e.config.store.getSubjects(m,s,L);t.push(...e.config.store.getSubjects(m,s,w)),re(s,e,e.config.store,t);const n=new Map,i=new Map;for(const o of t)n.set(o.id,{value:o,label:D(e.config.store.getQuads(o,null,null,null),e.config.languages),children:[]});for(const o of t){for(const l of e.config.store.getObjects(o,xe,null))n.has(l.id)&&i.set(o.id,l.id);for(const l of e.config.store.getObjects(o,Se,null))n.has(l.id)&&i.set(l.id,o.id);for(const l of e.config.store.getObjects(o,te,null))n.has(l.id)&&i.set(o.id,l.id)}for(const[o,l]of i.entries())n.get(l)?.children?.push(n.get(o));const a=[];for(const[o,l]of n.entries())i.has(o)||a.push(l);for(const o of e.config.store.getSubjects(te,s,null))a.push(...J(o,e));return a}}function G(s){let e;try{e=new URL(s)}catch{return!1}return e.protocol==="http:"||e.protocol==="https:"}function se(s,e,t){if(e===void 0)return t;if(t===void 0)return e;const n=s.indexOf(e.language);if(n<0)return t;const i=s.indexOf(t.language);return i<0||i>n?e:t}function De(s,{remove:e=!1,ignoreErrors:t=!1}={}){const n={},i=t?(()=>!0):((l,c)=>{throw new Error(`${l.value} ${c}`)}),a=s.getQuads(null,E+"rest",E+"nil",null),o=e?[...a]:[];return a.forEach(l=>{const c=[];let d=!1,r,u;const g=l.graph;let p=l.subject;for(;p&&!d;){const v=s.getQuads(null,null,p,null),$=s.getQuads(p,null,null,null).filter(y=>!y.predicate.equals(m));let b,O=null,Y=null,T=null;for(let y=0;y<$.length&&!d;y++)b=$[y],b.graph.equals(g)?r?d=i(p,"has non-list arcs out"):b.predicate.value===E+"first"?O?d=i(p,"has multiple rdf:first arcs"):o.push(O=b):b.predicate.value===E+"rest"?Y?d=i(p,"has multiple rdf:rest arcs"):o.push(Y=b):v.length?d=i(p,"can't be subject and object"):(r=b,u="subject"):d=i(p,"not confined to single graph");for(let y=0;y<v.length&&!d;++y)b=v[y],r?d=i(p,"can't have coreferences"):b.predicate.value===E+"rest"?T?d=i(p,"has incoming rdf:rest arcs"):T=b:(r=b,u="object");O?c.unshift(O.object):d=i(p,"has no list head"),p=T&&T.subject}d?e=!1:r&&(n[r[u].value]=c)}),e&&s.removeQuads(o),n}function ce(s,e,t){const n=document.createElement("div");n.classList.add("shacl-or-constraint");const i=[];if(e instanceof S){const a=[];let o=!1;s.length&&(o=t.store.countQuads(s[0],F,null,null)>0);for(let d=0;d<s.length;d++)if(o){const r=t.store.getObjects(s[d],F,null),u=[];let g="";for(const p of r){const v=new _(p,e,t);u.push(v),g+=(g.length>1?" / ":"")+v.template.label}a.push(u),i.push({label:g,value:d.toString()})}else{const r=new _(s[d],e,t);a.push([r]),i.push({label:r.template.label,value:d.toString()})}const l=t.theme.createListEditor("Please choose",null,!1,i),c=l.querySelector(".editor");c.onchange=()=>{if(c.value){const d=a[parseInt(c.value)];let r;d.length&&(r=d[0],n.replaceWith(d[0]));for(let u=1;u<d.length;u++)r.after(d[u]),r=d[u]}},n.appendChild(l)}else{const a=[];for(let c=0;c<s.length;c++){const d=t.store.getQuads(s[c],null,null,null);d.length&&(a.push(d),i.push({label:D(d,t.languages)||U(d[0].predicate.value,t.prefixes)+" = "+U(d[0].object.value,t.prefixes),value:c.toString()}))}const o=t.theme.createListEditor(e.template.label+"?",null,!1,i,e.template),l=o.querySelector(".editor");l.onchange=()=>{l.value&&n.replaceWith(P(e.template.clone().merge(a[parseInt(l.value)]),void 0,!0))},n.appendChild(o)}return n}function $e(s,e,t){if(e instanceof C){const n=e.datatype;for(const i of s){const a=t.store.getQuads(i,null,null,null);for(const o of a)if(o.predicate.value===`${h}datatype`&&o.object.equals(n))return a}}else{const n=t.store.getObjects(e,m,null);for(const i of s){const a=t.store.getQuads(i,null,null,null);for(const o of a)if(n.length>0){if(o.predicate.value===`${h}node`){for(const l of n)if(t.store.getQuads(o.object,I,l,null).length>0)return a}if(o.predicate.equals(K)){for(const l of n)if(o.object.equals(l))return a}}else if(o.predicate.equals(Le)&&o.object.equals(Ce))return a}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Oe(s,e,t){for(const n of s){let i=!1;const a=t.store.getObjects(n,F,null);for(const o of a){const l=t.store.getObjects(o,`${h}path`,null);for(const c of l)if(i=t.store.countQuads(e,c,null,null)>0,i)break}if(i)return a}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const Te={[`${h}name`]:(s,e)=>{const t=e;s.name=se(s.config.languages,s.name,t)},[`${h}description`]:(s,e)=>{const t=e;s.description=se(s.config.languages,s.description,t)},[`${h}path`]:(s,e)=>{s.path=e.value},[`${h}node`]:(s,e)=>{s.node=e},[`${h}datatype`]:(s,e)=>{s.datatype=e},[`${h}nodeKind`]:(s,e)=>{s.nodeKind=e},[`${h}minCount`]:(s,e)=>{s.minCount=parseInt(e.value)},[`${h}maxCount`]:(s,e)=>{s.maxCount=parseInt(e.value)},[`${h}minLength`]:(s,e)=>{s.minLength=parseInt(e.value)},[`${h}maxLength`]:(s,e)=>{s.maxLength=parseInt(e.value)},[`${h}minInclusive`]:(s,e)=>{s.minInclusive=parseInt(e.value)},[`${h}maxInclusive`]:(s,e)=>{s.maxInclusive=parseInt(e.value)},[`${h}minExclusive`]:(s,e)=>{s.minExclusive=parseInt(e.value)},[`${h}maxExclusive`]:(s,e)=>{s.maxExclusive=parseInt(e.value)},[`${h}pattern`]:(s,e)=>{s.pattern=e.value},[`${h}order`]:(s,e)=>{s.order=parseInt(e.value)},[`${ee}singleLine`]:(s,e)=>{s.singleLine=e.value==="true"},[`${ee}readonly`]:(s,e)=>{s.readonly=e.value==="true"},[`${ye}styleClass`]:(s,e)=>{s.cssClass=e.value},[`${h}and`]:(s,e)=>{s.shaclAnd=e.value},[`${h}in`]:(s,e)=>{s.shaclIn=e.value},[`${h}languageIn`]:(s,e)=>{s.languageIn=s.config.lists[e.value],s.datatype=f.namedNode(E+"langString")},[`${h}defaultValue`]:(s,e)=>{s.defaultValue=e},[`${h}hasValue`]:(s,e)=>{s.hasValue=e},[`${h}qualifiedValueShape`]:(s,e)=>{s.qualifiedValueShape=e},[`${h}qualifiedMinCount`]:(s,e)=>{s.minCount=parseInt(e.value)},[`${h}qualifiedMaxCount`]:(s,e)=>{s.maxCount=parseInt(e.value)},[z.id]:(s,e)=>{s.owlImports.push(e)},[K.id]:(s,e)=>{s.class=e;const t=s.config.store.getSubjects(I,e,null);t.length>0&&(s.node=t[0])},[`${h}or`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.shaclOr=t:console.error("list for sh:or not found:",e.value,"existing lists:",s.config.lists)},[`${h}xone`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.shaclXone=t:console.error("list for sh:xone not found:",e.value,"existing lists:",s.config.lists)}};class Ae{constructor(e,t,n){this.label="",this.owlImports=[],this.extendedShapes=[],this.parent=t,this.config=n,this.merge(e),this.qualifiedValueShape&&this.merge(n.store.getQuads(this.qualifiedValueShape,null,null,null))}merge(e){for(const t of e)Te[t.predicate.id]?.call(this,this,t.object);if(this.label=this.name?.value||D(e,this.config.languages),!this.label&&!this.shaclAnd&&(this.label=this.path?U(this.path,this.config.prefixes):"unknown"),this.node&&this.extendedShapes.push(this.node),this.shaclAnd){const t=this.config.lists[this.shaclAnd];if(t?.length)for(const n of t)this.extendedShapes.push(n)}return this}clone(){const e=Object.assign({},this);return e.extendedShapes=[...this.extendedShapes],e.owlImports=[...this.owlImports],this.languageIn&&(e.languageIn=[...this.languageIn]),this.shaclOr&&(e.shaclOr=[...this.shaclOr]),this.shaclXone&&(e.shaclXone=[...this.shaclXone]),e.merge=this.merge.bind(e),e.clone=this.clone.bind(e),e}}const Ne=`form { display:block; --label-width: 8em; --caret-size: 10px; }
|
|
1
|
+
import{DataFactory as f,Literal as C,NamedNode as N,Writer as be,Store as W,StreamParser as me,Quad as le}from"n3";import{RokitCollapsible as k,RokitSelect as ce,RokitButton as ve,RokitInput as q,RokitTextArea as ye}from"@ro-kit/ui-widgets";import{v4 as se}from"uuid";import{RdfXmlParser as we}from"rdfxml-streaming-parser";import{toRDF as Se}from"jsonld";import{Validator as xe}from"shacl-engine";const u="http://www.w3.org/ns/shacl#",ne="http://datashapes.org/dash#",x="http://www.w3.org/2001/XMLSchema#",S="http://www.w3.org/1999/02/22-rdf-syntax-ns#",K="http://www.w3.org/2000/01/rdf-schema#",X="http://www.w3.org/2004/02/skos/core#",Ee="http://www.w3.org/2002/07/owl#",Ce="http://www.w3.org/ns/oa#",Le="http://purl.org/dc/terms/",Ie="http://xmlns.com/foaf/0.1/",j=f.namedNode("loaded-shapes"),y=f.namedNode("loaded-data"),g=f.namedNode(S+"type"),B=f.namedNode(Le+"conformsTo"),ie=f.namedNode(K+"subClassOf"),J=f.namedNode(Ee+"imports"),je=f.namedNode(X+"broader"),Re=f.namedNode(X+"narrower"),A=f.namedNode(u+"NodeShape"),$e=f.namedNode(u+"IRI"),z=f.namedNode(u+"property"),Y=f.namedNode(u+"class");f.namedNode(u+"node");const _=f.namedNode(u+"targetClass"),De=f.namedNode(u+"nodeKind");f.namedNode(x+"string");function R(s,e,t=u,i){let n="";const o=Te(s,e,t,i);return o&&(n=o.value),n}function Te(s,e,t=u,i){let n;const o=t+e;if(i?.length){for(const a of i)for(const r of s)if(r.predicate.value===o){if(r.object.id.endsWith(`@${a}`))return r.object;r.object.id.indexOf("@")<0?n=r.object:n||(n=r.object)}}else for(const a of s)if(a.predicate.value===o)return a.object;return n}function Oe(s){s.querySelector(".editor")?.focus()}function D(s,e){return R(s,"prefLabel",X,e)||R(s,"label",K,e)||R(s,"name",Ie,e)}function de(s,e,t){const i=[];for(const n of s)i.push({value:n,label:D(e.getQuads(n,null,null,null),t),children:[]});return i}function U(s,e){for(const t in e)s=s.replace(e[t],"");return s}function ue(s,e,t,i,n=new Set){for(const o of e.owlImports)n.has(o.id)||(n.add(o.id),i.push(...t.getSubjects(g,s,o)));e.parent&&ue(s,e.parent,t,i,n)}function Z(s,e){if(e.in){const t=e.config.lists[e.in];return de(t?.length?t:[],e.config.store,e.config.languages)}else{const t=e.config.store.getSubjects(g,s,j);t.push(...e.config.store.getSubjects(g,s,y)),ue(s,e,e.config.store,t);const i=new Map,n=new Map;for(const a of t)i.set(a.id,{value:a,label:D(e.config.store.getQuads(a,null,null,null),e.config.languages),children:[]});for(const a of t){for(const r of e.config.store.getObjects(a,je,null))i.has(r.id)&&n.set(a.id,r.id);for(const r of e.config.store.getObjects(a,Re,null))i.has(r.id)&&n.set(r.id,a.id);for(const r of e.config.store.getObjects(a,ie,null))i.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())i.get(r)?.children?.push(i.get(a));const o=[];for(const[a,r]of i.entries())n.has(a)||o.push(r);for(const a of e.config.store.getSubjects(ie,s,null))o.push(...Z(a,e));return o}}function G(s){let e;try{e=new URL(s)}catch{return!1}return e.protocol==="http:"||e.protocol==="https:"}function oe(s,e,t){if(e===void 0)return t;if(t===void 0)return e;const i=s.indexOf(e.language);if(i<0)return t;const n=s.indexOf(t.language);return n<0||n>i?e:t}function Ae(s,{remove:e=!1,ignoreErrors:t=!1}={}){const i={},n=t?(()=>!0):((r,l)=>{throw new Error(`${r.value} ${l}`)}),o=s.getQuads(null,S+"rest",S+"nil",null),a=e?[...o]:[];return o.forEach(r=>{const l=[];let c=!1,d,h;const b=r.graph;let p=r.subject;for(;p&&!c;){const w=s.getQuads(null,null,p,null),E=s.getQuads(p,null,null,null).filter(v=>!v.predicate.equals(g));let m,T=null,te=null,O=null;for(let v=0;v<E.length&&!c;v++)m=E[v],m.graph.equals(b)?d?c=n(p,"has non-list arcs out"):m.predicate.value===S+"first"?T?c=n(p,"has multiple rdf:first arcs"):a.push(T=m):m.predicate.value===S+"rest"?te?c=n(p,"has multiple rdf:rest arcs"):a.push(te=m):w.length?c=n(p,"can't be subject and object"):(d=m,h="subject"):c=n(p,"not confined to single graph");for(let v=0;v<w.length&&!c;++v)m=w[v],d?c=n(p,"can't have coreferences"):m.predicate.value===S+"rest"?O?c=n(p,"has incoming rdf:rest arcs"):O=m:(d=m,h="object");T?l.unshift(T.object):c=n(p,"has no list head"),p=O&&O.subject}c?e=!1:d&&(i[d[h].value]=l)}),e&&s.removeQuads(a),i}const Ne={[`${u}node`]:(s,e)=>{s.extendedShapes.add(s.config.nodeShapes[e.value]||new I(e,s.config,s))},[`${u}and`]:(s,e)=>{for(const t of s.config.lists[e.value])s.extendedShapes.add(s.config.nodeShapes[t.value]||new I(t,s.config,s))},[`${u}property`]:(s,e)=>{const t=s.config.propertyShapes[e.value]||new H(e,s);if(t.path){let i=s.properties[t.path];i||(i=[],s.properties[t.path]=i),i.push(t)}},[`${u}nodeKind`]:(s,e)=>{s.nodeKind=e},[`${u}targetClass`]:(s,e)=>{s.targetClass=e},[`${u}or`]:(s,e)=>{s.or=s.config.lists[e.value]},[`${u}xone`]:(s,e)=>{s.xone=s.config.lists[e.value]},[J.id]:(s,e)=>{s.owlImports.add(e)}};class I{constructor(e,t,i){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.id=e,this.config=t,this.parent=i,t.nodeShapes[e.value]=this,Pe(this,t.store.getQuads(e,null,null,null))}}function Pe(s,e){for(const t of e)Ne[t.predicate.id]?.call(s,s,t.object);return s}function ke(s){const e={};he(s,e);for(const[t,i]of Object.entries(e))if(i.length>1){let n=!1,o=!0;for(const a of i)n=n||a.maxCount===1,o=o&&a.qualifiedValueShape===void 0;if(n&&o){const a=i[i.length-1];for(let r=i.length-2;r>=0;r--){const l=i[r];delete l.parent.properties[t],_e(a,l)}}}}function he(s,e,t=new WeakSet){if(!t.has(s.id)){t.add(s.id);for(const[i,n]of Object.entries(s.properties)){let o=e[i];o||(o=[],e[i]=o),o.push(...n)}for(const i of s.extendedShapes)he(i,e,t)}}const Fe={[`${u}name`]:(s,e)=>{const t=e;s.name=oe(s.config.languages,s.name,t)},[`${u}description`]:(s,e)=>{const t=e;s.description=oe(s.config.languages,s.description,t)},[`${u}path`]:(s,e)=>{s.path=e.value},[`${u}node`]:(s,e)=>{s.node=e},[`${u}group`]:(s,e)=>{s.group=e.id},[`${u}datatype`]:(s,e)=>{s.datatype=e},[`${u}nodeKind`]:(s,e)=>{s.nodeKind=e},[`${u}minCount`]:(s,e)=>{s.minCount=parseInt(e.value)},[`${u}maxCount`]:(s,e)=>{s.maxCount=parseInt(e.value)},[`${u}minLength`]:(s,e)=>{s.minLength=parseInt(e.value)},[`${u}maxLength`]:(s,e)=>{s.maxLength=parseInt(e.value)},[`${u}minInclusive`]:(s,e)=>{s.minInclusive=parseInt(e.value)},[`${u}maxInclusive`]:(s,e)=>{s.maxInclusive=parseInt(e.value)},[`${u}minExclusive`]:(s,e)=>{s.minExclusive=parseInt(e.value)},[`${u}maxExclusive`]:(s,e)=>{s.maxExclusive=parseInt(e.value)},[`${u}pattern`]:(s,e)=>{s.pattern=e.value},[`${u}order`]:(s,e)=>{s.order=parseInt(e.value)},[`${ne}singleLine`]:(s,e)=>{s.singleLine=e.value==="true"},[`${ne}readonly`]:(s,e)=>{s.readonly=e.value==="true"},[`${Ce}styleClass`]:(s,e)=>{s.cssClass=e.value},[`${u}and`]:(s,e)=>{s.and=e.value},[`${u}in`]:(s,e)=>{s.in=e.value},[`${u}languageIn`]:(s,e)=>{s.languageIn=s.config.lists[e.value],s.datatype=f.namedNode(S+"langString")},[`${u}defaultValue`]:(s,e)=>{s.defaultValue=e},[`${u}hasValue`]:(s,e)=>{s.hasValue=e},[`${u}qualifiedValueShape`]:(s,e)=>{s.qualifiedValueShape=e,s.extendedShapes.add(s.config.nodeShapes[e.value]||new I(e,s.config))},[`${u}qualifiedMinCount`]:(s,e)=>{s.minCount=parseInt(e.value)},[`${u}qualifiedMaxCount`]:(s,e)=>{s.maxCount=parseInt(e.value)},[J.id]:(s,e)=>{s.owlImports.add(e)},[Y.id]:(s,e)=>{s.class=e;const t=s.config.store.getSubjects(_,e,null);t.length>0&&(s.node=t[0])},[`${u}or`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.or=t:console.error("list for sh:or not found:",e.value,"existing lists:",s.config.lists)},[`${u}xone`]:(s,e)=>{const t=s.config.lists[e.value];t?.length?s.xone=t:console.error("list for sh:xone not found:",e.value,"existing lists:",s.config.lists)}};class H{constructor(e,t){this.label="",this.extendedShapes=new Set,this.owlImports=new Set,this.parent=t,this.config=t.config,this.config.propertyShapes[e.value]=this,ee(this,this.config.store.getQuads(e,null,null,null))}}function fe(s){const e=Object.assign({},s);return e.extendedShapes=new Set(s.extendedShapes),e.owlImports=new Set(s.owlImports),s.languageIn&&(e.languageIn=[...s.languageIn]),s.or&&(e.or=[...s.or]),s.xone&&(e.xone=[...s.xone]),e}function ee(s,e){for(const t of e)Fe[t.predicate.id]?.call(s,s,t.object);if(s.label=s.name?.value||D(e,s.config.languages),!s.label&&!s.and&&(s.label=s.path?U(s.path,s.config.prefixes):"unknown"),s.node&&s.extendedShapes.add(s.config.nodeShapes[s.node.value]||new I(s.node,s.config)),s.and){const t=s.config.lists[s.and];if(t?.length)for(const i of t)s.extendedShapes.add(s.config.nodeShapes[i.value]||new I(i,s.config))}return s}function _e(s,e){const t=e,i=s;for(const n in e)n!=="parent"&&n!=="config"&&t[n]!==void 0&&t[n]!==""&&(Array.isArray(t[n])?i[n].push(...t[n]):t[n]instanceof Set&&t[n].size?i[n]=new Set([...i[n],...t[n]]):i[n]=t[n])}function pe(s,e,t){const i=document.createElement("div");i.classList.add("shacl-or-constraint");const n=[];if(e instanceof L){const o=[];let a=!1;s.length&&(a=t.store.countQuads(s[0],z,null,null)>0);for(let c=0;c<s.length;c++)if(a){const d=t.store.getObjects(s[c],z,null),h=[];let b="";for(const p of d){const w=t.propertyShapes[p.value]||new H(p,e.template),E=new F(w,e);h.push(E),b+=(b.length>1?" / ":"")+E.template.label}o.push(h),n.push({label:b,value:c.toString()})}else{const d=s[c],h=t.propertyShapes[d.value]||new H(d,e.template),b=new F(h,e);o.push([b]),n.push({label:b.template.label,value:c.toString()})}const r=t.theme.createListEditor("Please choose",null,!1,n),l=r.querySelector(".editor");l.onchange=()=>{if(l.value){const c=o[parseInt(l.value)];let d;c.length&&(d=c[0],i.replaceWith(c[0]));for(let h=1;h<c.length;h++)d.after(c[h]),d=c[h]}},i.appendChild(r)}else{const o=[];for(let l=0;l<s.length;l++){const c=t.store.getQuads(s[l],null,null,null);c.length&&(o.push(c),n.push({label:D(c,t.languages)||U(c[0].predicate.value,t.prefixes)+" = "+U(c[0].object.value,t.prefixes),value:l.toString()}))}const a=t.theme.createListEditor(e.template.label+"?",null,!1,n,e.template),r=a.querySelector(".editor");r.onchange=()=>{if(r.value){const l=ee(fe(e.template),o[parseInt(r.value)]);i.replaceWith(P(l,void 0,!0))}},i.appendChild(a)}return i}function qe(s,e,t){if(e instanceof C){const i=e.datatype;for(const n of s){const o=t.store.getQuads(n,null,null,null);for(const a of o)if(a.predicate.value===`${u}datatype`&&a.object.equals(i))return o}}else{const i=t.store.getObjects(e,g,null);for(const n of s){const o=t.store.getQuads(n,null,null,null);for(const a of o)if(i.length>0){if(a.predicate.value===`${u}node`){for(const r of i)if(t.store.getQuads(a.object,_,r,null).length>0)return o}if(a.predicate.equals(Y)){for(const r of i)if(a.object.equals(r))return o}}else if(a.predicate.equals(De)&&a.object.equals($e))return o}}return console.error("couldn't resolve sh:or/sh:xone on property for value",e),[]}function Qe(s,e,t){for(const i of s){let n=!1;const o=t.store.getObjects(i,z,null);for(const a of o){const r=t.store.getObjects(a,`${u}path`,null);for(const l of r)if(n=t.store.countQuads(e,l,null,null)>0,n)break}if(n)return o}return console.error("couldn't resolve sh:or/sh:xone on node for value",e),[]}const Ve=`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; }
|
|
@@ -46,17 +46,17 @@ a, a:visited { color: inherit; }
|
|
|
46
46
|
.collapsible > .property-instance > shacl-node > h1 { display: none; }
|
|
47
47
|
.ref-link { cursor: pointer; }
|
|
48
48
|
.ref-link:hover { text-decoration: underline; }
|
|
49
|
-
.node-id-display { color: #999; font-size: 11px; }`;class
|
|
50
|
-
`+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}createViewer(e,t,n){const i=document.createElement("div"),a=document.createElement("label");a.innerHTML=e+":",n.description&&a.setAttribute("title",n.description.value),i.appendChild(a);let o=t.value,l=null;if(t instanceof N){const d=n.config.store.getQuads(o,null,null,null);if(d.length){const r=D(d,n.config.languages);r&&(o=r)}}else t instanceof C&&(t.language?(l=document.createElement("span"),l.classList.add("lang"),l.innerText=`@${t.language}`):t.datatype.value===`${x}date`?o=new Date(Date.parse(t.value)).toDateString():t.datatype.value===`${x}dateTime`&&(o=new Date(Date.parse(t.value)).toLocaleString()));let c;return G(t.value)?(c=document.createElement("a"),c.setAttribute("href",t.value)):c=document.createElement("div"),c.classList.add("d-flex"),c.innerText=o,l&&c.appendChild(l),i.appendChild(c),i}}function ke(s,e,t){if(t){const n=s.minCount!==void 0&&s.minCount>0;if(s.class)return s.config.theme.createListEditor(s.label,e,n,J(s.class,s),s);if(s.shaclIn){const i=s.config.lists[s.shaclIn];if(i?.length){const a=le(i,s.config.store,s.config.languages);return s.config.theme.createListEditor(s.label,e,n,a,s)}else console.error("list not found:",s.shaclIn,"existing lists:",s.config.lists)}if(s.datatype?.value===`${E}langString`||s.languageIn?.length)return s.config.theme.createLangStringEditor(s.label,e,n,s);switch(s.datatype?.value.replace(x,"")){case"integer":case"float":case"double":case"decimal":return s.config.theme.createNumberEditor(s.label,e,n,s);case"date":case"dateTime":return s.config.theme.createDateEditor(s.label,e,n,s);case"boolean":return s.config.theme.createBooleanEditor(s.label,e,n,s);case"base64Binary":return s.config.theme.createFileEditor(s.label,e,n,s)}return s.config.theme.createTextEditor(s.label,e,n,s)}else{if(e)return s.config.theme.createViewer(s.label,e,s);const n=document.createElement("div");return n.innerHTML="No value",n}}function Fe(s,e,t){if(e==="application/ld+json")return _e(s);{const n=new ue({format:e,prefixes:t});n.addQuads(s);let i="";return n.end((a,o)=>{a&&console.error(a),i=o}),i}}function _e(s){const e=[];for(const t of s){const n={"@id":t.subject.id};if(t.predicate===m)n["@type"]=t.object.id;else{let i=t.object.value;t.object instanceof C?t.object.language?i={"@language":t.object.language,"@value":t.object.value}:t.object.datatype&&t.object.datatype.value!==`${x}#string`&&(i={"@type":t.object.datatype.value,"@value":t.object.value}):i={"@id":t.object.id},n[t.predicate.value]=i}e.push(n)}return JSON.stringify(e)}function qe(s){let e=s.shaclDatatype,t=s.value;if(t){if(t.startsWith("<")&&t.endsWith(">")&&t.indexOf(":")>-1)return f.namedNode(t.substring(1,t.length-1));if(s.dataset.class||s.dataset.nodeKind===h+"IRI")return f.namedNode(t);if(s.dataset.link)return JSON.parse(s.dataset.link);if(s.dataset.lang?e=s.dataset.lang:s.type==="number"?t=parseFloat(t):s.type==="file"&&s.binaryData?t=s.binaryData:s.type==="datetime-local"&&(t=new Date(t).toISOString().slice(0,19)),!e&&typeof t=="string"){let n=t.split("^^");n.length===2&&n[0].startsWith('"')&&n[0].endsWith('"')&&n[1].split(":").length===2?(t=n[0].substring(1,n[0].length-1),e=f.namedNode(n[1])):(n=t.split("@"),n.length===2&&n[0].startsWith('"')&&n[0].endsWith('"')?(t=n[0].substring(1,n[0].length-1),e=n[1]):t.startsWith('"')&&t.endsWith('"')&&(t=t.substring(1,t.length-1)))}return f.literal(t,e)}else if((s.type==="checkbox"||s.getAttribute("type")==="checkbox")&&(s.checked||parseInt(s.dataset.minCount||"0")>0))return f.literal(s.checked?"true":"false",e)}const R={};function Qe(s){s.predicate===void 0&&s.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',s):R[`${s.predicate}^${s.datatype}`]=s}function Ve(){return Object.entries(R).map(s=>s[1])}function Me(s,e){let t=R[`${s}^${e}`];return t||(t=R[`${s}^undefined`],t)?t:R[`undefined^${e}`]}class et{constructor(e,t){this.predicate=e.predicate,this.datatype=e.datatype,t&&(this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t))}createViewer(e,t){return e.config.theme.createViewer(e.label,t,e)}}class _ extends HTMLElement{constructor(e,t,n,i){if(super(),this.template=new Ae(n.store.getQuads(e,null,null,null),t,n),this.container=this,this.template.extendedShapes.length&&this.template.config.attributes.collapse!==null&&(!this.template.maxCount||this.template.maxCount>1)){const a=new k;a.classList.add("collapsible","shacl-group"),a.open=n.attributes.collapse==="open",a.label=this.template.label,this.container=a}if(this.template.order!==void 0&&(this.style.order=`${this.template.order}`),this.template.cssClass&&this.classList.add(this.template.cssClass),n.editMode&&!t.linked&&(this.addButton=this.createAddButton(),this.container.appendChild(this.addButton)),this.template.path){let a=[];i&&(t.linked?a=n.store.getQuads(i,this.template.path,null,null):a=n.store.getQuads(i,this.template.path,null,w));let o=!1;for(const l of a)this.isValueValid(l.object)&&(this.addPropertyInstance(l.object),this.template.hasValue&&l.object.equals(this.template.hasValue)&&(o=!0));n.editMode&&this.template.hasValue&&!o&&!t.linked&&this.addPropertyInstance(this.template.hasValue)}n.editMode&&!t.linked&&(this.addEventListener("change",()=>{this.updateControls()}),this.updateControls()),this.container instanceof k&&(n.editMode&&!t.linked||this.container.childElementCount>0)&&this.appendChild(this.container)}addPropertyInstance(e){let t;if(this.template.shaclOr?.length||this.template.shaclXone?.length){const n=this.template.shaclOr?.length?this.template.shaclOr:this.template.shaclXone;let i=!1;if(e){const a=$e(n,e,this.template.config);a.length&&(t=P(this.template.clone().merge(a),e,!0),i=!0)}i||(t=ce(n,this,this.template.config),de(t,""))}else{let n=!1;if(e&&!(e instanceof C)){const i=this.getRdfClassToLinkOrCreate();i&&this.template.config.store.countQuads(e,m,i,w)===0&&(n=!0)}t=P(this.template,e,void 0,n||this.template.parent.linked)}return this.addButton?this.container.insertBefore(t,this.addButton):this.container.appendChild(t),t}updateControls(){let e=this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node").length;e===0&&(!this.template.extendedShapes.length||this.template.minCount!==void 0&&this.template.minCount>0)&&(this.addPropertyInstance(),e=this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node").length);let t;this.template.minCount!==void 0?t=e>this.template.minCount:t=this.template.extendedShapes.length>0||e>1;const n=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",t),this.classList.toggle("may-add",n)}toRDF(e,t){for(const n of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance")){const i=f.namedNode(n.dataset.path);if(n.firstChild instanceof S){const a=n.firstChild.toRDF(e);e.addQuad(t,i,a,this.template.config.valuesGraphId)}else for(const a of n.querySelectorAll(":scope > .editor")){const o=qe(a);o&&e.addQuad(t,i,o,this.template.config.valuesGraphId)}}}getRdfClassToLinkOrCreate(){if(this.template.class&&this.template.node)return this.template.class;for(const e of this.template.extendedShapes){const t=this.template.config.store.getObjects(e,I,null);if(t.length>0)return t[0]}}isValueValid(e){if(!this.template.extendedShapes.length)return!0;for(const t of this.template.extendedShapes){const n=this.template.config.store.getObjects(t,I,null);for(const i of n)if(this.template.config.store.countQuads(e,m,i,null)>0)return!0}return!1}createAddButton(){const e=new oe;e.dense=!0,e.label="+ "+this.template.label,e.title="Add "+this.template.label,e.autoGrowLabelWidth=!0,e.classList.add("add-button");let t=[],n=this.getRdfClassToLinkOrCreate();if(n&&(t=J(n,this.template)),t.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",i=>{e.blur();const a=this.addPropertyInstance();a.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Re(a),a.classList.remove("fadeIn")},200)});else{const i=document.createElement("ul"),a=document.createElement("li");a.innerHTML="+ Create new "+this.template.label+"...",a.dataset.value="new",a.classList.add("large"),i.appendChild(a);const o=document.createElement("li");o.classList.add("divider"),i.appendChild(o);const l=document.createElement("li");l.classList.add("header"),l.innerText="Or link existing:",i.appendChild(l);for(const c of t){const d=document.createElement("li"),r=typeof c.value=="string"?c.value:c.value.value;d.innerText=c.label?c.label:r,d.dataset.value=JSON.stringify(c.value),i.appendChild(d)}e.appendChild(i),e.collapsibleWidth="250px",e.collapsibleOrientationLeft="",e.addEventListener("change",()=>{if(e.value==="new")this.addPropertyInstance();else{const c=JSON.parse(e.value);this.container.insertBefore(P(this.template,c,!0,!0),e)}e.value=""})}return e}}function P(s,e,t=!1,n=!1){let i;if(s.extendedShapes.length){i=document.createElement("div"),i.classList.add("property-instance");for(const a of s.extendedShapes)i.appendChild(new S(a,s.config,e,s.parent,s.nodeKind,s.label,n))}else{const a=Me(s.path,s.datatype?.value);a?s.config.editMode&&!n?i=a.createEditor(s,e):i=a.createViewer(s,e):i=ke(s,e||null,s.config.editMode&&!n),i.classList.add("property-instance"),n&&i.classList.add("linked")}return s.config.editMode&&de(i,s.label,t),i.dataset.path=s.path,i}function de(s,e,t=!1){const n=new fe;n.classList.add("remove-button","clear"),n.title="Remove "+e,n.dense=!0,n.icon=!0,n.addEventListener("click",i=>{s.classList.remove("fadeIn"),s.classList.add("fadeOut"),setTimeout(()=>{const a=s.parentElement;s.remove(),a?.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0}))},200)}),t&&n.classList.add("persistent"),s.appendChild(n)}window.customElements.define("shacl-property",_);function Be(s,e){let t=s;const n=e.store.getQuads(s,null,null,null),i=j(n,"label",X,e.languages);i&&(t=i);let a;if(e.attributes.collapse!==null)a=new k,a.classList.add("collapsible"),a.open=e.attributes.collapse==="open",a.label=t;else{a=document.createElement("div");const l=document.createElement("h1");l.innerText=t,a.appendChild(l)}a.dataset.subject=s,a.classList.add("shacl-group");const o=j(n,"order");return o&&(a.style.order=o),a}class S extends HTMLElement{constructor(e,t,n,i,a,o,l){super(),this.owlImports=[],this.parent=i,this.config=t,this.shaclSubject=e,this.linked=l||!1;let c=n;if(!c){if(!a){const r=t.store.getObjects(e,`${h}nodeKind`,null);r.length&&(a=r[0])}a===void 0&&t.attributes.valuesNamespace||a?.value===`${h}IRI`?c=f.namedNode(t.attributes.valuesNamespace+Z()):c=f.blankNode(Z())}this.nodeId=c;const d=JSON.stringify([e,n]);if(n&&t.renderedNodes.has(d)){o=o||"Link";const r=document.createElement("label");r.innerText=o,r.classList.add("linked"),this.appendChild(r);const u=document.createElement("a");let g=n.termType==="BlankNode"?"_:"+n.value:n.value;u.innerText=g,u.classList.add("ref-link"),u.onclick=()=>{this.config.form.querySelector(`shacl-node[data-node-id='${g}']`)?.scrollIntoView()},this.appendChild(u),this.style.flexDirection="row"}else{if(n&&t.renderedNodes.add(d),this.dataset.nodeId=this.nodeId.id,this.config.attributes.showNodeIds!==null){const r=document.createElement("div");r.innerText=`id: ${this.nodeId.id}`,r.classList.add("node-id-display"),this.appendChild(r)}for(const r of t.store.getQuads(e,z,null,null))this.owlImports.push(r.object);for(const r of t.store.getQuads(e,null,null,null))switch(r.predicate.id){case F.id:this.addPropertyInstance(r.object,t,n);break;case`${h}and`:const u=t.lists[r.object.value];if(u?.length)for(const g of u)this.prepend(new S(g,t,n,this));else console.error("list not found:",r.object.value,"existing lists:",t.lists);break;case Ie.id:this.prepend(new S(r.object,t,n,this));break;case`${h}targetClass`:this.targetClass=r.object;break;case`${h}or`:this.tryResolve(r.object,n,t);break;case`${h}xone`:this.tryResolve(r.object,n,t);break}if(o){const r=document.createElement("h1");r.innerText=o,this.prepend(r)}}}toRDF(e,t){if(t||(t=this.nodeId),!this.linked){for(const n of this.querySelectorAll(":scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property"))n.toRDF(e,t);this.targetClass&&e.addQuad(t,m,this.targetClass,this.config.valuesGraphId),this.config.attributes.generateNodeShapeReference&&!this.parent&&e.addQuad(t,f.namedNode(this.config.attributes.generateNodeShapeReference),this.shaclSubject,this.config.valuesGraphId)}return t}addPropertyInstance(e,t,n){let i=this;const a=t.store.getQuads(e,`${h}group`,null,null);if(a.length>0){const l=a[0].object.value;if(t.groups.indexOf(l)>-1){let c=this.querySelector(`:scope > .shacl-group[data-subject='${l}']`);c||(c=Be(l,t),this.appendChild(c)),i=c}else console.warn("ignoring unknown group reference",a[0],"existing groups:",t.groups)}const o=new _(e,this,t,n);o.childElementCount>0&&i.appendChild(o)}tryResolve(e,t,n){const i=n.lists[e.value];if(i?.length){let a=!1;if(t){const o=Oe(i,t,n);if(o.length){for(const l of o)this.addPropertyInstance(l,n,t);a=!0}}a||this.appendChild(ce(i,this,n))}else console.error("list for sh:or/sh:xone not found:",e,"existing lists:",n.lists)}}window.customElements.define("shacl-node",S);const Q={},V={};class Ue{constructor(e){this.loadedExternalUrls=[],this.loadedClasses=[],this.config=e}async loadGraphs(){this.loadedExternalUrls=[],this.loadedClasses=[],this.config.prefixes={};const e=[],t=new H;if(e.push(this.importRDF(this.config.attributes.shapes?this.config.attributes.shapes:this.config.attributes.shapesUrl?this.fetchRDF(this.config.attributes.shapesUrl):"",t,L)),e.push(this.importRDF(this.config.attributes.values?this.config.attributes.values:this.config.attributes.valuesUrl?this.fetchRDF(this.config.attributes.valuesUrl):"",t,w)),await Promise.all(e),t.countQuads(null,null,null,L)===0&&this.config.attributes.valuesSubject){const n=[...t.getObjects(this.config.attributes.valuesSubject,B,w)],i=[];for(const a of n){const o=this.toURL(a.value);o&&this.loadedExternalUrls.indexOf(o)<0&&(this.loadedExternalUrls.push(o),i.push(this.importRDF(this.fetchRDF(o),t,L)))}try{await Promise.allSettled(i)}catch(a){console.warn(a)}}this.config.store=t}async importRDF(e,t,n){const i=async a=>{const o=[];await new Promise((l,c)=>{const d=ne(a)==="xml"?new ge:new he;d.on("data",r=>{if(t.add(new ae(r.subject,r.predicate,r.object,n)),this.config.attributes.ignoreOwlImports===null&&z.equals(r.predicate)){const u=this.toURL(r.object.value);u&&this.loadedExternalUrls.indexOf(u)<0&&(this.loadedExternalUrls.push(u),o.push(this.importRDF(this.fetchRDF(u),t,f.namedNode(u))))}if(this.config.classInstanceProvider&&(K.equals(r.predicate)||I.equals(r.predicate))){const u=r.object.value;if(this.loadedClasses.indexOf(u)<0){let g;u in V?g=V[u]:(g=this.config.classInstanceProvider(u),V[u]=g),this.loadedClasses.push(u),o.push(this.importRDF(g,t,n))}}}).on("error",r=>{console.warn("failed parsing graph",n,r.message),c(r)}).on("prefix",(r,u)=>{r&&(this.config.prefixes[r]=u)}).on("end",()=>{l(null)}),d.write(a),d.end()});try{await Promise.allSettled(o)}catch(l){console.warn(l)}};if(e instanceof Promise&&(e=await e),e){if(ne(e)==="json")try{e=await me(JSON.parse(e),{format:"application/n-quads"})}catch(a){console.error(a)}await i(e)}}toURL(e){if(G(e))return e;if(this.config.prefixes){const t=e.split(":");if(t.length===2){const n=this.config.prefixes[t[0]];if(n&&(e=e.replace(`${t[0]}:`,n),G(e)))return e}}return null}async fetchRDF(e){if(e in Q)return Q[e];let t=e;this.config.attributes.proxy&&(t=this.config.attributes.proxy+encodeURIComponent(e));const n=fetch(t,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(i=>i.text());return Q[e]=n,n}}function ne(s){return/^\s*\{/.test(s)?"json":/^\s*<\?xml/.test(s)?"xml":"ttl"}class M{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.submitButton=null,this.generateNodeShapeReference=null,this.showNodeIds=null}}class ie{constructor(e,t){this.attributes=new M,this.loader=new Ue(this),this.prefixes={},this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new H,this.theme=e,this.form=t,this.languages=[...new Set(navigator.languages.flatMap(n=>n.length>2?[n.toLocaleLowerCase(),n.substring(0,2)]:n)),""]}updateAttributes(e){const t=new M;if(Object.keys(t).forEach(n=>{const i=e.dataset[n];i!==void 0&&(t[n]=i)}),this.editMode=t.view===null,this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){const n=this.languages.indexOf(t.language);n>-1&&this.languages.splice(n,1),this.languages.unshift(t.language)}t.valuesGraph&&(this.valuesGraphId=f.namedNode(t.valuesGraph))}static dataAttributes(){const e=new M;return Object.keys(e).map(t=>(t=t.replace(/[A-Z]/g,n=>"-"+n.toLowerCase()),"data-"+t))}get store(){return this._store}set store(e){this._store=e,this.lists=De(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(t=>{this.groups.push(t.id)},m,`${h}PropertyGroup`,null)}}const Ge=`
|
|
49
|
+
.node-id-display { color: #999; font-size: 11px; }`;class Me{constructor(e){let t=Ve;e&&(t+=`
|
|
50
|
+
`+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}createViewer(e,t,i){const n=document.createElement("div"),o=document.createElement("label");o.innerHTML=e+":",i.description&&o.setAttribute("title",i.description.value),n.appendChild(o);let a=t.value,r=null;if(t instanceof N){const c=i.config.store.getQuads(a,null,null,null);if(c.length){const d=D(c,i.config.languages);d&&(a=d)}}else t instanceof C&&(t.language?(r=document.createElement("span"),r.classList.add("lang"),r.innerText=`@${t.language}`):t.datatype.value===`${x}date`?a=new Date(Date.parse(t.value)).toDateString():t.datatype.value===`${x}dateTime`&&(a=new Date(Date.parse(t.value)).toLocaleString()));let l;return G(t.value)?(l=document.createElement("a"),l.setAttribute("href",t.value)):l=document.createElement("div"),l.classList.add("d-flex"),l.innerText=a,r&&l.appendChild(r),n.appendChild(l),n}}function Be(s,e,t){if(t){const i=s.minCount!==void 0&&s.minCount>0;if(s.class&&!s.hasValue)return s.config.theme.createListEditor(s.label,e,i,Z(s.class,s),s);if(s.in){const n=s.config.lists[s.in];if(n?.length){const o=de(n,s.config.store,s.config.languages);return s.config.theme.createListEditor(s.label,e,i,o,s)}else console.error("list not found:",s.in,"existing lists:",s.config.lists)}if(s.datatype?.value===`${S}langString`||s.languageIn?.length)return s.config.theme.createLangStringEditor(s.label,e,i,s);switch(s.datatype?.value.replace(x,"")){case"integer":case"float":case"double":case"decimal":return s.config.theme.createNumberEditor(s.label,e,i,s);case"date":case"dateTime":return s.config.theme.createDateEditor(s.label,e,i,s);case"boolean":return s.config.theme.createBooleanEditor(s.label,e,i,s);case"base64Binary":return s.config.theme.createFileEditor(s.label,e,i,s)}return s.config.theme.createTextEditor(s.label,e,i,s)}else{if(e)return s.config.theme.createViewer(s.label,e,s);const i=document.createElement("div");return i.innerHTML="No value",i}}function ze(s,e,t){if(e==="application/ld+json")return Ue(s);{const i=new be({format:e,prefixes:t});i.addQuads(s);let n="";return i.end((o,a)=>{o&&console.error(o),n=a}),n}}function Ue(s){const e=[];for(const t of s){const i={"@id":t.subject.id};if(t.predicate===g)i["@type"]=t.object.id;else{let n=t.object.value;t.object instanceof C?t.object.language?n={"@language":t.object.language,"@value":t.object.value}:t.object.datatype&&t.object.datatype.value!==`${x}#string`&&(n={"@type":t.object.datatype.value,"@value":t.object.value}):n={"@id":t.object.id},i[t.predicate.value]=n}e.push(i)}return JSON.stringify(e)}function Ge(s){let e=s.shaclDatatype,t=s.value;if(t){if(t.startsWith("<")&&t.endsWith(">")&&t.indexOf(":")>-1)return f.namedNode(t.substring(1,t.length-1));if(s.dataset.class||s.dataset.nodeKind===u+"IRI")return f.namedNode(t);if(s.dataset.link)return JSON.parse(s.dataset.link);if(s.dataset.lang?e=s.dataset.lang:s.type==="number"?t=parseFloat(t):s.type==="file"&&s.binaryData?t=s.binaryData:s.type==="datetime-local"&&(t=new Date(t).toISOString().slice(0,19)),!e&&typeof t=="string"){let i=t.split("^^");i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')&&i[1].split(":").length===2?(t=i[0].substring(1,i[0].length-1),e=f.namedNode(i[1])):(i=t.split("@"),i.length===2&&i[0].startsWith('"')&&i[0].endsWith('"')?(t=i[0].substring(1,i[0].length-1),e=i[1]):t.startsWith('"')&&t.endsWith('"')&&(t=t.substring(1,t.length-1)))}return f.literal(t,e)}else if((s.type==="checkbox"||s.getAttribute("type")==="checkbox")&&(s.checked||parseInt(s.dataset.minCount||"0")>0))return f.literal(s.checked?"true":"false",e)}const $={};function He(s){s.predicate===void 0&&s.datatype===void 0?console.warn('not registering plugin because it does neither define "predicate" nor "datatype"',s):$[`${s.predicate}^${s.datatype}`]=s}function We(){return Object.entries($).map(s=>s[1])}function Ke(s,e){let t=$[`${s}^${e}`];return t||(t=$[`${s}^undefined`],t)?t:$[`undefined^${e}`]}class rt{constructor(e,t){this.predicate=e.predicate,this.datatype=e.datatype,t&&(this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t))}createViewer(e,t){return e.config.theme.createViewer(e.label,t,e)}}class F extends HTMLElement{constructor(e,t,i){if(super(),this.template=e,this.parent=t,this.container=this,this.template.extendedShapes.size&&this.template.config.attributes.collapse!==null&&(!this.template.maxCount||this.template.maxCount>1)){const n=new k;n.classList.add("collapsible","shacl-group"),n.open=e.config.attributes.collapse==="open",n.label=this.template.label,this.container=n}if(this.template.order!==void 0&&(this.style.order=`${this.template.order}`),this.template.cssClass&&this.classList.add(this.template.cssClass),e.config.editMode&&!t.linked&&(this.addButton=this.createAddButton(),this.container.appendChild(this.addButton)),this.template.path){let n=[];i&&(t.linked?n=e.config.store.getQuads(i,this.template.path,null,null):n=e.config.store.getQuads(i,this.template.path,null,y));let o=!1;for(const a of n)this.isValueValid(a.object)&&(this.addPropertyInstance(a.object),this.template.hasValue&&a.object.equals(this.template.hasValue)&&(o=!0));e.config.editMode&&this.template.hasValue&&!o&&!t.linked&&this.addPropertyInstance(this.template.hasValue)}e.config.editMode&&!t.linked&&(this.addEventListener("change",()=>{this.updateControls()}),this.updateControls()),this.container instanceof k&&(e.config.editMode&&!t.linked||this.container.childElementCount>0)&&this.appendChild(this.container)}addPropertyInstance(e){let t;if(this.template.or?.length||this.template.xone?.length){const i=this.template.or?.length?this.template.or:this.template.xone;let n=!1;if(e){const o=qe(i,e,this.template.config);if(o.length){const a=ee(fe(this.template),o);t=P(a,e,!0),n=!0}}n||(t=pe(i,this,this.template.config),ge(t,""))}else{let i=!1;if(e&&!(e instanceof C)){const n=this.getRdfClassToLinkOrCreate();n&&this.template.config.store.countQuads(e,g,n,y)===0&&(i=!0)}t=P(this.template,e,void 0,i||this.parent.linked)}return this.addButton?this.container.insertBefore(t,this.addButton):this.container.appendChild(t),t}updateControls(){let e=this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length;e===0&&(this.template.extendedShapes.size===0||this.template.minCount!==void 0&&this.template.minCount>0)&&(this.addPropertyInstance(),e=this.querySelectorAll(":scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance").length);let t;this.template.minCount!==void 0?t=e>this.template.minCount:t=this.template.extendedShapes.size>0||e>1;const i=this.template.maxCount===void 0||e<this.template.maxCount;this.classList.toggle("may-remove",t),this.classList.toggle("may-add",i)}toRDF(e,t){for(const i of this.querySelectorAll(":scope > .property-instance, :scope > .collapsible > .property-instance")){const n=f.namedNode(i.dataset.path);if(i.firstChild instanceof L){const o=i.firstChild.toRDF(e);e.addQuad(t,n,o,this.template.config.valuesGraphId)}else for(const o of i.querySelectorAll(":scope > .editor")){const a=Ge(o);a&&e.addQuad(t,n,a,this.template.config.valuesGraphId)}}}getRdfClassToLinkOrCreate(){if(this.template.class&&this.template.extendedShapes.size)return this.template.class;for(const e of this.template.extendedShapes)if(e.targetClass)return e.targetClass}isValueValid(e){if(!this.template.extendedShapes.size)return!0;for(const t of this.template.extendedShapes)if(t.targetClass&&this.template.config.store.countQuads(e,g,t.targetClass,null)>0)return!0;return!1}createAddButton(){const e=new ce;e.dense=!0,e.label="+ "+this.template.label,e.title="Add "+this.template.label,e.autoGrowLabelWidth=!0,e.classList.add("add-button");let t=[],i=this.getRdfClassToLinkOrCreate();if(i&&(t=Z(i,this.template)),t.length===0)e.emptyMessage="",e.inputMinWidth=0,e.addEventListener("click",n=>{e.blur();const o=this.addPropertyInstance();o.classList.add("fadeIn"),this.updateControls(),setTimeout(()=>{Oe(o),o.classList.remove("fadeIn")},200)});else{const n=document.createElement("ul"),o=document.createElement("li");o.innerHTML="+ Create new "+this.template.label+"...",o.dataset.value="new",o.classList.add("large"),n.appendChild(o);const a=document.createElement("li");a.classList.add("divider"),n.appendChild(a);const r=document.createElement("li");r.classList.add("header"),r.innerText="Or link existing:",n.appendChild(r);for(const l of t){const c=document.createElement("li"),d=typeof l.value=="string"?l.value:l.value.value;c.innerText=l.label?l.label:d,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(P(this.template,l,!0,!0),e)}e.value=""})}return e}}function P(s,e,t=!1,i=!1){let n;if(s.extendedShapes.size){n=document.createElement("div"),n.classList.add("property-instance");for(const o of s.extendedShapes)n.appendChild(new L(o,e,s.nodeKind,s.label,i))}else{const o=Ke(s.path,s.datatype?.value);o?s.config.editMode&&!i?n=o.createEditor(s,e):n=o.createViewer(s,e):n=Be(s,e||null,s.config.editMode&&!i),n.classList.add("property-instance"),i&&n.classList.add("linked")}return s.config.editMode&&ge(n,s.label,t),n.dataset.path=s.path,n}function ge(s,e,t=!1){const i=new ve;i.classList.add("remove-button","clear"),i.title="Remove "+e,i.dense=!0,i.icon=!0,i.addEventListener("click",n=>{s.classList.remove("fadeIn"),s.classList.add("fadeOut"),setTimeout(()=>{const o=s.parentElement;s.remove(),o?.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0}))},200)}),t&&i.classList.add("persistent"),s.appendChild(i)}window.customElements.define("shacl-property",F);function Xe(s,e){let t=s;const i=e.store.getQuads(s,null,null,null),n=R(i,"label",K,e.languages);n&&(t=n);let o;if(e.attributes.collapse!==null)o=new k,o.classList.add("collapsible"),o.open=e.attributes.collapse==="open",o.label=t;else{o=document.createElement("div");const r=document.createElement("h1");r.innerText=t,o.appendChild(r)}o.dataset.subject=s,o.classList.add("shacl-group");const a=R(i,"order");return a&&(o.style.order=a),o}class L extends HTMLElement{constructor(e,t,i,n,o){super(),this.template=e,this.linked=o||!1;let a=t;a||(!i&&e.nodeKind&&(i=e.nodeKind),i===void 0&&e.config.attributes.valuesNamespace||i?.value===`${u}IRI`?a=f.namedNode(e.config.attributes.valuesNamespace+se()):a=f.blankNode(se())),this.nodeId=a;const r=JSON.stringify([e.id,t]);if(t&&e.config.renderedNodes.has(r)){n=n||"Link";const l=document.createElement("label");l.innerText=n,l.classList.add("linked"),this.appendChild(l);const c=document.createElement("a");let d=t.termType==="BlankNode"?"_:"+t.value:t.value;c.innerText=d,c.classList.add("ref-link"),c.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${d}']`)?.scrollIntoView()},this.appendChild(c),this.style.flexDirection="row"}else{if(t&&e.config.renderedNodes.add(r),this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){const l=document.createElement("div");l.innerText=`id: ${this.nodeId.id}`,l.classList.add("node-id-display"),this.appendChild(l)}for(const l of this.template.extendedShapes)this.prepend(new L(l,t));this.template.or?.length&&this.tryResolve(this.template.or,t,e.config),this.template.xone?.length&&this.tryResolve(this.template.xone,t,e.config);for(const[l,c]of Object.entries(this.template.properties))for(const d of c)this.addPropertyInstance(d,t);if(n){const l=document.createElement("h1");l.innerText=n,this.prepend(l)}}}toRDF(e,t){if(t||(t=this.nodeId),!this.linked){for(const i of this.querySelectorAll(":scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property"))i.toRDF(e,t);this.template.targetClass&&e.addQuad(t,g,this.template.targetClass,this.template.config.valuesGraphId),this.template.config.attributes.generateNodeShapeReference&&!this.template.parent&&e.addQuad(t,f.namedNode(this.template.config.attributes.generateNodeShapeReference),this.template.id,this.template.config.valuesGraphId)}return t}addPropertyInstance(e,t){let i=this;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let o=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);o||(o=Xe(e.group,e.config),this.appendChild(o)),i=o}else console.warn("ignoring unknown group reference",e.group,"existing groups:",e.config.groups);const n=new F(e,this,t);n.childElementCount>0&&i.appendChild(n)}tryResolve(e,t,i){let n=!1;if(t){const o=Qe(e,t,i);if(o.length){for(const a of o)this.addPropertyInstance(i.propertyShapes[a.value],t);n=!0}}n||this.appendChild(pe(e,this,i))}}window.customElements.define("shacl-node",L);const Q={},V={};class Je{constructor(e){this.loadedExternalUrls=[],this.loadedClasses=[],this.config=e}async loadGraphs(){this.loadedExternalUrls=[],this.loadedClasses=[];const e=[],t=new W;if(e.push(this.importRDF(this.config.attributes.shapes?this.config.attributes.shapes:this.config.attributes.shapesUrl?this.fetchRDF(this.config.attributes.shapesUrl):"",t,j)),e.push(this.importRDF(this.config.attributes.values?this.config.attributes.values:this.config.attributes.valuesUrl?this.fetchRDF(this.config.attributes.valuesUrl):"",t,y)),await Promise.all(e),t.countQuads(null,null,null,j)===0&&this.config.attributes.valuesSubject){const i=[...t.getObjects(this.config.attributes.valuesSubject,B,y)],n=[];for(const o of i){const a=this.toURL(o.value);a&&this.loadedExternalUrls.indexOf(a)<0&&(this.loadedExternalUrls.push(a),n.push(this.importRDF(this.fetchRDF(a),t,j)))}try{await Promise.allSettled(n)}catch(o){console.warn(o)}}this.config.store=t}async importRDF(e,t,i){const n=async o=>{const a=[];await new Promise((r,l)=>{const c=ae(o)==="xml"?new we:new me;c.on("data",d=>{if(t.add(new le(d.subject,d.predicate,d.object,i)),this.config.attributes.ignoreOwlImports===null&&J.equals(d.predicate)){const h=this.toURL(d.object.value);h&&this.loadedExternalUrls.indexOf(h)<0&&(this.loadedExternalUrls.push(h),a.push(this.importRDF(this.fetchRDF(h),t,f.namedNode(h))))}if(this.config.classInstanceProvider&&(Y.equals(d.predicate)||_.equals(d.predicate))){const h=d.object.value;if(this.loadedClasses.indexOf(h)<0){let b;h in V?b=V[h]:(b=this.config.classInstanceProvider(h),V[h]=b),this.loadedClasses.push(h),a.push(this.importRDF(b,t,i))}}}).on("error",d=>{console.warn("failed parsing graph",i,d.message),l(d)}).on("prefix",(d,h)=>{d&&(this.config.prefixes[d]=h)}).on("end",()=>{r(null)}),c.write(o),c.end()});try{await Promise.allSettled(a)}catch(r){console.warn(r)}};if(e instanceof Promise&&(e=await e),e){if(ae(e)==="json")try{e=await Se(JSON.parse(e),{format:"application/n-quads"})}catch(o){console.error(o)}await n(e)}}toURL(e){if(G(e))return e;if(this.config.prefixes){const t=e.split(":");if(t.length===2){const i=this.config.prefixes[t[0]];if(i&&(e=e.replace(`${t[0]}:`,i),G(e)))return e}}return null}async fetchRDF(e){if(e in Q)return Q[e];let t=e;this.config.attributes.proxy&&(t=this.config.attributes.proxy+encodeURIComponent(e));const i=fetch(t,{headers:{Accept:"text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json"}}).then(n=>n.text());return Q[e]=i,i}}function ae(s){return/^\s*\{/.test(s)?"json":/^\s*<\?xml/.test(s)?"xml":"ttl"}class M{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.submitButton=null,this.generateNodeShapeReference=null,this.showNodeIds=null}}class re{constructor(e,t){this.attributes=new M,this.loader=new Je(this),this.prefixes={},this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this.nodeShapes={},this.propertyShapes={},this._store=new W,this.theme=e,this.form=t,this.languages=[...new Set(navigator.languages.flatMap(i=>i.length>2?[i.toLocaleLowerCase(),i.substring(0,2)]:i)),""]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this.nodeShapes={},this.propertyShapes={}}updateAttributes(e){const t=new M;if(Object.keys(t).forEach(i=>{const n=e.dataset[i];n!==void 0&&(t[i]=n)}),this.editMode=t.view===null,this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){const i=this.languages.indexOf(t.language);i>-1&&this.languages.splice(i,1),this.languages.unshift(t.language)}t.valuesGraph&&(this.valuesGraphId=f.namedNode(t.valuesGraph))}static dataAttributes(){const e=new M;return Object.keys(e).map(t=>(t=t.replace(/[A-Z]/g,i=>"-"+i.toLowerCase()),"data-"+t))}get store(){return this._store}set store(e){this._store=e,this.lists=Ae(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(t=>{this.groups.push(t.id)},g,`${u}PropertyGroup`,null)}}const Ye=`
|
|
51
51
|
.editor:not([type='checkbox']) { border: 1px solid #DDD; }
|
|
52
52
|
.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; }
|
|
53
53
|
.property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
|
|
54
54
|
.mode-edit .property-instance label { width: var(--label-width); }
|
|
55
|
-
`;class
|
|
56
|
-
:scope shacl-node[data-node-id='${
|
|
57
|
-
:scope shacl-node[data-node-id='${
|
|
58
|
-
:scope shacl-node[data-node-id='${
|
|
59
|
-
:scope shacl-node[data-node-id='${
|
|
60
|
-
:scope [data-node-id='${
|
|
61
|
-
:scope [data-node-id='${
|
|
62
|
-
`;else
|
|
55
|
+
`;class Ze extends Me{constructor(e){super(e||Ye),this.idCtr=0}createDefaultTemplate(e,t,i,n,o){n.id=`e${this.idCtr++}`,n.classList.add("editor"),o?.datatype?n.shaclDatatype=o.datatype:t instanceof C&&(n.shaclDatatype=t.datatype),o?.minCount!==void 0&&(n.dataset.minCount=String(o.minCount)),o?.class&&(n.dataset.class=o.class.value),o?.nodeKind?n.dataset.nodeKind=o.nodeKind.value:t instanceof N&&(n.dataset.nodeKind=u+"IRI"),(o?.hasValue&&t||o?.readonly)&&(n.disabled=!0),n.value=t?.value||o?.defaultValue?.value||"";const a=document.createElement("label");a.htmlFor=n.id,a.innerText=e,o?.description&&a.setAttribute("title",o.description.value);const r=o?.description?o.description.value:o?.pattern?o.pattern:null;r&&n.setAttribute("placeholder",r),i&&(n.setAttribute("required","true"),a.classList.add("required"));const l=document.createElement("div");return l.appendChild(a),l.appendChild(n),l}createDateEditor(e,t,i,n){const o=new q;n.datatype?.value===x+"dateTime"?(o.type="datetime-local",o.setAttribute("step","1")):o.type="date",o.clearable=!0,o.dense=!0,o.classList.add("pr-0");const a=this.createDefaultTemplate(e,null,i,o,n);if(t)try{let r=new Date(t.value).toISOString();n.datatype?.value===x+"dateTime"?r=r.slice(0,19):r=r.slice(0,10),o.value=r}catch(r){console.error(r,t)}return a}createTextEditor(e,t,i,n){let o;return n.singleLine===!1?(o=new ye,o.resize="auto"):o=new q,o.dense=!0,n.pattern&&(o.pattern=n.pattern),n.minLength&&(o.minLength=n.minLength),n.maxLength&&(o.maxLength=n.maxLength),this.createDefaultTemplate(e,t,i,o,n)}createLangStringEditor(e,t,i,n){const o=this.createTextEditor(e,t,i,n),a=o.querySelector(":scope .editor");let r;if(n.languageIn?.length){r=document.createElement("select");for(const l of n.languageIn){const c=document.createElement("option");c.innerText=l.value,r.appendChild(c)}}else r=document.createElement("input"),r.maxLength=5,r.size=5,r.placeholder="lang?";return r.title="Language of the text",r.classList.add("lang-chooser"),r.slot="suffix",r.addEventListener("change",l=>{l.stopPropagation(),a&&(a.dataset.lang=r.value,a.dispatchEvent(new Event("change",{bubbles:!0})))}),t instanceof C&&(r.value=t.language),a.dataset.lang=r.value,a.appendChild(r),o}createBooleanEditor(e,t,i,n){const o=document.createElement("input");o.type="checkbox",o.classList.add("ml-0");const a=this.createDefaultTemplate(e,null,i,o,n);return o.removeAttribute("required"),a.querySelector(":scope label")?.classList.remove("required"),t instanceof C&&(o.checked=t.value==="true"),a}createFileEditor(e,t,i,n){const o=document.createElement("input");return o.type="file",o.addEventListener("change",a=>{if(o.files?.length){a.stopPropagation();const r=new FileReader;r.readAsDataURL(o.files[0]),r.onload=()=>{o.binaryData=btoa(r.result),o.parentElement?.dispatchEvent(new Event("change",{bubbles:!0}))}}else o.binaryData=void 0}),this.createDefaultTemplate(e,t,i,o,n)}createNumberEditor(e,t,i,n){const o=new q;o.type="number",o.clearable=!0,o.dense=!0,o.classList.add("pr-0");const a=n.minInclusive!==void 0?n.minInclusive:n.minExclusive!==void 0?n.minExclusive+1:void 0,r=n.maxInclusive!==void 0?n.maxInclusive:n.maxExclusive!==void 0?n.maxExclusive-1:void 0;return a!==void 0&&(o.min=String(a)),r!==void 0&&(o.max=String(r)),n.datatype?.value!==x+"integer"&&(o.step="0.1"),this.createDefaultTemplate(e,t,i,o,n)}createListEditor(e,t,i,n,o){const a=new ce;a.clearable=!0,a.dense=!0;const r=this.createDefaultTemplate(e,null,i,a,o),l=document.createElement("ul");let c=!0;const d=(h,b)=>{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 N&&(p.dataset.value="<"+p.dataset.value+">"),p.innerText=h.label?h.label:h.value.value),b.appendChild(p),h.children?.length){c=!1;const w=document.createElement("ul");p.appendChild(w);for(const E of h.children)d(E,w)}};for(const h of n)d(h,l);return c||(a.collapse=!0),a.appendChild(l),t&&(a.value=t.id,t instanceof N&&(a.value="<"+a.value+">")),r}createButton(e,t){const i=document.createElement("rokit-button");return i.innerHTML=e,i}}class et extends HTMLElement{constructor(){super(),this.shape=null,this.attachShadow({mode:"open"}),this.form=document.createElement("form"),this.config=new re(new Ze,this.form),this.form.addEventListener("change",e=>{e.stopPropagation(),this.config.editMode&&this.validate(!0).then(t=>{this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:t.conforms,report:t}}))}).catch(t=>{console.warn(t)})})}static get observedAttributes(){return re.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(),await this.config.loader.loadGraphs(),this.form.replaceChildren();const e=this.findRootShaclShapeSubject();if(e){this.form.classList.forEach(n=>{this.form.classList.remove(n)}),this.form.classList.toggle("mode-edit",this.config.editMode),this.form.classList.toggle("mode-view",!this.config.editMode),this.config.theme.apply(this.form);const t=[this.config.theme.stylesheet];for(const n of We())n.stylesheet&&t.push(n.stylesheet);this.shadowRoot.adoptedStyleSheets=t;const i=new I(e,this.config);for(const[n,o]of Object.entries(this.config.nodeShapes))ke(o);if(this.shape=new L(i,this.config.attributes.valuesSubject?f.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.editMode){if(this.config.attributes.submitButton!==null){const n=this.config.theme.createButton(this.config.attributes.submitButton||"Submit",!0);n.addEventListener("click",o=>{o.preventDefault(),this.form.reportValidity()&&this.validate().then(a=>{if(a?.conforms)this.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}));else{let r=this.form.querySelector(":scope .invalid > .editor");r?r.focus():this.form.querySelector(":scope .invalid")?.scrollIntoView()}})}),this.form.appendChild(n)}this.config.attributes.valuesSubject&&this.removeFromDataGraph(f.namedNode(this.config.attributes.valuesSubject)),await this.validate(!0)}}else if(this.config.store.countQuads(null,null,null,j)>0)throw new Error("shacl root node shape not found")}catch(e){console.error(e);const t=document.createElement("div");t.innerText=String(e),this.form.replaceChildren(t)}this.removeAttribute("loading")},200)}serialize(e="text/turtle",t=this.toRDF()){const i=t.getQuads(null,null,null,null);return ze(i,e,this.config.prefixes)}toRDF(e=new W){return this.shape?.toRDF(e),e}registerPlugin(e){He(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}async validate(e=!1){for(const t of this.form.querySelectorAll(":scope .validation-error"))t.remove();for(const t of this.form.querySelectorAll(":scope .property-instance"))t.classList.remove("invalid"),t.querySelector(":scope > .editor")?.value?t.classList.add("valid"):t.classList.remove("valid");this.config.store.deleteGraph(this.config.valuesGraphId||""),this.shape&&(this.shape.toRDF(this.config.store),this.config.store.add(new le(this.shape.template.id,f.namedNode(u+"targetNode"),this.shape.nodeId,this.config.valuesGraphId)));try{const t=this.config.store,i=await new xe(t,{details:!0,factory:f}).validate({dataset:t});for(const n of i.results)if(n.focusNode?.ptrs?.length)for(const o of n.focusNode.ptrs){const a=o._term;if(n.path?.length){const r=n.path[0].predicates[0];let l=this.form.querySelectorAll(`
|
|
56
|
+
:scope shacl-node[data-node-id='${a.id}'] > shacl-property > .property-instance[data-path='${r.id}'] > .editor,
|
|
57
|
+
:scope shacl-node[data-node-id='${a.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${r.id}'] > .editor,
|
|
58
|
+
:scope shacl-node[data-node-id='${a.id}'] > .shacl-group > shacl-property > .property-instance[data-path='${r.id}'] > .editor,
|
|
59
|
+
:scope shacl-node[data-node-id='${a.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[data-path='${r.id}'] > .editor`);l.length===0&&(l=this.form.querySelectorAll(`
|
|
60
|
+
:scope [data-node-id='${a.id}'] > shacl-property > .property-instance[data-path='${r.id}'],
|
|
61
|
+
:scope [data-node-id='${a.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${r.id}']`));for(const c of l)if(c.classList.contains("editor")){if(!e||c.value){let d=c.parentElement;d.classList.add("invalid"),d.classList.remove("valid"),d.appendChild(this.createValidationErrorDisplay(n));do d instanceof k&&(d.open=!0),d=d.parentElement;while(d)}}else e||(c.classList.add("invalid"),c.classList.remove("valid"),c.appendChild(this.createValidationErrorDisplay(n,"node")))}else e||this.form.querySelector(`:scope [data-node-id='${a.id}']`)?.prepend(this.createValidationErrorDisplay(n,"node"))}return i}catch(t){return console.error(t),!1}}createValidationErrorDisplay(e,t){const i=document.createElement("span");if(i.classList.add("validation-error"),t&&i.classList.add(t),e)if(e.message?.length>0)for(const n of e.message)i.title+=n.value+`
|
|
62
|
+
`;else i.title=e.sourceConstraintComponent?.value;return i}findRootShaclShapeSubject(){let e=null;if(this.config.attributes.shapeSubject){if(e=f.namedNode(this.config.attributes.shapeSubject),this.config.store.getQuads(e,g,A,null).length===0){console.warn(`shapes graph does not contain requested root shape ${this.config.attributes.shapeSubject}`);return}}else if(this.config.attributes.valuesSubject&&this.config.store.countQuads(null,null,null,y)>0){const t=f.namedNode(this.config.attributes.valuesSubject),i=[...this.config.store.getQuads(t,g,null,y),...this.config.store.getQuads(t,B,null,y)];if(i.length===0){console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${g.id} nor ${B.id} statement`);return}for(const n of i)if(this.config.store.getQuads(n.object,g,A,null).length>0){e=n.object;break}if(!e){const n=this.config.store.getQuads(null,_,i[0].object,null);if(n.length===0){console.error(`value subject '${this.config.attributes.valuesSubject}' has no shacl shape definition in the shapes graph`);return}if(n.length>1&&console.warn(`value subject '${this.config.attributes.valuesSubject}' has multiple shacl shape definitions in the shapes graph, choosing the first found (${n[0].subject})`),this.config.store.getQuads(n[0].subject,g,A,null).length===0){console.error(`value subject '${this.config.attributes.valuesSubject}' references a shape which is not a NodeShape (${n[0].subject})`);return}e=n[0].subject}}else{const t=this.config.store.getQuads(null,g,A,null);if(t.length==0){console.warn("shapes graph does not contain any root shapes");return}t.length>1&&(console.warn("shapes graph contains",t.length,"root shapes. choosing first found which is",t[0].subject.value),console.info('hint: set the shape to use with attribute "data-shape-subject"')),e=t[0].subject}return e}removeFromDataGraph(e){this.config.attributes.valuesSubject;for(const t of this.config.store.getQuads(e,null,null,y))this.config.store.delete(t),(t.object.termType==="NamedNode"||t.object.termType==="BlankNode")&&this.removeFromDataGraph(t.object)}}window.customElements.define("shacl-form",et);export{re as Config,Je as Loader,rt as Plugin,et as ShaclForm,H as ShaclPropertyTemplate,Me as Theme,D as findLabel,He as registerPlugin};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NamedNode, Quad } from 'n3';
|
|
2
|
+
import { Term } from '@rdfjs/types';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
import { ShaclPropertyTemplate } from './property-template';
|
|
5
|
+
export declare class ShaclNodeTemplate {
|
|
6
|
+
id: Term;
|
|
7
|
+
parent?: ShaclNodeTemplate;
|
|
8
|
+
nodeKind?: NamedNode;
|
|
9
|
+
targetClass?: NamedNode;
|
|
10
|
+
or?: Term[];
|
|
11
|
+
xone?: Term[];
|
|
12
|
+
extendedShapes: Set<ShaclNodeTemplate>;
|
|
13
|
+
properties: Record<string, ShaclPropertyTemplate[]>;
|
|
14
|
+
owlImports: Set<NamedNode>;
|
|
15
|
+
config: Config;
|
|
16
|
+
constructor(id: Term, config: Config, parent?: ShaclNodeTemplate);
|
|
17
|
+
}
|
|
18
|
+
export declare function mergeQuads(template: ShaclNodeTemplate, quads: Quad[]): ShaclNodeTemplate;
|
|
19
|
+
export declare function mergeOverriddenProperties(node: ShaclNodeTemplate): void;
|
package/dist/node.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { BlankNode, NamedNode, Store } from 'n3';
|
|
2
2
|
import { Term } from '@rdfjs/types';
|
|
3
3
|
import { Config } from './config';
|
|
4
|
+
import { ShaclNodeTemplate } from './node-template';
|
|
5
|
+
import { ShaclPropertyTemplate } from './property-template';
|
|
4
6
|
export declare class ShaclNode extends HTMLElement {
|
|
5
|
-
parent: ShaclNode | undefined;
|
|
6
|
-
shaclSubject: NamedNode;
|
|
7
7
|
nodeId: NamedNode | BlankNode;
|
|
8
|
-
|
|
9
|
-
owlImports: NamedNode[];
|
|
10
|
-
config: Config;
|
|
8
|
+
template: ShaclNodeTemplate;
|
|
11
9
|
linked: boolean;
|
|
12
|
-
constructor(
|
|
10
|
+
constructor(template: ShaclNodeTemplate, valueSubject: NamedNode | BlankNode | undefined, nodeKind?: NamedNode, label?: string, linked?: boolean);
|
|
13
11
|
toRDF(graph: Store, subject?: NamedNode | BlankNode): (NamedNode | BlankNode);
|
|
14
|
-
addPropertyInstance(
|
|
15
|
-
tryResolve(
|
|
12
|
+
addPropertyInstance(template: ShaclPropertyTemplate, valueSubject: NamedNode | BlankNode | undefined): void;
|
|
13
|
+
tryResolve(options: Term[], valueSubject: NamedNode | BlankNode | undefined, config: Config): void;
|
|
16
14
|
}
|
package/dist/plugins/leaflet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as d from"leaflet";import"leaflet-editable/src/Leaflet.Editable.js";import E from"leaflet/dist/leaflet.css?raw";import D from"leaflet.fullscreen/Control.FullScreen.css?raw";import"leaflet.fullscreen/Control.FullScreen.js";import{P as O}from"./assets/plugin-VN3CfgGe.js";import{DataFactory as c}from"n3";const l="http://www.w3.org/ns/shacl#",S="http://www.w3.org/2001/XMLSchema#",M="http://www.w3.org/1999/02/22-rdf-syntax-ns#",w="http://www.w3.org/2000/01/rdf-schema#",h="http://www.w3.org/2004/02/skos/core#",R="http://www.w3.org/2002/07/owl#",x="http://purl.org/dc/terms/",T="http://xmlns.com/foaf/0.1/",k=c.namedNode("loaded-shapes"),P=c.namedNode("loaded-data"),g=c.namedNode(M+"type");c.namedNode(x+"conformsTo");const f=c.namedNode(w+"subClassOf");c.namedNode(R+"imports");const F=c.namedNode(h+"broader"),z=c.namedNode(h+"narrower");c.namedNode(l+"NodeShape");c.namedNode(l+"IRI");c.namedNode(l+"property");c.namedNode(l+"class");c.namedNode(l+"node");c.namedNode(l+"targetClass");c.namedNode(l+"nodeKind");c.namedNode(S+"string");function u(t,o,i=l,e){let n="";const s=v(t,o,i,e);return s&&(n=s.value),n}function v(t,o,i=l,e){let n;const s=i+o;if(e?.length){for(const a of e)for(const r of t)if(r.predicate.value===s){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===s)return a.object;return n}function b(t,o){return u(t,"prefLabel",h,o)||u(t,"label",w,o)||u(t,"name",T,o)}function y(t,o,i){const e=[];for(const n of t)e.push({value:n,label:b(o.getQuads(n,null,null,null),i),children:[]});return e}function m(t,o,i,e,n=new Set){for(const s of o.owlImports)n.has(s.id)||(n.add(s.id),e.push(...i.getSubjects(g,t,s)));o.parent&&m(t,o.parent,i,e,n)}function I(t,o){if(o.
|
|
1
|
+
import*as d from"leaflet";import"leaflet-editable/src/Leaflet.Editable.js";import E from"leaflet/dist/leaflet.css?raw";import D from"leaflet.fullscreen/Control.FullScreen.css?raw";import"leaflet.fullscreen/Control.FullScreen.js";import{P as O}from"./assets/plugin-VN3CfgGe.js";import{DataFactory as c}from"n3";const l="http://www.w3.org/ns/shacl#",S="http://www.w3.org/2001/XMLSchema#",M="http://www.w3.org/1999/02/22-rdf-syntax-ns#",w="http://www.w3.org/2000/01/rdf-schema#",h="http://www.w3.org/2004/02/skos/core#",R="http://www.w3.org/2002/07/owl#",x="http://purl.org/dc/terms/",T="http://xmlns.com/foaf/0.1/",k=c.namedNode("loaded-shapes"),P=c.namedNode("loaded-data"),g=c.namedNode(M+"type");c.namedNode(x+"conformsTo");const f=c.namedNode(w+"subClassOf");c.namedNode(R+"imports");const F=c.namedNode(h+"broader"),z=c.namedNode(h+"narrower");c.namedNode(l+"NodeShape");c.namedNode(l+"IRI");c.namedNode(l+"property");c.namedNode(l+"class");c.namedNode(l+"node");c.namedNode(l+"targetClass");c.namedNode(l+"nodeKind");c.namedNode(S+"string");function u(t,o,i=l,e){let n="";const s=v(t,o,i,e);return s&&(n=s.value),n}function v(t,o,i=l,e){let n;const s=i+o;if(e?.length){for(const a of e)for(const r of t)if(r.predicate.value===s){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===s)return a.object;return n}function b(t,o){return u(t,"prefLabel",h,o)||u(t,"label",w,o)||u(t,"name",T,o)}function y(t,o,i){const e=[];for(const n of t)e.push({value:n,label:b(o.getQuads(n,null,null,null),i),children:[]});return e}function m(t,o,i,e,n=new Set){for(const s of o.owlImports)n.has(s.id)||(n.add(s.id),e.push(...i.getSubjects(g,t,s)));o.parent&&m(t,o.parent,i,e,n)}function I(t,o){if(o.in){const i=o.config.lists[o.in];return y(i?.length?i:[],o.config.store,o.config.languages)}else{const i=o.config.store.getSubjects(g,t,k);i.push(...o.config.store.getSubjects(g,t,P)),m(t,o,o.config.store,i);const e=new Map,n=new Map;for(const a of i)e.set(a.id,{value:a,label:b(o.config.store.getQuads(a,null,null,null),o.config.languages),children:[]});for(const a of i){for(const r of o.config.store.getObjects(a,F,null))e.has(r.id)&&n.set(a.id,r.id);for(const r of o.config.store.getObjects(a,z,null))e.has(r.id)&&n.set(r.id,a.id);for(const r of o.config.store.getObjects(a,f,null))e.has(r.id)&&n.set(a.id,r.id)}for(const[a,r]of n.entries())e.get(r)?.children?.push(e.get(a));const s=[];for(const[a,r]of e.entries())n.has(a)||s.push(r);for(const a of o.config.store.getSubjects(f,t,null))s.push(...I(a,o));return s}}function B(t,o,i){{const e=t.minCount!==void 0&&t.minCount>0;if(t.class&&!t.hasValue)return t.config.theme.createListEditor(t.label,o,e,I(t.class,t),t);if(t.in){const n=t.config.lists[t.in];if(n?.length){const s=y(n,t.config.store,t.config.languages);return t.config.theme.createListEditor(t.label,o,e,s,t)}else console.error("list not found:",t.in,"existing lists:",t.config.lists)}if(t.datatype?.value===`${M}langString`||t.languageIn?.length)return t.config.theme.createLangStringEditor(t.label,o,e,t);switch(t.datatype?.value.replace(S,"")){case"integer":case"float":case"double":case"decimal":return t.config.theme.createNumberEditor(t.label,o,e,t);case"date":case"dateTime":return t.config.theme.createDateEditor(t.label,o,e,t);case"boolean":return t.config.theme.createBooleanEditor(t.label,o,e,t);case"base64Binary":return t.config.theme.createFileEditor(t.label,o,e,t)}return t.config.theme.createTextEditor(t.label,o,e,t)}}const U=`
|
|
2
2
|
#shaclMapDialog .closeButton { position: absolute; right: 0; top: 0; z-index: 1; padding: 6px 8px; cursor: pointer; border: 0; background-color: #FFFA; font-size: 24px; z-index: 1000; }
|
|
3
3
|
#shaclMapDialog { padding: 0; width:90vw; height: 90vh; margin: auto; }
|
|
4
4
|
#shaclMapDialog::backdrop { background-color: #0007; }
|
|
@@ -12,6 +12,6 @@ import*as d from"leaflet";import"leaflet-editable/src/Leaflet.Editable.js";impor
|
|
|
12
12
|
<div id="shaclMapDialogContainer"></div>
|
|
13
13
|
<div class="hint">ⓘ Draw a polygon or marker, then close dialog</div>
|
|
14
14
|
<button class="closeButton" type="button" onclick="this.parentElement.close()">✕</button>
|
|
15
|
-
</dialog>`,
|
|
15
|
+
</dialog>`,L={lng:8.657238961696038,lat:49.87627570549512},p='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',C="https://tile.openstreetmap.de/{z}/{x}/{y}.png",j=d.icon({iconUrl:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAFgUlEQVR4Aa1XA5BjWRTN2oW17d3YaZtr2962HUzbDNpjszW24mRt28p47v7zq/bXZtrp/lWnXr337j3nPCe85NcypgSFdugCpW5YoDAMRaIMqRi6aKq5E3YqDQO3qAwjVWrD8Ncq/RBpykd8oZUb/kaJutow8r1aP9II0WmLKLIsJyv1w/kqw9Ch2MYdB++12Onxee/QMwvf4/Dk/Lfp/i4nxTXtOoQ4pW5Aj7wpici1A9erdAN2OH64x8OSP9j3Ft3b7aWkTg/Fm91siTra0f9on5sQr9INejH6CUUUpavjFNq1B+Oadhxmnfa8RfEmN8VNAsQhPqF55xHkMzz3jSmChWU6f7/XZKNH+9+hBLOHYozuKQPxyMPUKkrX/K0uWnfFaJGS1QPRtZsOPtr3NsW0uyh6NNCOkU3Yz+bXbT3I8G3xE5EXLXtCXbbqwCO9zPQYPRTZ5vIDXD7U+w7rFDEoUUf7ibHIR4y6bLVPXrz8JVZEql13trxwue/uDivd3fkWRbS6/IA2bID4uk0UpF1N8qLlbBlXs4Ee7HLTfV1j54APvODnSfOWBqtKVvjgLKzF5YdEk5ewRkGlK0i33Eofffc7HT56jD7/6U+qH3Cx7SBLNntH5YIPvODnyfIXZYRVDPqgHtLs5ABHD3YzLuespb7t79FY34DjMwrVrcTuwlT55YMPvOBnRrJ4VXTdNnYug5ucHLBjEpt30701A3Ts+HEa73u6dT3FNWwflY86eMHPk+Yu+i6pzUpRrW7SNDg5JHR4KapmM5Wv2E8Tfcb1HoqqHMHU+uWDD7zg54mz5/2BSnizi9T1Dg4QQXLToGNCkb6tb1NU+QAlGr1++eADrzhn/u8Q2YZhQVlZ5+CAOtqfbhmaUCS1ezNFVm2imDbPmPng5wmz+gwh+oHDce0eUtQ6OGDIyR0uUhUsoO3vfDmmgOezH0mZN59x7MBi++WDL1g/eEiU3avlidO671bkLfwbw5XV2P8Pzo0ydy4t2/0eu33xYSOMOD8hTf4CrBtGMSoXfPLchX+J0ruSePw3LZeK0juPJbYzrhkH0io7B3k164hiGvawhOKMLkrQLyVpZg8rHFW7E2uHOL888IBPlNZ1FPzstSJM694fWr6RwpvcJK60+0HCILTBzZLFNdtAzJaohze60T8qBzyh5ZuOg5e7uwQppofEmf2++DYvmySqGBuKaicF1blQjhuHdvCIMvp8whTTfZzI7RldpwtSzL+F1+wkdZ2TBOW2gIF88PBTzD/gpeREAMEbxnJcaJHNHrpzji0gQCS6hdkEeYt9DF/2qPcEC8RM28Hwmr3sdNyht00byAut2k3gufWNtgtOEOFGUwcXWNDbdNbpgBGxEvKkOQsxivJx33iow0Vw5S6SVTrpVq11ysA2Rp7gTfPfktc6zhtXBBC+adRLshf6sG2RfHPZ5EAc4sVZ83yCN00Fk/4kggu40ZTvIEm5g24qtU4KjBrx/BTTH8ifVASAG7gKrnWxJDcU7x8X6Ecczhm3o6YicvsLXWfh3Ch1W0k8x0nXF+0fFxgt4phz8QvypiwCCFKMqXCnqXExjq10beH+UUA7+nG6mdG/Pu0f3LgFcGrl2s0kNNjpmoJ9o4B29CMO8dMT4Q5ox8uitF6fqsrJOr8qnwNbRzv6hSnG5wP+64C7h9lp30hKNtKdWjtdkbuPA19nJ7Tz3zR/ibgARbhb4AlhavcBebmTHcFl2fvYEnW0ox9xMxKBS8btJ+KiEbq9zA4RthQXDhPa0T9TEe69gWupwc6uBUphquXgf+/FrIjweHQS4/pduMe5ERUMHUd9xv8ZR98CxkS4F2n3EUrUZ10EYNw7BWm9x1GiPssi3GgiGRDKWRYZfXlON+dfNbM+GgIwYdwAAAAASUVORK5CYII=",shadowUrl:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAApCAQAAAACach9AAACMUlEQVR4Ae3ShY7jQBAE0Aoz/f9/HTMzhg1zrdKUrJbdx+Kd2nD8VNudfsL/Th///dyQN2TH6f3y/BGpC379rV+S+qqetBOxImNQXL8JCAr2V4iMQXHGNJxeCfZXhSRBcQMfvkOWUdtfzlLgAENmZDcmo2TVmt8OSM2eXxBp3DjHSMFutqS7SbmemzBiR+xpKCNUIRkdkkYxhAkyGoBvyQFEJEefwSmmvBfJuJ6aKqKWnAkvGZOaZXTUgFqYULWNSHUckZuR1HIIimUExutRxwzOLROIG4vKmCKQt364mIlhSyzAf1m9lHZHJZrlAOMMztRRiKimp/rpdJDc9Awry5xTZCte7FHtuS8wJgeYGrex28xNTd086Dik7vUMscQOa8y4DoGtCCSkAKlNwpgNtphjrC6MIHUkR6YWxxs6Sc5xqn222mmCRFzIt8lEdKx+ikCtg91qS2WpwVfBelJCiQJwvzixfI9cxZQWgiSJelKnwBElKYtDOb2MFbhmUigbReQBV0Cg4+qMXSxXSyGUn4UbF8l+7qdSGnTC0XLCmahIgUHLhLOhpVCtw4CzYXvLQWQbJNmxoCsOKAxSgBJno75avolkRw8iIAFcsdc02e9iyCd8tHwmeSSoKTowIgvscSGZUOA7PuCN5b2BX9mQM7S0wYhMNU74zgsPBj3HU7wguAfnxxjFQGBE6pwN+GjME9zHY7zGp8wVxMShYX9NXvEWD3HbwJf4giO4CFIQxXScH1/TM+04kkBiAAAAAElFTkSuQmCC",iconSize:[25,41],shadowSize:[41,41],iconAnchor:[12,41],shadowAnchor:[14,41],popupAnchor:[-3,-76]});class K extends O{constructor(o){super(o,E+`
|
|
16
16
|
`+D+`
|
|
17
|
-
`+U)}initEditMode(o){o.insertAdjacentHTML("beforeend",Y);const i=o.querySelector("#shaclMapDialogContainer");this.map=d.map(i,{fullscreenControl:!0,editable:!0,layers:[d.tileLayer(C)],zoom:5,maxBounds:A,center:
|
|
17
|
+
`+U)}initEditMode(o){o.insertAdjacentHTML("beforeend",Y);const i=o.querySelector("#shaclMapDialogContainer");this.map=d.map(i,{fullscreenControl:!0,editable:!0,layers:[d.tileLayer(C)],zoom:5,maxBounds:A,center:L}),this.map.attributionControl.addAttribution(p);const e=d.Control.extend({options:{position:"topleft",callback:null,kind:"",html:""},onAdd:function(s){let a=d.DomUtil.create("div","leaflet-control leaflet-bar"),r=d.DomUtil.create("a","",a);return r.href="#",r.title="Create a new "+this.options.kind,r.innerHTML=this.options.html,d.DomEvent.on(r,"click",d.DomEvent.stop).on(r,"click",()=>{window.LAYER=this.options.callback.call(s.editTools)},this),a}});this.map.addControl(new(e.extend({options:{callback:()=>{this.displayedShape?.remove(),this.displayedShape=this.map?.editTools.startPolygon()},kind:"polygon",html:"▰"}}))),this.map.addControl(new(e.extend({options:{callback:()=>{this.displayedShape?.remove(),this.displayedShape=this.map?.editTools.startMarker(void 0,{icon:j})},kind:"marker",html:"•"}}))),this.map.on("editable:drawing:end",()=>{this.saveChanges()}),this.map.on("editable:vertex:dragend",()=>{this.saveChanges()});const n=o.querySelector("#shaclMapDialog");return n.addEventListener("close",()=>{const s=document.body.style.top;document.body.style.position="",document.body.style.top="",window.scrollTo(0,parseInt(s||"0")*-1),this.currentEditor&&this.createdGeometry&&(this.currentEditor.value=H(this.createdGeometry),this.currentEditor.dispatchEvent(new Event("change",{bubbles:!0})))}),n}createEditor(o,i){let e=o.config.form.querySelector("#shaclMapDialog");e||(e=this.initEditMode(o.config.form));const n=o.config.theme.createButton("Open map...",!1);n.style.marginLeft="5px",n.classList.add("open-map-button"),n.onclick=()=>{this.currentEditor=s.querySelector(".editor"),this.createdGeometry=void 0,this.displayedShape?.remove(),this.drawAndZoomToGeometry(N(this.currentEditor.value||""),this.map),document.body.style.top=`-${window.scrollY}px`,document.body.style.position="fixed",e.showModal()};const s=B(o,i||null);return s.appendChild(n),s}createViewer(o,i){const e=document.createElement("div"),n=N(i.value);if(n?.coordinates?.length){const s=d.map(e,{fullscreenControl:!0,layers:[d.tileLayer(C)],zoom:5,center:L,maxBounds:A});s.attributionControl.addAttribution(p),this.drawAndZoomToGeometry(n,s)}return e}drawAndZoomToGeometry(o,i){if(setTimeout(()=>{i.invalidateSize()}),o?.type==="Point"){const e={lng:o.coordinates[0],lat:o.coordinates[1]};this.displayedShape=d.marker(e,{icon:j}).addTo(i),i.setView(e,15,{animate:!1})}else if(o?.type==="Polygon"){const e=o.coordinates[0].map(s=>({lng:s[0],lat:s[1]})),n=d.polygon(e).addTo(i);this.displayedShape=n,i.fitBounds(n.getBounds(),{animate:!1}),setTimeout(()=>{i.fitBounds(n.getBounds(),{animate:!1}),i.setView(n.getCenter(),void 0,{animate:!1})},1)}else i.setZoom(5)}saveChanges(){if(this.displayedShape instanceof d.Marker){const o=this.displayedShape.getLatLng();this.createdGeometry={type:"Point",coordinates:[o.lng,o.lat]}}else if(this.displayedShape instanceof d.Polygon){const o=this.displayedShape.getLatLngs();o[0][0].equals(o[0][o[0].length-1])||o[0].push(o[0][0]),this.createdGeometry={type:"Polygon",coordinates:[o[0].map(i=>[i.lng,i.lat])]}}else this.createdGeometry=void 0}}const A=[[-90,-180],[90,180]];function N(t){const o=t.match(/^POINT\((.*)\)$/);if(o?.length==2){const e=o[1].split(" ");if(e.length===2)return{type:"Point",coordinates:[parseFloat(e[0]),parseFloat(e[1])]}}const i=t.match(/^POLYGON[(]{2}(.*)[)]{2}$/);if(i?.length==2){const e=i[1].split(",");if(e.length>2){const n=[],s=[];n.push(s);for(const a of e){const r=a.split(" ");r.length===2&&s.push([parseFloat(r[0]),parseFloat(r[1])])}return{type:"Polygon",coordinates:n}}}}function H(t){return t.type==="Point"?`POINT(${t.coordinates.join(" ")})`:t.type==="Polygon"?`POLYGON((${t.coordinates[0].map(o=>o.join(" ")).join(",")}))`:""}export{K as LeafletPlugin,H as geometryToWkt,N as wktToGeometry,A as worldBounds};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Literal, NamedNode, Quad } from 'n3';
|
|
2
2
|
import { Term } from '@rdfjs/types';
|
|
3
3
|
import { Config } from './config';
|
|
4
|
-
import {
|
|
4
|
+
import { ShaclNodeTemplate } from './node-template';
|
|
5
5
|
export declare class ShaclPropertyTemplate {
|
|
6
|
-
parent: ShaclNode;
|
|
7
6
|
label: string;
|
|
8
7
|
name: Literal | undefined;
|
|
9
8
|
description: Literal | undefined;
|
|
10
9
|
path: string | undefined;
|
|
11
10
|
node: NamedNode | undefined;
|
|
11
|
+
group: string | undefined;
|
|
12
12
|
class: NamedNode | undefined;
|
|
13
13
|
minCount: number | undefined;
|
|
14
14
|
maxCount: number | undefined;
|
|
@@ -25,18 +25,20 @@ export declare class ShaclPropertyTemplate {
|
|
|
25
25
|
pattern: string | undefined;
|
|
26
26
|
order: number | undefined;
|
|
27
27
|
nodeKind: NamedNode | undefined;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
and: string | undefined;
|
|
29
|
+
in: string | undefined;
|
|
30
|
+
or: Term[] | undefined;
|
|
31
|
+
xone: Term[] | undefined;
|
|
32
32
|
languageIn: Term[] | undefined;
|
|
33
33
|
datatype: NamedNode | undefined;
|
|
34
34
|
hasValue: Term | undefined;
|
|
35
35
|
qualifiedValueShape: Term | undefined;
|
|
36
|
-
|
|
36
|
+
extendedShapes: Set<ShaclNodeTemplate>;
|
|
37
|
+
owlImports: Set<NamedNode>;
|
|
38
|
+
parent: ShaclNodeTemplate;
|
|
37
39
|
config: Config;
|
|
38
|
-
|
|
39
|
-
constructor(quads: Quad[], parent: ShaclNode, config: Config);
|
|
40
|
-
merge(quads: Quad[]): ShaclPropertyTemplate;
|
|
41
|
-
clone(): ShaclPropertyTemplate;
|
|
40
|
+
constructor(id: Term, parent: ShaclNodeTemplate);
|
|
42
41
|
}
|
|
42
|
+
export declare function cloneProperty(template: ShaclPropertyTemplate): ShaclPropertyTemplate;
|
|
43
|
+
export declare function mergeQuads(template: ShaclPropertyTemplate, quads: Quad[]): ShaclPropertyTemplate;
|
|
44
|
+
export declare function mergeProperty(target: ShaclPropertyTemplate, source: ShaclPropertyTemplate): void;
|
package/dist/property.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BlankNode, NamedNode, Store } from 'n3';
|
|
2
2
|
import { Term } from '@rdfjs/types';
|
|
3
3
|
import { ShaclNode } from './node';
|
|
4
|
-
import { Config } from './config';
|
|
5
4
|
import { ShaclPropertyTemplate } from './property-template';
|
|
6
5
|
import { RokitSelect } from '@ro-kit/ui-widgets';
|
|
7
6
|
export declare class ShaclProperty extends HTMLElement {
|
|
8
7
|
template: ShaclPropertyTemplate;
|
|
9
8
|
addButton: RokitSelect | undefined;
|
|
10
9
|
container: HTMLElement;
|
|
11
|
-
|
|
10
|
+
parent: ShaclNode;
|
|
11
|
+
constructor(template: ShaclPropertyTemplate, parent: ShaclNode, valueSubject?: NamedNode | BlankNode);
|
|
12
12
|
addPropertyInstance(value?: Term): HTMLElement;
|
|
13
13
|
updateControls(): void;
|
|
14
14
|
toRDF(graph: Store, subject: NamedNode | BlankNode): void;
|
package/dist/theme.default.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ShaclPropertyTemplate } from "./property-template";
|
|
|
3
3
|
import { Editor, InputListEntry, Theme } from "./theme";
|
|
4
4
|
export declare class DefaultTheme extends Theme {
|
|
5
5
|
idCtr: number;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(overriddenCss?: string);
|
|
7
7
|
createDefaultTemplate(label: string, value: Term | null, required: boolean, editor: Editor, template?: ShaclPropertyTemplate): HTMLElement;
|
|
8
8
|
createDateEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
|
|
9
9
|
createTextEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulb-darmstadt/shacl-form",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc9",
|
|
4
4
|
"description": "SHACL form generator",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@open-wc/testing": "^4.0.0",
|
|
48
|
+
"@remcovaes/web-test-runner-vite-plugin": "^1.3.0",
|
|
48
49
|
"@types/jsonld": "^1.5.15",
|
|
49
50
|
"@types/leaflet": "^1.9.20",
|
|
50
51
|
"@types/leaflet-editable": "^1.2.7",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"vitest": "^3.2.4"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@ro-kit/ui-widgets": "^1.0.
|
|
68
|
+
"@ro-kit/ui-widgets": "^1.0.9",
|
|
68
69
|
"jsonld": "^8.3.3",
|
|
69
70
|
"leaflet": "^1.9.4",
|
|
70
71
|
"leaflet-editable": "^1.3.2",
|