@ulb-darmstadt/shacl-form 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare class ElementAttributes {
18
18
  valuesSubject: string | null;
19
19
  valuesNamespace: string;
20
20
  valuesGraph: string | null;
21
+ preserveUnmappedValues: string | null;
21
22
  /**
22
23
  * @deprecated Use mode='view' instead
23
24
  */
@@ -49,6 +50,7 @@ export declare class Config {
49
50
  form: HTMLElement;
50
51
  renderedNodes: Set<string>;
51
52
  valuesGraphId: NamedNode | undefined;
53
+ originalValues: Store<import("@rdfjs/types").Quad, import("n3").Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>;
52
54
  hierarchyColorsStyleSheet: CSSStyleSheet | undefined;
53
55
  private _store;
54
56
  private _theme;
@@ -22,6 +22,7 @@ export declare const SHACL_OBJECT_IRI: import("n3").NamedNode<string>;
22
22
  export declare const SHACL_PREDICATE_PROPERTY: import("n3").NamedNode<string>;
23
23
  export declare const SHACL_PREDICATE_CLASS: import("n3").NamedNode<string>;
24
24
  export declare const SHACL_PREDICATE_NODE: import("n3").NamedNode<string>;
25
+ export declare const SHACL_PREDICATE_MESSAGE: import("n3").NamedNode<string>;
25
26
  export declare const SHACL_PREDICATE_TARGET_CLASS: import("n3").NamedNode<string>;
26
27
  export declare const SHACL_PREDICATE_NODE_KIND: import("n3").NamedNode<string>;
27
28
  export declare const XSD_DATATYPE_STRING: import("n3").NamedNode<string>;
package/dist/form.d.ts CHANGED
@@ -18,14 +18,19 @@ export declare class ShaclForm extends HTMLElement {
18
18
  initDebounceTimeout: ReturnType<typeof setTimeout> | undefined;
19
19
  private styleElement;
20
20
  private queryController?;
21
+ private validationQueue;
22
+ private validationGeneration;
21
23
  constructor();
22
24
  connectedCallback(): void;
23
25
  attributeChangedCallback(): void;
24
26
  private initialize;
25
27
  private ensureRenderRoot;
28
+ private focusFirstInvalidElement;
26
29
  private applyStyles;
27
30
  serialize(format?: string, graph?: Store): string;
28
31
  toRDF(graph?: Store<import("@rdfjs/types").Quad, import("n3").Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>): Store;
32
+ private preparePreservedOutput;
33
+ private pruneOrphanedBlankNodes;
29
34
  registerPlugin(plugin: Plugin): void;
30
35
  setTheme(theme: Theme): void;
31
36
  setClassInstanceProvider(provider: ClassInstanceProvider): void;
@@ -37,6 +42,8 @@ export declare class ShaclForm extends HTMLElement {
37
42
  validate(ignoreEmptyValues?: boolean): Promise<ValidationReport>;
38
43
  private assertNotQueryMode;
39
44
  private refreshClassInstanceEditors;
45
+ private appendValidationErrorDisplay;
46
+ private hasExplicitShaclMessage;
40
47
  private createValidationErrorDisplay;
41
48
  private findRootShaclShapeSubject;
42
49
  private removeFromDataGraph;
@@ -19,5 +19,5 @@ export interface LoaderContext {
19
19
  }
20
20
  export declare function findConformsToValuesSubject(store: Store): string | undefined;
21
21
  export declare function findConformsToShapeSubject(store: Store, valuesSubject: string): NamedNode | undefined;
22
- export declare function loadGraphs(atts: LoaderAttributes): Promise<Store<import("@rdfjs/types").Quad, Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>>;
23
- export declare function importRDF(rdf: Promise<Quad[]>, ctx: LoaderContext, graph: NamedNode): Promise<void>;
22
+ export declare function loadGraphs(atts: LoaderAttributes, originalValues?: Store): Promise<Store<import("@rdfjs/types").Quad, Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>>;
23
+ export declare function importRDF(rdf: Promise<Quad[]>, ctx: LoaderContext, graph: NamedNode, originalValues?: Store): Promise<void>;
package/dist/index.js CHANGED
@@ -1,19 +1,21 @@
1
- import{$ as e,A as t,B as n,C as r,E as i,F as a,G as o,H as s,I as c,J as l,M as u,N as d,Q as ee,R as f,S as p,U as m,V as h,X as g,Y as _,Z as v,_ as y,b,c as x,d as S,f as C,g as w,h as T,i as E,j as D,k as O,l as k,m as A,n as te,r as j,s as ne,t as M,u as N,v as P,w as F,y as I,z as L}from"./assets/query-CWN5zxbg.js";import{BlankNode as R,DataFactory as z,Literal as B,NamedNode as V,Store as H}from"n3";import{RokitButton as U,RokitCollapsible as W,RokitInput as G,RokitSelect as K,RokitTextArea as q}from"@ro-kit/ui-widgets";import{Validator as J}from"shacl-engine";var Y=`
1
+ import{$ as e,A as t,B as n,C as r,E as i,F as a,G as o,H as s,I as c,J as l,M as u,N as d,Q as ee,R as f,S as p,U as m,V as h,X as g,Y as _,Z as te,_ as v,b as y,c as b,d as x,et as S,f as C,g as w,h as T,i as E,j as D,k as O,l as k,m as ne,n as re,r as A,s as j,t as M,u as N,v as P,w as F,y as I,z as L}from"./assets/query-DOX-ExQB.js";import{BlankNode as R,DataFactory as z,Literal as B,NamedNode as V,Store as H}from"n3";import{RokitButton as U,RokitCollapsible as W,RokitInput as G,RokitSelect as K,RokitTextArea as q}from"@ro-kit/ui-widgets";import{Validator as J}from"shacl-engine";var Y=`
2
2
  .editor:not([type='checkbox']) { border: 1px solid var(--shacl-border-color, #DDD); }
3
- .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; }
3
+ .property-instance label { display: inline-flex; align-self: center; word-break: break-word; line-height: 1em; padding-right: 1em; flex-shrink: 0; position: relative; }
4
+ .property-instance:has(> .editor:is(textarea, rokit-textarea)) > label { align-self: flex-start; padding-top: 0.45em; }
4
5
  .property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
5
6
  .mode-edit .property-instance label { width: var(--label-width); }
6
- `,X=class extends b{constructor(e){super(e||Y),this.idCtr=0}createDefaultTemplate(t,n,r,i,a){let s=n??a?.defaultValue??null;if(i.id=`e${this.idCtr++}`,i.classList.add(`editor`),i.setAttribute(`part`,`editor`),a?.datatype?i.shaclDatatype=a.datatype:n instanceof B&&(i.shaclDatatype=n.datatype),a&&F(a)>0&&(i.dataset.minCount=String(F(a))),a?.class&&(i.dataset.class=a.class.value),a?.nodeKind)i.dataset.nodeKind=a.nodeKind.value;else if(n&&(n instanceof V||a?.nodeKind?.equals(_))&&(i.dataset.nodeKind=o+`IRI`,a)){let e=f(a.config.store.getQuads(n,null,null,null),a.config.languages);e&&(n=z.literal(e))}(a?.hasValue&&n||a?.readonly)&&(i.disabled=!0);let c=n?.value||a?.defaultValue?.value||``;n instanceof R?c=n.id:n instanceof V&&a?.nodeKind?.value===`http://www.w3.org/ns/shacl#IRIOrLiteral`&&(c=`<${n.value}>`),a?.datatype?.equals(e)?i.checked=n?.value===`true`||a?.defaultValue?.value===`true`:i.type===`file`?i.binaryData=c||void 0:i.value=c,y(i,s);let l=document.createElement(`label`);l.htmlFor=i.id,l.innerText=t,l.setAttribute(`part`,`label`),a?.description&&l.setAttribute(`title`,a.description.value);let u=a?.description?a.description.value:a?.pattern?a.pattern:null;u&&i.setAttribute(`placeholder`,u),r&&(i.setAttribute(`required`,`true`),l.classList.add(`required`));let d=document.createElement(`div`);return d.setAttribute(`part`,`field`),d.appendChild(l),d.appendChild(i),d}createDateEditor(e,t,r,i){let a=new G;i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?(a.type=`datetime-local`,a.setAttribute(`step`,`1`)):a.type=`date`,a.clearable=!0,a.dense=this.dense,a.classList.add(`pr-0`);let o=this.createDefaultTemplate(e,null,r,a,i);if(t){let e=i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?L(t.value):n(t.value);e?(a.value=e.value,e.suffix&&(a.dataset.xsdTemporalSuffix=e.suffix)):console.error(`unable to parse xsd date literal`,t),y(a,t)}return o}createTextEditor(e,t,n,r){let i;return r.singleLine===!1?(i=new q,i.resize=`auto`):i=new G,i.dense=this.dense,r.pattern&&(i.pattern=r.pattern),r.minLength&&(i.minLength=r.minLength),r.maxLength&&(i.maxLength=r.maxLength),this.createDefaultTemplate(e,t,n,i,r)}createLangStringEditor(e,t,n,r){let i=this.createTextEditor(e,t,n,r),a=i.querySelector(`:scope .editor`),o;if(r.languageIn?.length){o=document.createElement(`select`);for(let e of r.languageIn){let t=document.createElement(`option`);t.innerText=e.value,o.appendChild(t)}}else o=document.createElement(`input`),o.maxLength=5,o.size=5,o.placeholder=`lang?`;return o.title=`Language of the text`,o.classList.add(`lang-chooser`),o.setAttribute(`part`,`lang-chooser`),o.slot=`suffix`,a.addEventListener(`change`,()=>{o.required=a.value!==``}),o.addEventListener(`change`,e=>{e.stopPropagation(),a&&(a.dataset.lang=o.value,a.dispatchEvent(new Event(`change`,{bubbles:!0})))}),t instanceof B&&(o.value=t.language),a.dataset.lang=o.value,y(a,t??r.defaultValue),a.appendChild(o),i}createBooleanEditor(e,t,n,r){let i=document.createElement(`input`);i.type=`checkbox`,i.classList.add(`ml-0`);let a=this.createDefaultTemplate(e,null,n,i,r);return i.removeAttribute(`required`),a.querySelector(`:scope label`)?.classList.remove(`required`),t instanceof B&&(i.checked=t.value===`true`,y(i,t)),a}createFileEditor(e,t,n,r){let i=document.createElement(`input`);return i.type=`file`,i.addEventListener(`change`,e=>{if(i.files?.length){e.stopPropagation();let t=new FileReader;t.readAsDataURL(i.files[0]),t.onload=()=>{i.binaryData=btoa(t.result),i.parentElement?.dispatchEvent(new Event(`change`,{bubbles:!0}))}}else i.binaryData=void 0}),this.createDefaultTemplate(e,t,n,i,r)}createNumberEditor(e,t,n,r){let i=new G,a=m.has(r.datatype?.value??``);i.type=a?`text`:`number`,a&&(i.pattern=r.datatype?.value===`http://www.w3.org/2001/XMLSchema#decimal`?`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)`:`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)(?:[eE][+\\-]?[0-9]+)?`,i.updateComplete.then(()=>{i.inputElement.inputMode=`decimal`})),i.clearable=!0,i.dense=this.dense,i.classList.add(`pr-0`);let o=r.minInclusive===void 0?r.minExclusive===void 0?void 0:r.minExclusive+1:r.minInclusive,s=r.maxInclusive===void 0?r.maxExclusive===void 0?void 0:r.maxExclusive-1:r.maxInclusive;return o!==void 0&&(i.min=String(o)),s!==void 0&&(i.max=String(s)),!a&&r.datatype?.value!==`http://www.w3.org/2001/XMLSchema#integer`&&(i.step=`any`),this.createDefaultTemplate(e,t,n,i,r)}createListEditor(e,t,n,r,i){let a=new K;a.clearable=!0,a.dense=this.dense;let o=this.createDefaultTemplate(e,null,n,a,i),s=document.createElement(`ul`),c=[],l=!0,u=(e,t)=>{let n=document.createElement(`li`);if(typeof e.value==`string`?(n.dataset.value=e.value,n.innerText=e.label?e.label:e.value):(n.dataset.value=I(e.value),c.push(e.value),n.innerText=e.label?e.label:e.value.value),t.appendChild(n),e.children?.length){l=!1;let t=document.createElement(`ul`);n.appendChild(t);for(let n of e.children)u(n,t)}};for(let e of r)u(e,s);return l||(a.collapse=!0),a.appendChild(s),P(a,c),t=t??i?.defaultValue??null,t&&(a.value=I(t),y(a,t)),o}createButton(e,t){let n=new U;return n.dense=this.dense,n.innerHTML=e,t?(n.setAttribute(`primary`,``),n.setAttribute(`part`,`button primary`)):n.setAttribute(`part`,`button`),n}},Z=class{constructor(){this.shapes=null,this.shapesUrl=null,this.shapeSubject=null,this.values=null,this.valuesUrl=null,this.valueSubject=null,this.valuesSubject=null,this.valuesNamespace=``,this.valuesGraph=null,this.view=null,this.mode=null,this.language=null,this.loading=`Loading…`,this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=s.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense=`true`,this.useShadowRoot=`true`}},re=`#4c93d785, #f85e9a85, #00327385, #87001f85`,Q=class{constructor(e){this.attributes=new Z,this.mode=`edit`,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new H,this._nodeTemplates={},this._propertyTemplates={},this.validator=new J(this._store,{details:!0,factory:z}),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this.form=e,this._theme=new X,this.languages=[...new Set(navigator.languages.flatMap(e=>e.length>2?[e.toLocaleLowerCase(),e.substring(0,2)]:e)),``]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){let t=new Z;if(Object.keys(t).forEach(n=>{let r=e.dataset[n];r!==void 0&&(t[n]=r)}),t.mode!==null&&![`edit`,`view`,`query`].includes(t.mode))throw Error(`invalid shacl-form mode: ${t.mode}`);if(this.mode=t.mode??(t.view===null?`edit`:`view`),this.theme.setDense(t.dense===`true`),this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){let e=this.languages.indexOf(t.language);e>-1&&this.languages.splice(e,1),this.languages.unshift(t.language)}if(t.valuesGraph&&(this.valuesGraphId=z.namedNode(t.valuesGraph)),t.hierarchyColors!=null){let e=t.hierarchyColors.length?t.hierarchyColors:re,n=`:host { --hierarchy-colors: ${e}; --hierarchy-colors-length: ${e.split(`,`).length} }`;for(let e=8;e>=0;e--){let t=`shacl-property { --hierarchy-level: ${e} }`;for(let n=0;n<e;n++)t=`shacl-property `+t;n=n+`
7
- `+t}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){let e=new Z;return Object.keys(e).map(e=>(e=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase()),`data-`+e))}buildTemplateKey(e,t){let n=e.value;return t&&(t instanceof r?n+=`*`+t.id.value:n+=`*`+this.buildTemplateKey(t.id,t.parent)),n}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){let e=new Set;for(let t of Object.values(this._nodeTemplates))e.add(t.id.value);return e}getNodeTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._nodeTemplates[n];return r||=new j(e,this,t),r}getPropertyTemplate(e,t){let n=this.buildTemplateKey(e,t),i=this._propertyTemplates[n];return i||=new r(e,t),i}get nodeTemplates(){return Object.values(this._nodeTemplates)}get theme(){return this._theme}set theme(e){this._theme=e,e.setDense(this.attributes.dense===`true`)}get store(){return this._store}get editMode(){return this.mode===`edit`}get queryMode(){return this.mode===`query`}set store(e){this._store=e,this.lists=a(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(e=>{this.groups.push(e.id)},l,`${o}PropertyGroup`,null),this.validator=new J(e,{details:!0,factory:z})}},ie=200,$=class extends HTMLElement{static get observedAttributes(){return Q.dataAttributes()}constructor(){super(),this.shape=null,this.styleElement=null,this.form=document.createElement(`form`),this.form.setAttribute(`part`,`form`),this.config=new Q(this.form),this.form.addEventListener(`change`,e=>{e.stopPropagation(),this.config.queryMode?this.queryController?.handleChange():this.config.editMode&&this.validate(!0).then(e=>{this.refreshClassInstanceEditors(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:e.conforms,report:e}}))}).catch(e=>{console.warn(e)})})}connectedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}attributeChangedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.queryController?.dispose(),this.queryController=void 0,this.setAttribute(`loading`,``),this.config.theme.apply(this.form),this.applyStyles([this.config.theme.stylesheet]),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await S({shapes:this.config.attributes.shapes,shapesUrl:this.config.attributes.shapesUrl,values:this.config.attributes.values,valuesUrl:this.config.attributes.valuesUrl,valuesSubject:this.config.attributes.valuesSubject,loadOwlImports:this.config.attributes.ignoreOwlImports===null,classInstanceProvider:this.config.classInstanceProvider,rdfUrlResolver:this.config.rdfUrlResolver,proxy:this.config.attributes.proxy}),this.config.resourceLinkProvider&&await ne(this.config),this.config.attributes.valuesSubject||(this.config.attributes.valuesSubject=k(this.config.store)||null),this.form.replaceChildren();let e=this.findRootShaclShapeSubject();if(e){if(this.form.classList.forEach(e=>{this.form.classList.remove(e)}),this.form.classList.toggle(`mode-edit`,this.config.editMode),this.form.classList.toggle(`mode-view`,this.config.mode===`view`),this.form.classList.toggle(`mode-query`,this.config.queryMode),this.config.queryMode){let{QueryModeController:e}=await p(async()=>{let{QueryModeController:e}=await import(`./assets/mode-_I_CsUK6.js`);return{QueryModeController:e}},[]);this.queryController=new e(this)}this.config.theme.apply(this.form);let t=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&t.push(this.config.hierarchyColorsStyleSheet),this.queryController&&t.push(this.queryController.stylesheet);for(let e of A())e.stylesheet&&t.push(e.stylesheet);this.applyStyles(t);let n=new j(e,this.config);for(let e of this.config.nodeTemplates)E(e);if(this.shape=new te(n,this.config.attributes.valuesSubject?z.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&n.label){let e=document.createElement(`h3`);e.innerText=n.label.value,this.form.prepend(e)}if(this.config.editMode){if(this.config.attributes.submitButton!==null){let e=this.config.theme.createButton(this.config.attributes.submitButton||`Submit`,!0);e.classList.add(`submit-button`);let t=e.getAttribute(`part`);e.setAttribute(`part`,`${t?t+` `:``}submit-button`),e.addEventListener(`click`,e=>{e.preventDefault(),this.form.reportValidity()&&this.validate().then(e=>{if(e?.conforms)this.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0}));else{let e=this.form.querySelector(`:scope .invalid > .editor`);e?e.focus():this.form.querySelector(`:scope .invalid`)?.scrollIntoView()}})}),this.form.appendChild(e)}await this.shape?.ready,this.config.attributes.valuesSubject&&this.removeFromDataGraph(z.namedNode(this.config.attributes.valuesSubject)),await this.validate(!0),this.refreshClassInstanceEditors()}else this.config.queryMode&&(await this.shape.ready,await this.queryController?.initialize())}else if(this.config.store.countQuads(null,null,null,ee)>0)throw Error(`shacl root node shape not found`)}catch(e){console.error(e);let t=document.createElement(`div`);t.innerText=String(e),this.form.replaceChildren(t)}this.config.queryMode&&this.config.queryFacetProvider&&this.queryController||this.removeAttribute(`loading`),await this.shape?.ready,this.dispatchEvent(new Event(`ready`))},200)}ensureRenderRoot(){this.config.attributes.useShadowRoot===`false`?(this.shadowRoot?.contains(this.form)&&this.shadowRoot.removeChild(this.form),this.contains(this.form)||this.prepend(this.form)):(this.shadowRoot||this.attachShadow({mode:`open`}),this.shadowRoot.contains(this.form)||this.shadowRoot.prepend(this.form))}applyStyles(e){if(this.config.attributes.useShadowRoot!==`false`&&this.shadowRoot){this.shadowRoot.adoptedStyleSheets=e,this.styleElement&&=(this.styleElement.remove(),null);return}let t=e.map(e=>Array.from(e.cssRules).map(e=>e.cssText).join(`
7
+ `,X=class extends y{constructor(e){super(e||Y),this.idCtr=0}createDefaultTemplate(e,t,n,r,i){let a=t??i?.defaultValue??null;if(r.id=`e${this.idCtr++}`,r.classList.add(`editor`),r.setAttribute(`part`,`editor`),i?.datatype?r.shaclDatatype=i.datatype:t instanceof B&&(r.shaclDatatype=t.datatype),i&&F(i)>0&&(r.dataset.minCount=String(F(i))),i?.class&&(r.dataset.class=i.class.value),i?.nodeKind)r.dataset.nodeKind=i.nodeKind.value;else if(t&&(t instanceof V||i?.nodeKind?.equals(_))&&(r.dataset.nodeKind=o+`IRI`,i)){let e=f(i.config.store.getQuads(t,null,null,null),i.config.languages);e&&(t=z.literal(e))}(i?.hasValue&&t||i?.readonly)&&(r.disabled=!0);let s=t?.value||i?.defaultValue?.value||``;t instanceof R?s=t.id:t instanceof V&&i?.nodeKind?.value===`http://www.w3.org/ns/shacl#IRIOrLiteral`&&(s=`<${t.value}>`),i?.datatype?.equals(S)?r.checked=t?.value===`true`||i?.defaultValue?.value===`true`:r.type===`file`?r.binaryData=s||void 0:r.value=s,v(r,a);let c=document.createElement(`label`);c.htmlFor=r.id,c.innerText=e,c.setAttribute(`part`,`label`),i?.description&&c.setAttribute(`title`,i.description.value);let l=i?.description?i.description.value:i?.pattern?i.pattern:null;l&&r.setAttribute(`placeholder`,l),n&&(r.setAttribute(`required`,`true`),c.classList.add(`required`));let u=document.createElement(`div`);return u.setAttribute(`part`,`field`),u.appendChild(c),u.appendChild(r),u}createDateEditor(e,t,r,i){let a=new G;i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?(a.type=`datetime-local`,a.setAttribute(`step`,`1`)):a.type=`date`,a.clearable=!0,a.dense=this.dense,a.classList.add(`pr-0`);let o=this.createDefaultTemplate(e,null,r,a,i);if(t){let e=i.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?L(t.value):n(t.value);e?(a.value=e.value,e.suffix&&(a.dataset.xsdTemporalSuffix=e.suffix)):console.error(`unable to parse xsd date literal`,t),v(a,t)}return o}createTextEditor(e,t,n,r){let i;return r.singleLine===!1?(i=new q,i.resize=`auto`):i=new G,i.dense=this.dense,r.pattern&&(i.pattern=r.pattern),r.minLength&&(i.minLength=r.minLength),r.maxLength&&(i.maxLength=r.maxLength),this.createDefaultTemplate(e,t,n,i,r)}createLangStringEditor(e,t,n,r){let i=this.createTextEditor(e,t,n,r),a=i.querySelector(`:scope .editor`),o;if(r.languageIn?.length){o=document.createElement(`select`);for(let e of r.languageIn){let t=document.createElement(`option`);t.innerText=e.value,o.appendChild(t)}}else o=document.createElement(`input`),o.maxLength=5,o.size=5,o.placeholder=`lang?`;return o.title=`Language of the text`,o.classList.add(`lang-chooser`),o.setAttribute(`part`,`lang-chooser`),o.slot=`suffix`,a.addEventListener(`change`,()=>{o.required=a.value!==``}),o.addEventListener(`change`,e=>{e.stopPropagation(),a&&(a.dataset.lang=o.value,a.dispatchEvent(new Event(`change`,{bubbles:!0})))}),t instanceof B&&(o.value=t.language),a.dataset.lang=o.value,v(a,t??r.defaultValue),a.appendChild(o),i}createBooleanEditor(e,t,n,r){let i=document.createElement(`input`);i.type=`checkbox`,i.classList.add(`ml-0`);let a=this.createDefaultTemplate(e,null,n,i,r);return i.removeAttribute(`required`),a.querySelector(`:scope label`)?.classList.remove(`required`),t instanceof B&&(i.checked=t.value===`true`,v(i,t)),a}createFileEditor(e,t,n,r){let i=document.createElement(`input`);return i.type=`file`,i.addEventListener(`change`,e=>{if(i.files?.length){e.stopPropagation();let t=new FileReader;t.readAsDataURL(i.files[0]),t.onload=()=>{i.binaryData=btoa(t.result),i.parentElement?.dispatchEvent(new Event(`change`,{bubbles:!0}))}}else i.binaryData=void 0}),this.createDefaultTemplate(e,t,n,i,r)}createNumberEditor(e,t,n,r){let i=new G,a=m.has(r.datatype?.value??``);i.type=a?`text`:`number`,a&&(i.pattern=r.datatype?.value===`http://www.w3.org/2001/XMLSchema#decimal`?`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)`:`[+\\-]?(?:[0-9]+(?:[.,][0-9]*)?|[.,][0-9]+)(?:[eE][+\\-]?[0-9]+)?`,i.updateComplete.then(()=>{i.inputElement.inputMode=`decimal`})),i.clearable=!0,i.dense=this.dense,i.classList.add(`pr-0`);let o=r.minInclusive===void 0?r.minExclusive===void 0?void 0:r.minExclusive+1:r.minInclusive,s=r.maxInclusive===void 0?r.maxExclusive===void 0?void 0:r.maxExclusive-1:r.maxInclusive;return o!==void 0&&(i.min=String(o)),s!==void 0&&(i.max=String(s)),!a&&r.datatype?.value!==`http://www.w3.org/2001/XMLSchema#integer`&&(i.step=`any`),this.createDefaultTemplate(e,t,n,i,r)}createListEditor(e,t,n,r,i){let a=new K;a.clearable=!0,a.dense=this.dense;let o=this.createDefaultTemplate(e,null,n,a,i),s=document.createElement(`ul`),c=[],l=!0,u=(e,t)=>{let n=document.createElement(`li`);if(typeof e.value==`string`?(n.dataset.value=e.value,n.innerText=e.label?e.label:e.value):(n.dataset.value=I(e.value),c.push(e.value),n.innerText=e.label?e.label:e.value.value),t.appendChild(n),e.children?.length){l=!1;let t=document.createElement(`ul`);n.appendChild(t);for(let n of e.children)u(n,t)}};for(let e of r)u(e,s);return l||(a.collapse=!0),a.appendChild(s),P(a,c),t=t??i?.defaultValue??null,t&&(a.value=I(t),v(a,t)),o}createButton(e,t){let n=new U;return n.dense=this.dense,n.innerHTML=e,t?(n.setAttribute(`primary`,``),n.setAttribute(`part`,`button primary`)):n.setAttribute(`part`,`button`),n}},Z=class{constructor(){this.shapes=null,this.shapesUrl=null,this.shapeSubject=null,this.values=null,this.valuesUrl=null,this.valueSubject=null,this.valuesSubject=null,this.valuesNamespace=``,this.valuesGraph=null,this.preserveUnmappedValues=null,this.view=null,this.mode=null,this.language=null,this.loading=`Loading…`,this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=s.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense=`true`,this.useShadowRoot=`true`}},ie=`#4c93d785, #f85e9a85, #00327385, #87001f85`,Q=class{constructor(e){this.attributes=new Z,this.mode=`edit`,this.lists={},this.groups=[],this.renderedNodes=new Set,this.originalValues=new H,this._store=new H,this._nodeTemplates={},this._propertyTemplates={},this.validator=new J(this._store,{details:!0,factory:z}),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this.form=e,this._theme=new X,this.languages=[...new Set(navigator.languages.flatMap(e=>e.length>2?[e.toLocaleLowerCase(),e.substring(0,2)]:e)),``]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this.providedConformingResourceIds={},this.providedResources={},this.providedResourceLabels={},this.originalValues=new H,this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(e){let t=new Z;if(Object.keys(t).forEach(n=>{let r=e.dataset[n];r!==void 0&&(t[n]=r)}),t.mode!==null&&![`edit`,`view`,`query`].includes(t.mode))throw Error(`invalid shacl-form mode: ${t.mode}`);if(this.mode=t.mode??(t.view===null?`edit`:`view`),this.theme.setDense(t.dense===`true`),this.attributes=t,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),t.language){let e=this.languages.indexOf(t.language);e>-1&&this.languages.splice(e,1),this.languages.unshift(t.language)}if(t.valuesGraph&&(this.valuesGraphId=z.namedNode(t.valuesGraph)),t.hierarchyColors!=null){let e=t.hierarchyColors.length?t.hierarchyColors:ie,n=`:host { --hierarchy-colors: ${e}; --hierarchy-colors-length: ${e.split(`,`).length} }`;for(let e=8;e>=0;e--){let t=`shacl-property { --hierarchy-level: ${e} }`;for(let n=0;n<e;n++)t=`shacl-property `+t;n=n+`
8
+ `+t}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(n)}}static dataAttributes(){let e=new Z;return Object.keys(e).map(e=>(e=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase()),`data-`+e))}buildTemplateKey(e,t){let n=e.value;return t&&(t instanceof r?n+=`*`+t.id.value:n+=`*`+this.buildTemplateKey(t.id,t.parent)),n}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){let e=new Set;for(let t of Object.values(this._nodeTemplates))e.add(t.id.value);return e}getNodeTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._nodeTemplates[n];return r||=new A(e,this,t),r}getPropertyTemplate(e,t){let n=this.buildTemplateKey(e,t),i=this._propertyTemplates[n];return i||=new r(e,t),i}get nodeTemplates(){return Object.values(this._nodeTemplates)}get theme(){return this._theme}set theme(e){this._theme=e,e.setDense(this.attributes.dense===`true`)}get store(){return this._store}get editMode(){return this.mode===`edit`}get queryMode(){return this.mode===`query`}set store(e){this._store=e,this.lists=a(e,{ignoreErrors:!0}),this.groups=[],e.forSubjects(e=>{this.groups.push(e.id)},l,`${o}PropertyGroup`,null),this.validator=new J(e,{details:!0,factory:z})}},ae=200,$=class extends HTMLElement{static get observedAttributes(){return Q.dataAttributes()}constructor(){super(),this.shape=null,this.styleElement=null,this.validationQueue=Promise.resolve(),this.validationGeneration=0,this.form=document.createElement(`form`),this.form.setAttribute(`part`,`form`),this.config=new Q(this.form),this.form.addEventListener(`change`,e=>{e.stopPropagation(),this.config.queryMode?this.queryController?.handleChange():this.config.editMode&&this.validate(!0).then(e=>{this.refreshClassInstanceEditors(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:e.conforms,report:e}}))}).catch(e=>{console.warn(e)})})}connectedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}attributeChangedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.queryController?.dispose(),this.queryController=void 0,this.setAttribute(`loading`,``),this.config.theme.apply(this.form),this.applyStyles([this.config.theme.stylesheet]),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await x({shapes:this.config.attributes.shapes,shapesUrl:this.config.attributes.shapesUrl,values:this.config.attributes.values,valuesUrl:this.config.attributes.valuesUrl,valuesSubject:this.config.attributes.valuesSubject,loadOwlImports:this.config.attributes.ignoreOwlImports===null,classInstanceProvider:this.config.classInstanceProvider,rdfUrlResolver:this.config.rdfUrlResolver,proxy:this.config.attributes.proxy},this.config.originalValues),this.config.resourceLinkProvider&&await j(this.config),this.config.attributes.valuesSubject||(this.config.attributes.valuesSubject=k(this.config.store)||null),this.form.replaceChildren();let t=this.findRootShaclShapeSubject();if(t){if(this.form.classList.forEach(e=>{this.form.classList.remove(e)}),this.form.classList.toggle(`mode-edit`,this.config.editMode),this.form.classList.toggle(`mode-view`,this.config.mode===`view`),this.form.classList.toggle(`mode-query`,this.config.queryMode),this.config.queryMode){let{QueryModeController:e}=await p(async()=>{let{QueryModeController:e}=await import(`./assets/mode-C_BqcQqf.js`);return{QueryModeController:e}},[]);this.queryController=new e(this)}this.config.theme.apply(this.form);let e=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&e.push(this.config.hierarchyColorsStyleSheet),this.queryController&&e.push(this.queryController.stylesheet);for(let t of ne())t.stylesheet&&e.push(t.stylesheet);this.applyStyles(e);let n=new A(t,this.config);for(let e of this.config.nodeTemplates)E(e);if(this.shape=new re(n,this.config.attributes.valuesSubject?z.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&n.label){let e=document.createElement(`h3`);e.innerText=n.label.value,this.form.prepend(e)}if(this.config.editMode){if(this.config.attributes.submitButton!==null){let e=this.config.theme.createButton(this.config.attributes.submitButton||`Submit`,!0);e.classList.add(`submit-button`);let t=e.getAttribute(`part`);e.setAttribute(`part`,`${t?t+` `:``}submit-button`),e.addEventListener(`click`,e=>{e.preventDefault(),this.form.reportValidity()?this.validate().then(e=>{e?.conforms?this.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0})):this.focusFirstInvalidElement()}):this.validate().then(()=>{this.focusFirstInvalidElement(!0)})}),this.form.appendChild(e)}await this.shape?.ready,this.config.attributes.valuesSubject&&this.removeFromDataGraph(z.namedNode(this.config.attributes.valuesSubject)),await this.validate(!0),this.refreshClassInstanceEditors()}else this.config.queryMode&&(await this.shape.ready,await this.queryController?.initialize())}else if(this.config.store.countQuads(null,null,null,e)>0)throw Error(`shacl root node shape not found`)}catch(e){console.error(e);let t=document.createElement(`div`);t.innerText=String(e),this.form.replaceChildren(t)}this.config.queryMode&&this.config.queryFacetProvider&&this.queryController||this.removeAttribute(`loading`),await this.shape?.ready,this.dispatchEvent(new Event(`ready`))},200)}ensureRenderRoot(){this.config.attributes.useShadowRoot===`false`?(this.shadowRoot?.contains(this.form)&&this.shadowRoot.removeChild(this.form),this.contains(this.form)||this.prepend(this.form)):(this.shadowRoot||this.attachShadow({mode:`open`}),this.shadowRoot.contains(this.form)||this.shadowRoot.prepend(this.form))}focusFirstInvalidElement(e=!1){let t=this.form.querySelector(`:scope .invalid > .editor`);t?(e&&t.reportValidity?.(),t instanceof K?t.input.inputElement.focus():t.focus()):this.form.querySelector(`:scope .invalid`)?.scrollIntoView()}applyStyles(e){if(this.config.attributes.useShadowRoot!==`false`&&this.shadowRoot){this.shadowRoot.adoptedStyleSheets=e,this.styleElement&&=(this.styleElement.remove(),null);return}let t=e.map(e=>Array.from(e.cssRules).map(e=>e.cssText).join(`
8
9
  `).replace(/:host\b/g,`shacl-form`)).join(`
9
- `);this.styleElement||(this.styleElement=document.createElement(`style`),this.prepend(this.styleElement)),this.styleElement.textContent=t}serialize(e=`text/turtle`,t){return this.assertNotQueryMode(`serialize`),t??=this.toRDF(),w(t.getQuads(null,null,null,null),e,u)}toRDF(e=new H){return this.assertNotQueryMode(`toRDF`),this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),e}registerPlugin(e){T(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}setRdfUrlResolver(e){this.config.rdfUrlResolver=e,this.initialize()}setResourceLinkProvider(e){this.config.resourceLinkProvider=e,this.initialize()}setQueryFacetProvider(e){this.config.queryFacetProvider=e,this.queryController?.refreshFacets()}getQuery(){return this.shape?this.queryController?.getQuery()??{rootShapeId:this.shape.template.id.value,targetClass:this.shape.template.targetClass?.value,criteria:[]}:{rootShapeId:``,criteria:[]}}refreshQueryFacets(){this.queryController?.refreshFacets()}async validate(e=!1){this.assertNotQueryMode(`validate`);for(let e of this.form.querySelectorAll(`:scope .validation-error`))e.remove();for(let e of this.form.querySelectorAll(`:scope .property-instance`))e.classList.remove(`invalid`),e.querySelector(`:scope > .editor`)?.value?e.classList.add(`valid`):e.classList.remove(`valid`);for(let e of this.form.querySelectorAll(`.add-button-wrapper`))e.classList.remove(`invalid`,`validation-error`);if(!this.shape)return{conforms:!0,results:[]};if(!e){let e=this.form.querySelectorAll(`.add-button-wrapper.required`);for(let t of e)t.classList.add(`invalid`),t.after(this.createValidationErrorDisplay(`Value is required`,`node`));if(e.length>0)return{conforms:!1,results:[]}}let t=this.shape;return new Promise(n=>{this.config.store.deleteGraph(this.config.valuesGraphId||``).on(`end`,async()=>{t.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{let r=await this.config.validator.validate({dataset:this.config.store,terms:[t.nodeId]},[{terms:[t.template.id]}]);for(let t of r.results)if(t.focusNode?.ptrs?.length)for(let n of t.focusNode.ptrs){let r=n._term;if(t.path?.length){let n=t.path[0].predicates[0],i=e=>`
10
- :scope shacl-node[data-node-id='${r.id}'] > shacl-property > .property-instance[${e}='${n.id}'] > .editor,
11
- :scope shacl-node[data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[${e}='${n.id}'] > .editor,
12
- :scope shacl-node[data-node-id='${r.id}'] > .shacl-group > shacl-property > .property-instance[${e}='${n.id}'] > .editor,
13
- :scope shacl-node[data-node-id='${r.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[${e}='${n.id}'] > .editor`,a=this.form.querySelectorAll(i(`data-path`));a.length===0&&(a=this.form.querySelectorAll(i(`data-predicate`))),a.length===0&&(a=this.form.querySelectorAll(`
14
- :scope [data-node-id='${r.id}'] > shacl-property > .property-instance[data-path='${n.id}'],
15
- :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${n.id}'],
16
- :scope [data-node-id='${r.id}'] > shacl-property > .alternative-path-constraint[data-path='${n.id}'],
17
- :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .alternative-path-constraint[data-path='${n.id}']`)),a.length===0&&(a=this.form.querySelectorAll(`
18
- :scope [data-node-id='${r.id}'] > shacl-property > .property-instance[data-predicate='${n.id}'],
19
- :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[data-predicate='${n.id}']`));for(let n of a)if(n.classList.contains(`editor`)){if(!e||n.value){let e=n.parentElement;e.classList.add(`invalid`),e.classList.remove(`valid`),e.appendChild(this.createValidationErrorDisplay(t));do e instanceof W&&(e.open=!0),e=e.parentElement;while(e)}}else e||(n.classList.add(`invalid`),n.classList.remove(`valid`),n.appendChild(this.createValidationErrorDisplay(t,`node`)))}else e||this.form.querySelector(`:scope [data-node-id='${r.id}']:not([part~='linked-node'])`)?.prepend(this.createValidationErrorDisplay(t,`node`))}n(r)}catch(e){console.error(e),n({conforms:!1,results:[]})}})})}assertNotQueryMode(e){if(this.config.queryMode)throw Error(`${e}() is not available in query mode; use getQuery()`)}refreshClassInstanceEditors(){if(!(!this.shape||!this.config.editMode))for(let e of this.form.querySelectorAll(`shacl-property`))e.refreshClassInstances()}createValidationErrorDisplay(e,t){let n=document.createElement(`span`);n.classList.add(`validation-error`),t&&n.classList.add(t);let r=typeof e==`object`&&e?e:null;return r?r.message?.length?n.title+=c(this.config.languages,r.message):r.sourceConstraintComponent?.value&&(n.title=r.sourceConstraintComponent.value):typeof e==`string`&&(n.title=e),n}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){let e=z.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,l,g,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,h)>0){let e=z.namedNode(this.config.attributes.valuesSubject),t=x(this.config.store,this.config.attributes.valuesSubject),n=this.config.store.getQuads(e,l,null,h);if(n.length===0&&console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${l.id} nor ${s.id} statement`),t)return t;for(let e of n)if(this.config.store.getQuads(e.object,l,g,null).length>0)return e.object;let r=this.config.store.getObjects(e,l,h);for(let e of r)for(let t of this.config.store.getQuads(null,v,e,null))return t.subject}let e=this.config.store.getQuads(null,l,g,null);if(e.length==0){console.warn(`shapes graph does not contain any node shapes`);return}return e.length>1&&(console.warn(`shapes graph contains`,e.length,`node shapes. choosing first found which is`,e[0].subject.value),console.info(`hint: set the node shape to use with element attribute "data-shape-subject"`)),e[0].subject}}removeFromDataGraph(e){for(let t of this.config.store.getQuads(e,null,null,h))this.config.store.delete(t),(t.object.termType===`NamedNode`||t.object.termType===`BlankNode`)&&this.removeFromDataGraph(t.object)}};window.customElements.define(`shacl-form`,$);export{Q as Config,X as DefaultTheme,C as Plugin,$ as ShaclForm,r as ShaclPropertyTemplate,b as Theme,O as fetchRDF,x as findConformsToShapeSubject,k as findConformsToValuesSubject,f as findLabel,N as importRDF,ie as initTimeout,M as isRangeQueryField,S as loadGraphs,t as loadRDF,D as parseRDF,u as prefixes,i as propertyMappers,d as rdfCache,T as registerPlugin};
10
+ `);this.styleElement||(this.styleElement=document.createElement(`style`),this.prepend(this.styleElement)),this.styleElement.textContent=t}serialize(e=`text/turtle`,t){return this.assertNotQueryMode(`serialize`),t??=this.toRDF(),w(t.getQuads(null,null,null,null),e,u)}toRDF(e=new H){this.assertNotQueryMode(`toRDF`);let t;return this.config.attributes.preserveUnmappedValues!==null&&(t=this.preparePreservedOutput(e)),this.shape?.toRDF(e,void 0,this.config.attributes.generateNodeShapeReference),t?.size&&this.pruneOrphanedBlankNodes(e,t),e}preparePreservedOutput(e){let t=this.config.originalValues,n=new Map;e.addQuads(t.getQuads(null,null,null,null));for(let r of this.form.querySelectorAll(`shacl-property`))if(!r.parent.linked){for(let i of r.template.pathAlternatives??[r.template.path])if(i)for(let a of t.getQuads(r.parent.nodeId,i,null,null))e.delete(a),a.object.termType===`BlankNode`&&n.set(a.object.id,a.object)}for(let n of this.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`))if(n.template.targetClass)for(let r of t.getQuads(n.nodeId,l,n.template.targetClass,null))e.delete(r);let r=this.config.attributes.generateNodeShapeReference;if(this.shape&&r)for(let n of t.getQuads(this.shape.nodeId,z.namedNode(r),this.shape.template.id,null))e.delete(n);return n}pruneOrphanedBlankNodes(e,t){let n=new Map(t),r=[...t.values()];for(;r.length;){let t=r.pop();for(let i of e.getQuads(t,null,null,null))i.object.termType===`BlankNode`&&!n.has(i.object.id)&&(n.set(i.object.id,i.object),r.push(i.object))}let i=new Set,a=[],o=e=>{i.has(e.id)||(i.add(e.id),a.push(e))};for(let e of this.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`))e.nodeId.termType===`BlankNode`&&n.has(e.nodeId.id)&&o(e.nodeId);for(let t of n.values())e.getQuads(null,null,t,null).some(e=>e.subject.termType!==`BlankNode`||!n.has(e.subject.id))&&o(t);for(;a.length;){let t=a.pop();for(let r of e.getQuads(t,null,null,null))r.object.termType===`BlankNode`&&n.has(r.object.id)&&o(r.object)}for(let t of n.values())if(!i.has(t.id))for(let n of e.getQuads(t,null,null,null))e.delete(n)}registerPlugin(e){T(e),this.initialize()}setTheme(e){this.config.theme=e,this.initialize()}setClassInstanceProvider(e){this.config.classInstanceProvider=e,this.initialize()}setRdfUrlResolver(e){this.config.rdfUrlResolver=e,this.initialize()}setResourceLinkProvider(e){this.config.resourceLinkProvider=e,this.initialize()}setQueryFacetProvider(e){this.config.queryFacetProvider=e,this.queryController?.refreshFacets()}getQuery(){return this.shape?this.queryController?.getQuery()??{rootShapeId:this.shape.template.id.value,targetClass:this.shape.template.targetClass?.value,criteria:[]}:{rootShapeId:``,criteria:[]}}refreshQueryFacets(){this.queryController?.refreshFacets()}async validate(e=!1){this.assertNotQueryMode(`validate`);let t=++this.validationGeneration;for(let e of this.form.querySelectorAll(`:scope .validation-error`))e.remove();for(let t of this.form.querySelectorAll(`:scope .property-instance`)){let n=t.querySelector(`:scope > .editor`),r=!!n?.value,i=n?.validity?.valid===!1&&(r||!e);t.classList.toggle(`invalid`,i),r&&!i?t.classList.add(`valid`):t.classList.remove(`valid`),i&&n?.validationMessage&&this.appendValidationErrorDisplay(t,n.validationMessage)}for(let e of this.form.querySelectorAll(`.add-button-wrapper`))e.classList.remove(`invalid`,`validation-error`);if(!this.shape)return{conforms:!0,results:[]};if(!e){let e=this.form.querySelectorAll(`.add-button-wrapper.required`);for(let t of e)t.classList.add(`invalid`),t.after(this.createValidationErrorDisplay(`Value is required`,`node`));if(e.length>0)return{conforms:!1,results:[]}}let n=this.shape,r=()=>new Promise(r=>{this.config.store.deleteGraph(this.config.valuesGraphId||``).on(`end`,async()=>{n.toRDF(this.config.store,void 0,this.config.attributes.generateNodeShapeReference);try{let i=await this.config.validator.validate({dataset:this.config.store,terms:[n.nodeId]},[{terms:[n.template.id]}]);if(t!==this.validationGeneration){r(i);return}let a=[...i.results];for(let t=0;t<a.length;t++){let n=a[t];if(a.push(...n.results??[]),n.focusNode?.ptrs?.length)for(let t of n.focusNode.ptrs){let r=t._term;if(n.path?.length){let t=n.path[0].predicates[0],i=e=>`
11
+ :scope shacl-node[data-node-id='${r.id}'] > shacl-property > .property-instance[${e}='${t.id}'] > .editor,
12
+ :scope shacl-node[data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[${e}='${t.id}'] > .editor,
13
+ :scope shacl-node[data-node-id='${r.id}'] > .shacl-group > shacl-property > .property-instance[${e}='${t.id}'] > .editor,
14
+ :scope shacl-node[data-node-id='${r.id}'] > .shacl-group > shacl-property > .shacl-group > .property-instance[${e}='${t.id}'] > .editor`,a=this.form.querySelectorAll(i(`data-path`));a.length===0&&(a=this.form.querySelectorAll(i(`data-predicate`))),a.length===0&&(a=this.form.querySelectorAll(`
15
+ :scope [data-node-id='${r.id}'] > shacl-property > .property-instance[data-path='${t.id}'],
16
+ :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[data-path='${t.id}'],
17
+ :scope [data-node-id='${r.id}'] > shacl-property > .alternative-path-constraint[data-path='${t.id}'],
18
+ :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .alternative-path-constraint[data-path='${t.id}']`)),a.length===0&&(a=this.form.querySelectorAll(`
19
+ :scope [data-node-id='${r.id}'] > shacl-property > .property-instance[data-predicate='${t.id}'],
20
+ :scope [data-node-id='${r.id}'] > shacl-property > .shacl-group > .property-instance[data-predicate='${t.id}']`));for(let t of a)if(t.classList.contains(`editor`)){if(!e||t.value){let e=t.parentElement;e.classList.add(`invalid`),e.classList.remove(`valid`),this.appendValidationErrorDisplay(e,n);do e instanceof W&&(e.open=!0),e=e.parentElement;while(e)}}else e||(t.classList.add(`invalid`),t.classList.remove(`valid`),t.appendChild(this.createValidationErrorDisplay(n,`node`)))}else e||this.form.querySelector(`:scope [data-node-id='${r.id}']:not([part~='linked-node'])`)?.prepend(this.createValidationErrorDisplay(n,`node`))}}r(i)}catch(e){console.error(e),r({conforms:!1,results:[]})}})}),i=this.validationQueue.then(r,r);return this.validationQueue=i.then(()=>void 0,()=>void 0),i}assertNotQueryMode(e){if(this.config.queryMode)throw Error(`${e}() is not available in query mode; use getQuery()`)}refreshClassInstanceEditors(){if(!(!this.shape||!this.config.editMode))for(let e of this.form.querySelectorAll(`shacl-property`))e.refreshClassInstances()}appendValidationErrorDisplay(e,t,n){let r=this.createValidationErrorDisplay(t,n),i=e.querySelector(`:scope > .validation-error`);if(!i){e.appendChild(r);return}if(r.title&&this.hasExplicitShaclMessage(t)){i.title=r.title;return}r.title&&!i.title.split(`
21
+ `).includes(r.title)&&(i.title=i.title?`${i.title}\n${r.title}`:r.title)}hasExplicitShaclMessage(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.shape?.message?.length?!0:[...t.shape?.ptr?.terms??[],...t.source??[]].some(e=>this.config.store.countQuads(e,te,null,null)>0)}createValidationErrorDisplay(e,t){let n=document.createElement(`span`);n.classList.add(`validation-error`),t&&n.classList.add(t);let r=typeof e==`object`&&e?e:null;return r?r.message?.length?n.title+=c(this.config.languages,r.message):r.sourceConstraintComponent?.value&&(n.title=r.sourceConstraintComponent.value):typeof e==`string`&&(n.title=e),n}findRootShaclShapeSubject(){if(this.config.attributes.shapeSubject){let e=z.namedNode(this.config.attributes.shapeSubject);if(this.config.store.getQuads(e,l,g,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,h)>0){let e=z.namedNode(this.config.attributes.valuesSubject),t=b(this.config.store,this.config.attributes.valuesSubject),n=this.config.store.getQuads(e,l,null,h);if(n.length===0&&console.warn(`value subject '${this.config.attributes.valuesSubject}' has neither ${l.id} nor ${s.id} statement`),t)return t;for(let e of n)if(this.config.store.getQuads(e.object,l,g,null).length>0)return e.object;let r=this.config.store.getObjects(e,l,h);for(let e of r)for(let t of this.config.store.getQuads(null,ee,e,null))return t.subject}let e=this.config.store.getQuads(null,l,g,null);if(e.length==0){console.warn(`shapes graph does not contain any node shapes`);return}return e.length>1&&(console.warn(`shapes graph contains`,e.length,`node shapes. choosing first found which is`,e[0].subject.value),console.info(`hint: set the node shape to use with element attribute "data-shape-subject"`)),e[0].subject}}removeFromDataGraph(e){for(let t of this.config.store.getQuads(e,null,null,h))this.config.store.delete(t),(t.object.termType===`NamedNode`||t.object.termType===`BlankNode`)&&this.removeFromDataGraph(t.object)}};window.customElements.define(`shacl-form`,$);export{Q as Config,X as DefaultTheme,C as Plugin,$ as ShaclForm,r as ShaclPropertyTemplate,y as Theme,O as fetchRDF,b as findConformsToShapeSubject,k as findConformsToValuesSubject,f as findLabel,N as importRDF,ae as initTimeout,M as isRangeQueryField,x as loadGraphs,t as loadRDF,D as parseRDF,u as prefixes,i as propertyMappers,d as rdfCache,T as registerPlugin};
@@ -0,0 +1 @@
1
+ import{DataFactory as e}from"n3";import"rdfxml-streaming-parser";import"jsonld";var t=class{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)}},n=`http://www.w3.org/ns/shacl#`,r=`http://datashapes.org/dash#`,i=`http://www.w3.org/2001/XMLSchema#`,a=`http://www.w3.org/ns/oa#`,o=e.namedNode(`loaded-shapes`),s=e.namedNode(`loaded-data`),c=e.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`),l=e.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`);e.namedNode(`http://purl.org/dc/terms/conformsTo`);var u=e.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),d=e.namedNode(`http://www.w3.org/2002/07/owl#imports`),f=e.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),p=e.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`);e.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),e.namedNode(`http://www.w3.org/ns/shacl#IRI`),e.namedNode(`http://www.w3.org/ns/shacl#property`);var m=e.namedNode(`http://www.w3.org/ns/shacl#class`);e.namedNode(`http://www.w3.org/ns/shacl#node`),e.namedNode(`http://www.w3.org/ns/shacl#message`),e.namedNode(`http://www.w3.org/ns/shacl#targetClass`),e.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),e.namedNode(`http://www.w3.org/2001/XMLSchema#string`),e.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`);function h(e,t,r=n,i){let a=``,o=g(e,t,r,i);return o&&(a=o.value),a}function g(e,t,r=n,i){let a,o=r+t;if(i?.length){for(let t of i)for(let n of e)if(n.predicate.value===o){if(n.object.id.endsWith(`@${t}`))return n.object;n.object.id.indexOf(`@`)<0?a=n.object:a||=n.object}}else for(let t of e)if(t.predicate.value===o)return t.object;return a}function _(e,t){return h(e,`prefLabel`,`http://www.w3.org/2004/02/skos/core#`,t)||h(e,`label`,`http://www.w3.org/2000/01/rdf-schema#`,t)||h(e,`title`,`http://purl.org/dc/terms/`,t)||h(e,`name`,`http://xmlns.com/foaf/0.1/`,t)}function v(e,t,n){let r=[];for(let i of e)r.push({value:i,label:_(t.getQuads(i,null,null,null),n),children:[]});return r}function y(t,n,r=new Map){r.set(o.id,o),r.set(s.id,s);let i=t.config.valuesGraphId??e.defaultGraph();r.set(i.id,i);for(let e of t.owlImports)b(e,n,r);return t.parent&&y(t.parent,n,r),[...r.values()]}function b(e,t,n){if(!n.has(e.id)){n.set(e.id,e);for(let r of t.getObjects(null,d,e))r.termType===`NamedNode`&&b(r,t,n)}}function x(e,t,n,r){return r.flatMap(r=>e.getSubjects(t,n,r))}function S(e,t,n,r){return r.flatMap(r=>e.getObjects(t,n,r))}function C(e,t){if(t.in){let e=t.config.lists[t.in];return v(e?.length?e:[],t.config.store,t.config.languages)}else{let n=y(t,t.config.store),r=x(t.config.store,c,e,n),i=new Map,a=new Map;for(let e of r)i.set(e.id,{value:e,label:_(t.config.store.getQuads(e,null,null,null),t.config.languages),children:[]});for(let e of r){for(let r of S(t.config.store,e,f,n))i.has(r.id)&&a.set(e.id,r.id);for(let r of S(t.config.store,e,p,n))i.has(r.id)&&a.set(r.id,e.id);for(let r of S(t.config.store,e,u,n))i.has(r.id)&&a.set(e.id,r.id)}for(let[e,t]of a.entries())i.get(t)?.children?.push(i.get(e));let o=[];for(let[e,t]of i.entries())a.has(e)||o.push(t);for(let r of x(t.config.store,u,e,n))o.push(...C(r,t));return o}}`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${r}`,`${r}`,`${a}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,d.id,m.id,`${n}`,`${n}`;function w(e){return Math.max(e.minCount??0,e.qualifiedMinCount??0)}export{l as a,i,v as n,t as o,C as r,w as t};
@@ -1 +1 @@
1
- import{o as e,t}from"./assets/property-template-r31Q9rrE.js";var n=class extends e{constructor(e,t,n){super(e),this.onChange=t,this.fileType=n}createEditor(e){let n=t(e)>0,r=e.config.theme.createFileEditor(e.label,null,n,e);return r.addEventListener(`change`,e=>{e.stopPropagation(),this.onChange(e)}),this.fileType&&r.querySelector(`input[type="file"]`)?.setAttribute(`accept`,this.fileType),r}};export{n as FileUploadPlugin};
1
+ import{o as e,t}from"./assets/property-template-DgV0sNnv.js";var n=class extends e{constructor(e,t,n){super(e),this.onChange=t,this.fileType=n}createEditor(e){let n=t(e)>0,r=e.config.theme.createFileEditor(e.label,null,n,e);return r.addEventListener(`change`,e=>{e.stopPropagation(),this.onChange(e)}),this.fileType&&r.querySelector(`input[type="file"]`)?.setAttribute(`accept`,this.fileType),r}};export{n as FileUploadPlugin};
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,n,o as r,r as i,t as a}from"./assets/property-template-r31Q9rrE.js";import*as o from"leaflet";import"leaflet-editable/src/Leaflet.Editable.js";import s from"leaflet/dist/leaflet.css?raw";import c from"leaflet.fullscreen/dist/Control.FullScreen.css?raw";import"leaflet.fullscreen";import"leaflet.heat/dist/leaflet-heat.js";import{RokitButton as l}from"@ro-kit/ui-widgets";import{DataFactory as u,Literal as d}from"n3";function f(r,o,s){if(s){let s=a(r)>0;if(r.class&&!r.hasValue)return r.config.theme.createListEditor(r.label,o,s,i(r.class,r),r);if(r.in){let e=r.config.lists[r.in];if(e?.length){let t=n(e,r.config.store,r.config.languages);return r.config.theme.createListEditor(r.label,o,s,t,r)}else console.error(`list not found:`,r.in,`existing lists:`,r.config.lists)}if(r.datatype?.equals(e)||r.languageIn?.length||r.datatype===void 0&&o instanceof d&&o.language)return r.config.theme.createLangStringEditor(r.label,o,s,r);switch(r.datatype?.value.replace(t,``)){case`integer`:case`float`:case`double`:case`decimal`:return r.config.theme.createNumberEditor(r.label,o,s,r);case`date`:case`dateTime`:return r.config.theme.createDateEditor(r.label,o,s,r);case`boolean`:return r.config.theme.createBooleanEditor(r.label,o,s,r);case`base64Binary`:return r.config.theme.createFileEditor(r.label,o,s,r)}return r.config.theme.createTextEditor(r.label,o,s,r)}else return o?r.config.theme.createViewer(r.label,o,r):document.createElement(`div`)}var p=c.replace(`:root`,`:host`),m=`
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./assets/property-template-DgV0sNnv.js";import*as o from"leaflet";import"leaflet-editable/src/Leaflet.Editable.js";import s from"leaflet/dist/leaflet.css?raw";import c from"leaflet.fullscreen/dist/Control.FullScreen.css?raw";import"leaflet.fullscreen";import"leaflet.heat/dist/leaflet-heat.js";import{RokitButton as l}from"@ro-kit/ui-widgets";import{DataFactory as u,Literal as d}from"n3";function f(r,o,s){if(s){let s=a(r)>0;if(r.class&&!r.hasValue)return r.config.theme.createListEditor(r.label,o,s,i(r.class,r),r);if(r.in){let e=r.config.lists[r.in];if(e?.length){let t=n(e,r.config.store,r.config.languages);return r.config.theme.createListEditor(r.label,o,s,t,r)}else console.error(`list not found:`,r.in,`existing lists:`,r.config.lists)}if(r.datatype?.equals(e)||r.languageIn?.length||r.datatype===void 0&&o instanceof d&&o.language)return r.config.theme.createLangStringEditor(r.label,o,s,r);switch(r.datatype?.value.replace(t,``)){case`integer`:case`float`:case`double`:case`decimal`:return r.config.theme.createNumberEditor(r.label,o,s,r);case`date`:case`dateTime`:return r.config.theme.createDateEditor(r.label,o,s,r);case`boolean`:return r.config.theme.createBooleanEditor(r.label,o,s,r);case`base64Binary`:return r.config.theme.createFileEditor(r.label,o,s,r)}return r.config.theme.createTextEditor(r.label,o,s,r)}else return o?r.config.theme.createViewer(r.label,o,r):document.createElement(`div`)}var p=c.replace(`:root`,`:host`),m=`
2
2
  #shaclMapDialog .closeButton { position: absolute; right: 0; top: 0; z-index: 1000; padding: 6px 8px; cursor: pointer; border: 0; background-color: #FFFA; font-size: 24px; }
3
3
  #shaclMapDialog { padding: 0; width:90vw; height: 90vh; margin: auto; }
4
4
  #shaclMapDialog::backdrop { background-color: #0007; }
package/dist/sparql.js CHANGED
@@ -1,4 +1,4 @@
1
- var e=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,t=`http://www.w3.org/2001/XMLSchema#`,n=`http://www.w3.org/2000/10/swap/`,{rdf:r,xsd:i}={xsd:{decimal:`${t}decimal`,boolean:`${t}boolean`,double:`${t}double`,integer:`${t}integer`,string:`${t}string`},rdf:{type:`${e}type`,nil:`${e}nil`,first:`${e}first`,rest:`${e}rest`,langString:`${e}langString`},owl:{sameAs:`http://www.w3.org/2002/07/owl#sameAs`},r:{forSome:`${n}reify#forSome`,forAll:`${n}reify#forAll`},log:{implies:`${n}log#implies`,isImpliedBy:`${n}log#isImpliedBy`}},a,o=0,s={namedNode:m,blankNode:h,variable:_,literal:g,defaultGraph:v,quad:y,triple:y,fromTerm:b,fromQuad:x},c=class e{constructor(e){this.id=e}get value(){return this.id}equals(t){return t instanceof e?this.id===t.id:!!t&&this.termType===t.termType&&this.value===t.value}hashCode(){return 0}toJSON(){return{termType:this.termType,value:this.value}}},l=class extends c{get termType(){return`NamedNode`}},u=class e extends c{get termType(){return`Literal`}get value(){return this.id.substring(1,this.id.lastIndexOf(`"`))}get language(){let e=this.id,t=e.lastIndexOf(`"`)+1;return t<e.length&&e[t++]===`@`?e.substr(t).toLowerCase():``}get datatype(){return new l(this.datatypeString)}get datatypeString(){let e=this.id,t=e.lastIndexOf(`"`)+1,n=t<e.length?e[t]:``;return n===`^`?e.substr(t+2):n===`@`?r.langString:i.string}equals(t){return t instanceof e?this.id===t.id:!!t&&!!t.datatype&&this.termType===t.termType&&this.value===t.value&&this.language===t.language&&this.datatype.value===t.datatype.value}toJSON(){return{termType:this.termType,value:this.value,language:this.language,datatype:{termType:`NamedNode`,value:this.datatypeString}}}},d=class extends c{constructor(e){super(`_:${e}`)}get termType(){return`BlankNode`}get value(){return this.id.substr(2)}},f=class extends c{constructor(e){super(`?${e}`)}get termType(){return`Variable`}get value(){return this.id.substr(1)}};a=new class extends c{constructor(){return super(``),a||this}get termType(){return`DefaultGraph`}equals(e){return this===e||!!e&&this.termType===e.termType}};var p=class extends c{constructor(e,t,n,r){super(``),this._subject=e,this._predicate=t,this._object=n,this._graph=r||a}get termType(){return`Quad`}get subject(){return this._subject}get predicate(){return this._predicate}get object(){return this._object}get graph(){return this._graph}toJSON(){return{termType:this.termType,subject:this._subject.toJSON(),predicate:this._predicate.toJSON(),object:this._object.toJSON(),graph:this._graph.toJSON()}}equals(e){return!!e&&this._subject.equals(e.subject)&&this._predicate.equals(e.predicate)&&this._object.equals(e.object)&&this._graph.equals(e.graph)}};function m(e){return new l(e)}function h(e){return new d(e||`n3-${o++}`)}function g(e,t){if(typeof t==`string`)return new u(`"${e}"@${t.toLowerCase()}`);let n=t?t.value:``;return n===``&&(typeof e==`boolean`?n=i.boolean:typeof e==`number`&&(Number.isFinite(e)?n=Number.isInteger(e)?i.integer:i.double:(n=i.double,Number.isNaN(e)||(e=e>0?`INF`:`-INF`)))),n===``||n===i.string?new u(`"${e}"`):new u(`"${e}"^^${n}`)}function _(e){return new f(e)}function v(){return a}function y(e,t,n,r){return new p(e,t,n,r)}function b(e){if(e instanceof c)return e;switch(e.termType){case`NamedNode`:return m(e.value);case`BlankNode`:return h(e.value);case`Variable`:return _(e.value);case`DefaultGraph`:return a;case`Literal`:return g(e.value,e.language||e.datatype);case`Quad`:return x(e);default:throw Error(`Unexpected termType: ${e.termType}`)}}function x(e){if(e instanceof p)return e;if(e.termType!==`Quad`)throw Error(`Unexpected termType: ${e.termType}`);return y(b(e.subject),b(e.predicate),b(e.object),b(e.graph))}s.namedNode(`loaded-shapes`),s.namedNode(`loaded-data`);var S=s.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`);s.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`);var C=s.namedNode(`http://purl.org/dc/terms/conformsTo`);s.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),s.namedNode(`http://www.w3.org/2002/07/owl#imports`),s.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),s.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`),s.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),s.namedNode(`http://www.w3.org/ns/shacl#IRI`),s.namedNode(`http://www.w3.org/ns/shacl#property`),s.namedNode(`http://www.w3.org/ns/shacl#class`),s.namedNode(`http://www.w3.org/ns/shacl#node`),s.namedNode(`http://www.w3.org/ns/shacl#targetClass`),s.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),s.namedNode(`http://www.w3.org/2001/XMLSchema#string`),s.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`);var w=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`,`http://www.w3.org/2001/XMLSchema#date`,`http://www.w3.org/2001/XMLSchema#dateTime`]);function T(e){return e.datatype!==void 0&&w.has(e.datatype)}var E=`?root`,D=class{constructor(e={}){this.options=e}buildWhere(e){let t=[this.rootPattern(e),...this.criterionPatterns(e)].filter(Boolean).join(`
1
+ var e=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,t=`http://www.w3.org/2001/XMLSchema#`,n=`http://www.w3.org/2000/10/swap/`,{rdf:r,xsd:i}={xsd:{decimal:`${t}decimal`,boolean:`${t}boolean`,double:`${t}double`,integer:`${t}integer`,string:`${t}string`},rdf:{type:`${e}type`,nil:`${e}nil`,first:`${e}first`,rest:`${e}rest`,langString:`${e}langString`},owl:{sameAs:`http://www.w3.org/2002/07/owl#sameAs`},r:{forSome:`${n}reify#forSome`,forAll:`${n}reify#forAll`},log:{implies:`${n}log#implies`,isImpliedBy:`${n}log#isImpliedBy`}},a,o=0,s={namedNode:m,blankNode:h,variable:_,literal:g,defaultGraph:v,quad:y,triple:y,fromTerm:b,fromQuad:x},c=class e{constructor(e){this.id=e}get value(){return this.id}equals(t){return t instanceof e?this.id===t.id:!!t&&this.termType===t.termType&&this.value===t.value}hashCode(){return 0}toJSON(){return{termType:this.termType,value:this.value}}},l=class extends c{get termType(){return`NamedNode`}},u=class e extends c{get termType(){return`Literal`}get value(){return this.id.substring(1,this.id.lastIndexOf(`"`))}get language(){let e=this.id,t=e.lastIndexOf(`"`)+1;return t<e.length&&e[t++]===`@`?e.substr(t).toLowerCase():``}get datatype(){return new l(this.datatypeString)}get datatypeString(){let e=this.id,t=e.lastIndexOf(`"`)+1,n=t<e.length?e[t]:``;return n===`^`?e.substr(t+2):n===`@`?r.langString:i.string}equals(t){return t instanceof e?this.id===t.id:!!t&&!!t.datatype&&this.termType===t.termType&&this.value===t.value&&this.language===t.language&&this.datatype.value===t.datatype.value}toJSON(){return{termType:this.termType,value:this.value,language:this.language,datatype:{termType:`NamedNode`,value:this.datatypeString}}}},d=class extends c{constructor(e){super(`_:${e}`)}get termType(){return`BlankNode`}get value(){return this.id.substr(2)}},f=class extends c{constructor(e){super(`?${e}`)}get termType(){return`Variable`}get value(){return this.id.substr(1)}};a=new class extends c{constructor(){return super(``),a||this}get termType(){return`DefaultGraph`}equals(e){return this===e||!!e&&this.termType===e.termType}};var p=class extends c{constructor(e,t,n,r){super(``),this._subject=e,this._predicate=t,this._object=n,this._graph=r||a}get termType(){return`Quad`}get subject(){return this._subject}get predicate(){return this._predicate}get object(){return this._object}get graph(){return this._graph}toJSON(){return{termType:this.termType,subject:this._subject.toJSON(),predicate:this._predicate.toJSON(),object:this._object.toJSON(),graph:this._graph.toJSON()}}equals(e){return!!e&&this._subject.equals(e.subject)&&this._predicate.equals(e.predicate)&&this._object.equals(e.object)&&this._graph.equals(e.graph)}};function m(e){return new l(e)}function h(e){return new d(e||`n3-${o++}`)}function g(e,t){if(typeof t==`string`)return new u(`"${e}"@${t.toLowerCase()}`);let n=t?t.value:``;return n===``&&(typeof e==`boolean`?n=i.boolean:typeof e==`number`&&(Number.isFinite(e)?n=Number.isInteger(e)?i.integer:i.double:(n=i.double,Number.isNaN(e)||(e=e>0?`INF`:`-INF`)))),n===``||n===i.string?new u(`"${e}"`):new u(`"${e}"^^${n}`)}function _(e){return new f(e)}function v(){return a}function y(e,t,n,r){return new p(e,t,n,r)}function b(e){if(e instanceof c)return e;switch(e.termType){case`NamedNode`:return m(e.value);case`BlankNode`:return h(e.value);case`Variable`:return _(e.value);case`DefaultGraph`:return a;case`Literal`:return g(e.value,e.language||e.datatype);case`Quad`:return x(e);default:throw Error(`Unexpected termType: ${e.termType}`)}}function x(e){if(e instanceof p)return e;if(e.termType!==`Quad`)throw Error(`Unexpected termType: ${e.termType}`);return y(b(e.subject),b(e.predicate),b(e.object),b(e.graph))}s.namedNode(`loaded-shapes`),s.namedNode(`loaded-data`);var S=s.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`);s.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`);var C=s.namedNode(`http://purl.org/dc/terms/conformsTo`);s.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),s.namedNode(`http://www.w3.org/2002/07/owl#imports`),s.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),s.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`),s.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),s.namedNode(`http://www.w3.org/ns/shacl#IRI`),s.namedNode(`http://www.w3.org/ns/shacl#property`),s.namedNode(`http://www.w3.org/ns/shacl#class`),s.namedNode(`http://www.w3.org/ns/shacl#node`),s.namedNode(`http://www.w3.org/ns/shacl#message`),s.namedNode(`http://www.w3.org/ns/shacl#targetClass`),s.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),s.namedNode(`http://www.w3.org/2001/XMLSchema#string`),s.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`);var w=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`,`http://www.w3.org/2001/XMLSchema#date`,`http://www.w3.org/2001/XMLSchema#dateTime`]);function T(e){return e.datatype!==void 0&&w.has(e.datatype)}var E=`?root`,D=class{constructor(e={}){this.options=e}buildWhere(e){let t=[this.rootPattern(e),...this.criterionPatterns(e)].filter(Boolean).join(`
2
2
  `);return this.wrapDataset(t)}buildSelect(e,t={}){let n=t.projection?.length?t.projection.join(` `):E,r=`SELECT ${t.distinct===!1?``:`DISTINCT `}${n} WHERE {\n${L(this.buildWhere(e))}\n}`;return t.orderBy&&(r+=`\nORDER BY ${t.orderBy}`),t.limit!==void 0&&(r+=`\nLIMIT ${z(t.limit,`limit`)}`),t.offset!==void 0&&(r+=`\nOFFSET ${z(t.offset,`offset`)}`),r}buildFacetSelect(e,t,n=100){let r=`?facetValue`,i=[this.rootPattern(e.query),...this.criterionPatterns(e.query),this.pathPattern(t.path,r,`facet_${R(t.id)}`)].filter(Boolean).join(`
3
3
  `),a=this.wrapDataset(i);return T(t)?`SELECT (COUNT(DISTINCT ${E}) AS ?count) (MIN(${r}) AS ?min) (MAX(${r}) AS ?max) WHERE {\n${L(a)}\n}`:`SELECT ${r} ?count ?total WHERE {\n { SELECT ${r} (COUNT(DISTINCT ${E}) AS ?count) WHERE {\n${L(L(a))}\n } GROUP BY ${r} }\n { SELECT (COUNT(DISTINCT ${E}) AS ?total) WHERE {\n${L(L(a))}\n } }\n}\nORDER BY DESC(?count)\nLIMIT ${z(n,`bucketLimit`)}`}buildFacetsSelect(e,t=100){return`SELECT ?fieldId ?facetValue ?count ?total ?min ?max WHERE {\n${e.fields.map(n=>{let r=`?facetValue`,i=[this.rootPattern(e.query),...this.criterionPatterns(e.query),this.pathPattern(n.path,r,`facet_${R(n.id)}`)].filter(Boolean).join(`
4
4
  `),a=this.wrapDataset(i),o=`BIND(${P(n.id)} AS ?fieldId)`;return T(n)?`{\n ${o}\n { SELECT (COUNT(DISTINCT ${E}) AS ?count) (MIN(${r}) AS ?min) (MAX(${r}) AS ?max) WHERE {\n${L(L(a))}\n } }\n}`:`{\n ${o}\n { SELECT ${r} (COUNT(DISTINCT ${E}) AS ?count) WHERE {\n${L(L(a))}\n } GROUP BY ${r} ORDER BY DESC(?count) LIMIT ${z(t,`bucketLimit`)} }\n { SELECT (COUNT(DISTINCT ${E}) AS ?total) WHERE {\n${L(L(a))}\n } }\n}`}).map(L).join(`
package/dist/theme.d.ts CHANGED
@@ -8,6 +8,8 @@ export type Editor = HTMLElement & {
8
8
  binaryData?: string;
9
9
  checked?: boolean;
10
10
  disabled?: boolean;
11
+ validity?: ValidityState;
12
+ validationMessage?: string;
11
13
  rdfTerm?: Term;
12
14
  rdfTermState?: {
13
15
  value: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulb-darmstadt/shacl-form",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "SHACL form generator",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -86,7 +86,7 @@
86
86
  "vite": "^8.1.5"
87
87
  },
88
88
  "peerDependencies": {
89
- "@ro-kit/ui-widgets": "^1.0.51",
89
+ "@ro-kit/ui-widgets": "^1.0.53",
90
90
  "jsonld": "^9.0.0",
91
91
  "leaflet": "^1.9.4",
92
92
  "leaflet-editable": "^1.3.2",
@@ -1,13 +0,0 @@
1
- import{$ as e,D as t,L as n,O as r,P as i,T as a,U as o,W as s,a as c,n as l,o as u,p as d,q as f,t as p,x as m}from"./query-CWN5zxbg.js";import{DataFactory as h}from"n3";import{RokitInput as g,RokitSelect as _,RokitSlider as v,epochToDate as y}from"@ro-kit/ui-widgets";function b(t,n){let r=document.createElement(`div`),i=!!(n.in||n.class||n.datatype?.equals(e));r.classList.add(`query-editor`),r.dataset.queryFieldId=t.id,r.setAttribute(`part`,`query-editor`);let a=document.createElement(`label`);a.textContent=n.label,n.description&&(a.title=n.description.value),r.appendChild(a);let o=document.createElement(`div`);o.classList.add(`query-controls`),r.appendChild(o);let s,c=k(n),l,u=(e=``)=>{let t=document.createElement(`div`);t.classList.add(`query-value-row`);let r=new _;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=n.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of c){let t=document.createElement(`li`);if(t.dataset.value=P(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,t.appendChild(r),t},d=(e=[])=>{o.replaceChildren(),o.appendChild(u(e[0]??``))},m=(e,t=``)=>{let r=new g;return r.classList.add(`editor`,`query-range-bound`),r.type=N(n),r.label=e,r.clearable=!0,r.dense=n.config.theme.dense,r.value=t,r},h=e=>{o.replaceChildren();let t=x(n,s);t&&t[0]<t[1]&&(l=t);let r=O(t,e&&l);if(!r||r[0]===r[1]){o.append(m(`Minimum`,e?.min?.value),m(`Maximum`,e?.max?.value));return}let i=new v;i.classList.add(`editor`,`query-range-slider`),i.dense=n.config.theme.dense,i.clearable=!0,i.range=``,i.setAttribute(`range`,``),i.min=String(r[0]),i.max=String(r[1]),i.step=String(S(n,r)),i.labelFormatter=e=>C(e,n);let a=e?.min?w(e.min,n):r[0],c=e?.max?w(e.max,n):r[1];i.value=JSON.stringify([D(a??r[0],r[0],r[1]),D(c??r[1],r[0],r[1])]),i.dataset.active=e?.min||e?.max?`true`:`false`,i.addEventListener(`change`,()=>{i.dataset.active=`true`}),o.appendChild(i)};return r.getQueryCriteria=()=>{if(p(t)){let e=o.querySelector(`rokit-slider`);if(e){if(e.dataset.active!==`true`)return[];let r=E(e.value);return r?[{field:t,operator:`range`,min:T(r[0],n),max:T(r[1],n)}]:[]}let r=o.querySelectorAll(`rokit-input`),i=j(r[0]?.value,n),a=j(r[1]?.value,n);return i||a?[{field:t,operator:`range`,min:i,max:a}]:[]}if(i)return Array.from(o.querySelectorAll(`rokit-select`)).flatMap(e=>{if(!e.value)return[];let n=c.find(t=>P(t.term)===e.value)?.term;return n?[{field:t,operator:`equals`,value:n}]:[]});let e=M(n)&&!n.class&&!n.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(o.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=j(i?.value,n,a);return o?[{field:t,operator:e,value:o}]:[]})},r.setQueryFacet=e=>{let a=r.getQueryCriteria();if(s=e,i&&s?.buckets){let e=new Map(k(n).map(e=>[P(e.term),e])),t=new Map(a.flatMap(e=>e.value?[[P(e.value),e.value]]:[]));c=s.buckets.flatMap(t=>{let r=e.get(P(t.value));return n.in&&!r?[]:[{term:t.value,label:t.label??r?.label??t.value.value,count:t.count}]});for(let[n,r]of t)c.some(e=>P(e.term)===n)||c.push({term:r,label:e.get(n)?.label??r.value,count:0});d([...t.keys()])}else if(p(t)){let e=a[0];h(e?{min:e.min,max:e.max}:void 0)}else if(!e)for(let e of o.querySelectorAll(`.query-value`))e.value=``},p(t)?h():i?d():(o.replaceChildren(),o.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let t=new g;t.classList.add(`editor`,`query-value`),t.type=N(n),t.clearable=!0,t.dense=n.config.theme.dense;let i;if(t.addEventListener(`input`,()=>{clearTimeout(i),i=setTimeout(()=>{r.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(t),n.datatype?.equals(f)){let t=n.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(t.classList.add(`lang-chooser`,`query-language`),t.title=`Language of the text`,t.setAttribute(`aria-label`,`Language of the text`),t instanceof HTMLSelectElement)for(let e of n.languageIn??[]){let n=document.createElement(`option`);n.value=e.value,n.textContent=e.value,t.appendChild(n)}else t.maxLength=35,t.placeholder=`lang?`,t.value=n.config.languages.find(e=>e.length>0)??``;e.appendChild(t)}return e})())),r}function x(e,t){let n=t?.min?w(t.min,e):void 0,r=t?.max?w(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n===void 0?i:i===void 0?n:Math.max(n,i),s=r===void 0?a:a===void 0?r:Math.min(r,a);return o!==void 0&&s!==void 0&&Number.isFinite(o)&&Number.isFinite(s)&&o<=s?[o,s]:void 0}function S(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function C(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?y(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?y(e):String(Math.round(e*1e3)/1e3)}function w(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function T(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?h.literal(y(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?h.literal(y(e),n):h.literal(String(e),n)}function E(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function D(e,t,n){return Math.min(n,Math.max(t,e))}function O(e,t){return e&&e[0]<e[1]?e:t||e}function k(t){if(t.datatype?.equals(e))return[{term:h.literal(`true`,e),label:`true`},{term:h.literal(`false`,e),label:`false`}];let r=[];return t.in?r=i(t.config.lists[t.in]??[],t.config.store,t.config.languages):t.class&&(r=n(t.class,t)),A(r)}function A(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...A(e.children??[])])}function j(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?h.namedNode(e):t.datatype?.equals(f)?n?h.literal(e,n):void 0:t.datatype?h.literal(e,t.datatype):h.literal(e)}function M(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(f)}function N(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function P(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var F=`form.mode-query { padding: 0; }
2
- :host([loading]) form.mode-query > shacl-node { display: none; }
3
- .mode-query shacl-property.query-unavailable { display: none; }
4
- .mode-query .shacl-group:not(:has(shacl-property:not(.query-unavailable))), .mode-query shacl-node:not(:has(shacl-property:not(.query-unavailable))) { display: none; }
5
- .query-editor { display: flex; align-items: center; width: 100%; padding: 3px 0; }
6
- .query-editor > label { width: var(--label-width); flex-shrink: 0; padding-right: 1em; word-break: break-word; }
7
- .query-controls { display: flex; flex: 1; min-width: 0; }
8
- .query-controls > rokit-input, .query-controls > rokit-slider, .query-value-row > rokit-input, .query-value-row > rokit-select { min-height: 28px; width: 100%; flex-grow: 1; }
9
- .query-value-row { display: flex; flex: 1; width: 100%; min-width: 0; gap: 4px; }
10
- .query-language { min-height: 28px; flex: 0 0 auto; }
11
- .query-range-slider[data-active='false'] { opacity: 0.7; }
12
- .query-facet-error .query-editor > label { color: var(--shacl-error-color); }
13
- `,I=0,L=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(F),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=this.getQuery();this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:e})),await this.requestFacets(e)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;this.applyFacets(a),this.facetsApplied=!0,this.setFacetsPending(!1)}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e){let t=new Map(e.map(e=>[e.fieldId,e]));for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let n=t.get(e.queryField.id),r=e.getQueryCriteria().length>0;e.setQueryFacet(n);let i=e.closest(`shacl-property`);i?.classList.toggle(`query-unavailable`,n?.count===0&&!r),i?.classList.toggle(`query-facet-error`,n?.error===!0)}let n=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of n){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let r=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));this.host.classList.toggle(`query-facets-empty`,!r)}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function R(e){let t=e.template;if(t.or?.length||t.xone?.length){let n=H(t);if(n){e.container.appendChild(z(n,e.parent));return}let r=t.or?.length?t.or:t.xone;e.container.appendChild(m(r,e,t.config));return}if(!t.nodeShapes.size){e.container.appendChild(z(t,e.parent));return}for(let n of t.nodeShapes){let i=new Set(e.parent.ancestorShapeIds);if(i.add(e.parent.template.id.value),i.has(n.id.value))continue;let a=e.parent.queryContext??{path:[],shapePath:[]},o=new l(n,void 0,t.nodeKind,t.label,!1,i,{path:[...a.path,r(t)],shapePath:[...a.shapePath,U(t)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),t.config.hierarchyColorsStyleSheet!==void 0&&s.appendChild(u(!0)),s.appendChild(o),e.container.appendChild(s),await o.ready}}function z(e,t){let n=t.queryContext??{path:[],shapePath:[]},i={id:`qf${(I++).toString(36)}`,path:[...n.path,r(e)],shapePath:[...n.shapePath,U(e)],datatype:e.datatype?.value},a=d(e.path,e.datatype?.value)?.createQueryEditor?.(i,e)??b(i,e);return a.queryField=i,a.classList.add(`property-instance`,`query-editor`),a.dataset.path=e.path,a}async function B(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function V(e,t,n){e.or=void 0,e.xone=void 0;let r=new c(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function H(e){let n=e.or??e.xone;if(!n?.length)return;let r=n.map(n=>{let r=a(e);return r.or=void 0,r.xone=void 0,t(r,e.config.store.getQuads(n,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(r.some(e=>!e||!s.has(e.value)))return;let i=a(e);return i.or=void 0,i.xone=void 0,i.datatype=r.find(e=>e&&o.has(e.value))??r[0],i}function U(e){return e.qualifiedValueShape||e.pathAlternatives?e.id.value:e.path}export{L as QueryModeController,B as activateNodeConstraintOption,V as activatePropertyConstraintOption,R as initializeQueryProperty};
@@ -1,87 +0,0 @@
1
- import{BlankNode as e,DataFactory as t,Literal as n,NamedNode as r,Store as i,StreamParser as a,Writer as o,termFromId as s,termToId as c}from"n3";import{RdfXmlParser as l}from"rdfxml-streaming-parser";import u from"jsonld";import{RokitButton as d,RokitCollapsible as f,RokitDialog as p}from"@ro-kit/ui-widgets";import{v4 as m}from"uuid";var h=`http://www.w3.org/ns/shacl#`,ee=`http://datashapes.org/dash#`,te=`http://www.w3.org/2001/XMLSchema#`,ne=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,re=`http://www.w3.org/2000/01/rdf-schema#`,ie=`http://www.w3.org/ns/oa#`,ae=`http://purl.org/dc/terms/`,g=t.namedNode(`loaded-shapes`),_=t.namedNode(`loaded-data`),v=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`),y=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`),b=t.namedNode(`http://purl.org/dc/terms/conformsTo`),oe=t.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),x=t.namedNode(`http://www.w3.org/2002/07/owl#imports`),se=t.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),ce=t.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`),le=t.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),ue=t.namedNode(`http://www.w3.org/ns/shacl#IRI`),S=t.namedNode(`http://www.w3.org/ns/shacl#property`),C=t.namedNode(`http://www.w3.org/ns/shacl#class`),de=t.namedNode(`http://www.w3.org/ns/shacl#node`),w=t.namedNode(`http://www.w3.org/ns/shacl#targetClass`),fe=t.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),pe=t.namedNode(`http://www.w3.org/2001/XMLSchema#string`),me=t.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`),he=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`,`http://www.w3.org/2001/XMLSchema#date`,`http://www.w3.org/2001/XMLSchema#dateTime`]),ge=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`]),_e=new Set([`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`]);function T(e,t,n=h,r){let i=``,a=ve(e,t,n,r);return a&&(i=a.value),i}function ve(e,t,n=h,r){let i,a=n+t;if(r?.length){for(let t of r)for(let n of e)if(n.predicate.value===a){if(n.object.id.endsWith(`@${t}`))return n.object;n.object.id.indexOf(`@`)<0?i=n.object:i||=n.object}}else for(let t of e)if(t.predicate.value===a)return t.object;return i}function ye(e){e.querySelector(`.editor`)?.focus()}function E(e,t){return T(e,`prefLabel`,`http://www.w3.org/2004/02/skos/core#`,t)||T(e,`label`,`http://www.w3.org/2000/01/rdf-schema#`,t)||T(e,`title`,`http://purl.org/dc/terms/`,t)||T(e,`name`,`http://xmlns.com/foaf/0.1/`,t)}function D(e,t,n){let r=[];for(let i of e)r.push({value:i,label:E(t.getQuads(i,null,null,null),n),children:[]});return r}function O(e,t){for(let n in t){let r=t[n];e.startsWith(r)&&(e=e.slice(r.length))}return e}function be(e,n,r=new Map){r.set(g.id,g),r.set(_.id,_);let i=e.config.valuesGraphId??t.defaultGraph();r.set(i.id,i);for(let t of e.owlImports)xe(t,n,r);return e.parent&&be(e.parent,n,r),[...r.values()]}function xe(e,t,n){if(!n.has(e.id)){n.set(e.id,e);for(let r of t.getObjects(null,x,e))r.termType===`NamedNode`&&xe(r,t,n)}}function Se(e,t,n,r){return r.flatMap(r=>e.getSubjects(t,n,r))}function k(e,t,n,r){return r.flatMap(r=>e.getObjects(t,n,r))}function A(e,t){if(t.in){let e=t.config.lists[t.in];return D(e?.length?e:[],t.config.store,t.config.languages)}else{let n=be(t,t.config.store),r=Se(t.config.store,v,e,n),i=new Map,a=new Map;for(let e of r)i.set(e.id,{value:e,label:E(t.config.store.getQuads(e,null,null,null),t.config.languages),children:[]});for(let e of r){for(let r of k(t.config.store,e,se,n))i.has(r.id)&&a.set(e.id,r.id);for(let r of k(t.config.store,e,ce,n))i.has(r.id)&&a.set(r.id,e.id);for(let r of k(t.config.store,e,oe,n))i.has(r.id)&&a.set(e.id,r.id)}for(let[e,t]of a.entries())i.get(t)?.children?.push(i.get(e));let o=[];for(let[e,t]of i.entries())a.has(e)||o.push(t);for(let r of Se(t.config.store,oe,e,n))o.push(...A(r,t));return o}}function j(e){let t;try{t=new URL(e)}catch{return!1}return t.protocol===`http:`||t.protocol===`https:`}function M(e,t,n){if(t===void 0)return n;if(n===void 0)return t;let r=e.indexOf(t.language);if(r<0)return n;let i=e.indexOf(n.language);return i<0||i>r?t:n}function Ce(e,t){let n;for(let r of t)n=M(e,n,r);return n?n.value:``}var N=/^(-?\d{4,}-\d{2}-\d{2})(Z|[+-]\d{2}:\d{2})?$/,we=/^(-?\d{4,}-\d{2}-\d{2})T(\d{2}:\d{2})(?::(\d{2})(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/,Te=/^(-?\d{4,}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(\.\d+)?)?$/;function Ee(e){let t=e.match(N);if(!t){let t=e.match(we);return t?{value:t[1],suffix:t[5]||``}:void 0}return{value:t[1],suffix:t[2]||``}}function De(e){let t=e.match(we);if(!t){let t=e.match(N);return t?{value:`${t[1]}T00:00:00`,suffix:t[2]||``}:void 0}return{value:`${t[1]}T${t[2]}:${t[3]||`00`}`,suffix:t[5]||``}}function Oe(e,t=``){let n=e.match(N);return n?`${n[1]}${t}`:e}function ke(e,t=``){let n=e.match(Te);return n?`${n[1]}:${n[2]||`00`}${n[3]||``}${t}`:e}function Ae(e){let t=new Set;for(let n of e.getObjects(null,C,g))t.add(n.value);for(let n of e.getObjects(null,w,g))t.add(n.value);return t}function je(e,t){return e instanceof Set?[...t].filter(t=>!e.has(t)):[...t].filter(t=>!e.includes(t))}function Me(e,{remove:t=!1,ignoreErrors:n=!1}={}){let r={},i=n?()=>!0:(e,t)=>{throw Error(`${e.value} ${t}`)},a=e.getQuads(null,ne+`rest`,ne+`nil`,null),o=t?[...a]:[];return a.forEach(n=>{let a=[],s=!1,c,l,u=n.graph,d=n.subject;for(;d&&!s;){let t=e.getQuads(null,null,d,null),n=e.getQuads(d,null,null,null).filter(e=>!e.predicate.equals(v)),r,f=null,p=null,m=null;for(let e=0;e<n.length&&!s;e++)r=n[e],r.graph.equals(u)?c?s=i(d,`has non-list arcs out`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#first`?f?s=i(d,`has multiple rdf:first arcs`):o.push(f=r):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?p?s=i(d,`has multiple rdf:rest arcs`):o.push(p=r):t.length?s=i(d,`can't be subject and object`):(c=r,l=`subject`):s=i(d,`not confined to single graph`);for(let e=0;e<t.length&&!s;++e)r=t[e],c?s=i(d,`can't have coreferences`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?m?s=i(d,`has incoming rdf:rest arcs`):m=r:(c=r,l=`object`);f?a.unshift(f.object):s=i(d,`has no list head`),d=m&&m.subject}s?t=!1:c&&(r[c[l].value]=a)}),t&&e.removeQuads(o),r}var P={},F={};async function I(e){return`rdf`in e?L(e.rdf):e.rdfUrlResolver?L(await e.rdfUrlResolver(e.url)):Ne(e.url,e.proxy)}async function Ne(e,t){return e in P||(P[e]=(async()=>{let n=e;t&&(n=t+encodeURIComponent(e));let r=await fetch(n,{headers:{Accept:`text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json`}});return r.ok?L(await r.text()):(console.warn(`failed fetching RDF from`,e),[])})()),P[e]}async function L(e){if(!e.trim())return[];let n=Pe(e);if(n===`json`)try{e=await u.toRDF(JSON.parse(e),{format:`application/n-quads`})}catch(e){console.error(e)}let r=[];return await new Promise((i,o)=>{let s=n===`xml`?new l:new a;s.on(`data`,e=>{r.push(t.quad(e.subject,e.predicate,e.object,e.graph))}).on(`error`,e=>{o(e)}).on(`prefix`,(e,t)=>{e&&(F[e]=t)}).on(`end`,()=>{i(null)}),s.write(e),s.end()}),r}function Pe(e){return/^\s*[\\[{]/.test(e)?`json`:/^\s*<\?xml/.test(e)?`xml`:`ttl`}var Fe={[`${h}name`]:(e,t)=>{let n=t;e.name=M(e.config.languages,e.name,n)},[`${h}description`]:(e,t)=>{let n=t;e.description=M(e.config.languages,e.description,n)},[`${h}path`]:(e,t)=>{if(t.termType===`NamedNode`){e.path=t.value;return}let n=e.config.store.getQuads(t,null,null,null),r=n.filter(e=>e.predicate.value===`${h}alternativePath`);if(n.length!==1||r.length!==1){console.warn(`ignoring unsupported or malformed SHACL property path`,t.value);return}let i=e.config.lists[r[0].object.value];if(!i||i.length<2||i.some(e=>e.termType!==`NamedNode`)){console.warn(`ignoring sh:alternativePath without at least two predicate IRI members`,t.value);return}e.pathAlternatives=i.map(e=>e.value),e.path=e.pathAlternatives[0]},[`${h}group`]:(e,t)=>{e.group=t.id},[`${h}datatype`]:(e,t)=>{e.datatype=t},[`${h}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${h}minCount`]:(e,t)=>{e.minCount=parseInt(t.value)},[`${h}maxCount`]:(e,t)=>{e.maxCount=parseInt(t.value)},[`${h}minLength`]:(e,t)=>{e.minLength=parseInt(t.value)},[`${h}maxLength`]:(e,t)=>{e.maxLength=parseInt(t.value)},[`${h}minInclusive`]:(e,t)=>{e.minInclusive=parseInt(t.value)},[`${h}maxInclusive`]:(e,t)=>{e.maxInclusive=parseInt(t.value)},[`${h}minExclusive`]:(e,t)=>{e.minExclusive=parseInt(t.value)},[`${h}maxExclusive`]:(e,t)=>{e.maxExclusive=parseInt(t.value)},[`${h}pattern`]:(e,t)=>{e.pattern=t.value},[`${h}order`]:(e,t)=>{e.order=parseInt(t.value)},[`${ee}singleLine`]:(e,t)=>{e.singleLine=t.value===`true`},[`${ee}readonly`]:(e,t)=>{e.readonly=t.value===`true`},[`${ie}styleClass`]:(e,t)=>{e.cssClass=t.value},[`${h}in`]:(e,t)=>{e.in=t.value},[`${h}languageIn`]:(e,t)=>{e.languageIn=e.config.lists[t.value],e.datatype=y},[`${h}defaultValue`]:(e,t)=>{e.defaultValue=t},[`${h}hasValue`]:(e,t)=>{e.hasValue=t},[`${h}node`]:(e,t)=>{e.node=t,e.nodeShapes.add(e.config.getNodeTemplate(t,e))},[`${h}and`]:(e,t)=>{e.and=t.value;let n=e.config.lists[e.and];if(n?.length)for(let t of n)e.nodeShapes.add(e.config.getNodeTemplate(t,e))},[`${h}qualifiedValueShape`]:(e,t)=>{let n=e.config.getNodeTemplate(t,e);e.qualifiedValueShape=n,e.nodeShapes.add(n)},[`${h}qualifiedMinCount`]:(e,t)=>{e.qualifiedMinCount=parseInt(t.value)},[`${h}qualifiedMaxCount`]:(e,t)=>{e.qualifiedMaxCount=parseInt(t.value)},[x.id]:(e,t)=>{e.owlImports.add(t)},[C.id]:(e,t)=>{e.class=t;let n=e.config.store.getSubjects(w,t,null);n.length>0&&(e.node=n[0])},[`${h}or`]:(e,t)=>{let n=e.config.lists[t.value];n?.length?e.or=n:console.error(`list for sh:or not found:`,t.value,`existing lists:`,e.config.lists)},[`${h}xone`]:(e,t)=>{let n=e.config.lists[t.value];n?.length?e.xone=n:console.error(`list for sh:xone not found:`,t.value,`existing lists:`,e.config.lists)}},Ie=class{constructor(e,t){this.label=``,this.nodeShapes=new Set,this.owlImports=new Set,this.id=e,this.parent=t,this.config=t.config,this.config.registerPropertyTemplate(this),B(this,this.config.store.getQuads(e,null,null,null))}};function R(e){return Math.max(e.minCount??0,e.qualifiedMinCount??0)}function Le(e){return Math.min(e.maxCount??2**53-1,e.qualifiedMaxCount??2**53-1)}function z(e){let t=Object.assign({},e);return t.nodeShapes=new Set(e.nodeShapes),t.owlImports=new Set(e.owlImports),e.languageIn&&(t.languageIn=[...e.languageIn]),e.pathAlternatives&&(t.pathAlternatives=[...e.pathAlternatives]),e.pathAlternativeBranches&&(t.pathAlternativeBranches={...e.pathAlternativeBranches}),e.or&&(t.or=[...e.or]),e.xone&&(t.xone=[...e.xone]),t}function B(e,t){for(let n of t)Fe[n.predicate.id]?.call(e,e,n.object);return e.label=e.name?.value||E(t,e.config.languages),e.label||=e.pathAlternatives?e.pathAlternatives.map(e=>O(e,F)).join(` / `):e.path?O(e.path,F):`unknown`,e}function Re(e,t,n=!1){let r=t,i=e,a=Be(e),o=Be(t),s=a&&H(t),c=o&&H(e);s&&(e.nodeShapes.clear(),e.node=void 0);for(let a in t)if(a!==`parent`&&a!==`config`&&a!==`id`){let o=r[a];if(o!==void 0&&o!==``){if(a===`label`)continue;if(a===`name`||a===`description`||a===`group`||a===`order`)(n||i[a]===void 0||i[a]===``)&&(i[a]=o);else if(a===`minCount`)e.minCount=Math.max(e.minCount??0,t.minCount);else if(a===`maxCount`)e.maxCount=Math.min(e.maxCount??2**53-1,t.maxCount);else if(a===`qualifiedMinCount`)e.qualifiedMinCount=Math.max(e.qualifiedMinCount??0,t.qualifiedMinCount);else if(a===`qualifiedMaxCount`)e.qualifiedMaxCount=Math.min(e.qualifiedMaxCount??2**53-1,t.qualifiedMaxCount);else if(a===`nodeShapes`&&c)continue;else if(a===`node`&&c)continue;else if(a===`pathAlternatives`)continue;else if(Array.isArray(o)){let e=i[a];Array.isArray(e)?e.push(...o):i[a]=[...o]}else if(o instanceof Set&&o.size){let e=i[a];i[a]=new Set([...e instanceof Set?e:[],...o])}else i[a]=o}}e.name&&(e.label=e.name.value)}function V(e){return e.pathAlternatives?`alternative:${JSON.stringify(e.pathAlternatives)}`:e.path}function ze(e){return e.pathAlternatives?[...e.pathAlternatives]:e.path}function Be(e){return e.nodeShapes.size>0&&e.qualifiedValueShape===void 0&&e.name===void 0&&e.description===void 0&&!H(e)}function H(e){return e.in!==void 0||e.datatype!==void 0||e.languageIn!==void 0||e.class!==void 0||e.hasValue!==void 0||e.defaultValue!==void 0}var Ve=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),He=function(e){return`/`+e},Ue={},U=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=He(t,n),t=s(t),t in Ue)return;Ue[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ve,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function W(e,t,n,r,i){let a=document.createElement(`div`);a.classList.add(`shacl-or-constraint`),a.setAttribute(`part`,`constraint`);let o=[];if(t instanceof $){let r=[],i=!1;e.length&&(i=n.store.countQuads(e[0],S,null,null)>0);for(let a=0;a<e.length;a++)if(i){let i=n.store.getObjects(e[a],S,null),s=[],c=``;for(let e of i){let r=new Y(n.getPropertyTemplate(e,t.template),t);s.push(r),c+=(c.length>0?` / `:``)+r.template.label}r.push(s),o.push({label:c,value:a.toString()})}else{let i=e[a],s=new Y(n.getPropertyTemplate(i,t.template),t);r.push([s]),o.push({label:s.template.label,value:a.toString()})}let s=n.theme.createListEditor(`Please choose`,null,!1,o);s.setAttribute(`part`,`constraint-editor`);let c=s.querySelector(`.editor`);c.onchange=async()=>{if(c.value){let e=r[parseInt(c.value)];if(n.queryMode){let{activateNodeConstraintOption:t}=await U(async()=>{let{activateNodeConstraintOption:e}=await import(`./mode-_I_CsUK6.js`);return{activateNodeConstraintOption:e}},[]);await t(e,a);return}let i;if(e.length){for(let n of e)await n.bindValues(t.nodeId,!1);i=e[0],a.replaceWith(e[0]),i.updateControls()}for(let t=1;t<e.length;t++)i.after(e[t]),i=e[t],i.updateControls()}},a.appendChild(s)}else{let s=[];for(let t=0;t<e.length;t++){let r=n.store.getQuads(e[t],null,null,null);if(r.length){s.push(r);let e=E(r,n.languages);for(let t of r)t.predicate.equals(de)&&(e||=E(n.store.getQuads(t.object,null,null,null),n.languages));o.push({label:e||O(r[0].predicate.value,F)+` = `+O(r[0].object.value,F),value:(s.length-1).toString()})}}let c=n.theme.createListEditor(t.template.label+`?`,null,!1,o,t.template);c.setAttribute(`part`,`constraint-editor`);let l=c.querySelector(`.editor`);l.onchange=async()=>{if(l.value){let e=B(z(i??t.template),s[parseInt(l.value)]);if(e.or=void 0,e.xone=void 0,n.queryMode){let{activatePropertyConstraintOption:n}=await U(async()=>{let{activatePropertyConstraintOption:e}=await import(`./mode-_I_CsUK6.js`);return{activatePropertyConstraintOption:e}},[]);await n(e,t,a);return}if(r||Le(t.template)>1){let n=await X(e,void 0,!0,!1,t.parent);n.dataset.path=t.template.path,r&&(n.dataset.predicate=r),a.replaceWith(n),n.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0}));return}e.pathAlternatives=void 0;let o=new Y(e,t.parent);t.replaceWith(o),await o.updateControls()}},a.appendChild(c)}return a}function We(e,t,n,r=!1){let i=document.createElement(`div`);i.classList.add(`alternative-path-constraint`),i.setAttribute(`part`,`constraint`),i.dataset.path=e.template.path;let a=e.template.pathAlternatives.map((e,t)=>({label:O(e,F),value:t.toString()})),o=e.template.config.theme.createListEditor(`${e.template.label}: path`,null,!1,a,e.template);o.setAttribute(`part`,`constraint-editor`);let s=o.querySelector(`.editor`);return s.onchange=async()=>{if(s.value===``)return;let r=e.template.pathAlternatives[parseInt(s.value)],a=await e.addPropertyInstance(t,n,!0,r,!1);a&&(i.replaceWith(a),a.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0})))},i.appendChild(o),Z(i,e.template.label,e.template.config.theme.dense,e.template.config.hierarchyColorsStyleSheet!==void 0,r),i}function Ge(e,t,n){if(t.termType===`Literal`){let r=t.datatype;for(let t of e){let e=n.store.getQuads(t,null,null,null);for(let t of e)if(t.predicate.value===`http://www.w3.org/ns/shacl#datatype`&&t.object.equals(r))return e}}else{let r=n.store.getObjects(t,v,null);for(let t of e){let e=n.store.getQuads(t,null,null,null);for(let t of e)if(r.length>0){if(t.predicate.value===`http://www.w3.org/ns/shacl#node`){for(let i of r)if(n.store.getQuads(t.object,w,i,null).length>0)return e}if(t.predicate.equals(C)){for(let n of r)if(t.object.equals(n))return e}}else if(t.predicate.equals(fe)&&t.object.equals(ue))return e}}return console.error(`couldn't resolve sh:or/sh:xone on property for value`,t),[]}function Ke(e,t,n){for(let r of e){let e=!1,i=n.store.getObjects(r,S,null);for(let r of i){let i=n.store.getObjects(r,`${h}path`,null);for(let r of i)if(e=n.store.countQuads(t,r,null,null)>0,e)break}if(e)return i}return console.error(`couldn't resolve sh:or/sh:xone on node for value`,t),[]}var qe=`:host {
2
- --shacl-font-family: inherit;
3
- --shacl-font-size: 14px;
4
- --shacl-text-color: #333;
5
- --shacl-muted-color: #555;
6
- --shacl-border-color: #DDD;
7
- --shacl-bg: #FFF;
8
- --shacl-row-alt-bg: #F8F8F8;
9
- --shacl-error-color: #C00;
10
- --shacl-label-width: 8em;
11
- }
12
- form { display:block; --label-width: var(--shacl-label-width, 8em); --caret-size: 10px; font-family: var(--shacl-font-family); font-size: var(--shacl-font-size); color: var(--shacl-text-color); background-color: var(--shacl-bg); }
13
- form.mode-edit { padding-left: 1em; }
14
- form, form * { box-sizing: border-box; }
15
- shacl-node, .collapsible::part(content) { display: flex; flex-direction: column; width: 100%; position: relative; }
16
- shacl-node .remove-button { margin-top: 1px; }
17
- shacl-node .add-button-wrapper { display: flex; width: 100%; justify-content: flex-end; gap: 20px; padding-right: 24px; color: var(--shacl-muted-color); font-size: 14px; }
18
- shacl-node .add-button::part(button)::before { content: '+ ' }
19
- shacl-node .link-button::part(button)::before { content: '🔗 '; font-size: 10px; }
20
- shacl-node h1 { font-size: 16px; border-bottom: 1px solid #AAA; margin-top: 4px; color: var(--shacl-muted-color); }
21
- shacl-property:not(:has(>.collapsible)), shacl-property>.collapsible::part(content) { display: flex; flex-direction: column; align-items: end; position: relative; }
22
- shacl-property:not(.may-add) > .add-button-wrapper, shacl-property:not(.may-add) > .collapsible > .add-button-wrapper { display: none; }
23
- shacl-property:not(.may-remove) > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
24
- shacl-property:not(.may-remove) > .collapsible > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
25
- shacl-property:not(.may-remove) > .shacl-or-constraint > .remove-button-wrapper > .remove-button:not(.persistent),
26
- shacl-property:not(.may-remove) > .alternative-path-constraint > .remove-button-wrapper > .remove-button:not(.persistent),
27
- shacl-property:not(.may-remove) > .collapsible > .alternative-path-constraint > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
28
- .mode-view .shacl-group:not(:has(shacl-property)) { display: none; }
29
- .property-instance, .shacl-or-constraint, .alternative-path-constraint { display: flex; align-items: flex-start; padding: 4px 0; width: 100%; position: relative; }
30
- .shacl-or-constraint > div, .alternative-path-constraint > div { display: flex; align-items: flex-start; }
31
- .shacl-or-constraint > div:first-child, .alternative-path-constraint > div:first-child { flex-grow: 1 }
32
- .shacl-or-constraint label, .alternative-path-constraint label { display: inline-block; word-break: break-word; width: var(--label-width); line-height: 1em; padding-top: 0.15em; padding-right: 1em; flex-shrink: 0; position: relative; }
33
- .property-instance label[title] { cursor: help; text-decoration: underline dashed #AAA; }
34
- .property-instance.linked label:after, label.linked:after { content: '\\1F517'; font-size: 0.6em; position: absolute; top: 3px; right: 3px; }
35
- .mode-edit .property-instance label.required::before, .add-button-wrapper.required > .add-button::before, .add-button-wrapper.required > .link-button::before { color: var(--shacl-error-color); content: '\\2736'; font-size: 0.6rem; position: absolute; left: -1.4em; }
36
- .mode-edit .add-button-wrapper.required > .add-button::before, .add-button-wrapper.required > .link-button::before { left: -0.5em; }
37
- .mode-edit .property-instance label.required::before { top: 0.15rem; }
38
- .property-instance.valid::before { content: ''; position: absolute; left: calc(var(--label-width) - 1em); top:0.5em; width: 0.9em; height: 0.9em; background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1024 1024" fill="green" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M866.133333 258.133333L362.666667 761.6l-204.8-204.8L98.133333 618.666667 362.666667 881.066667l563.2-563.2z"/></svg>'); }
39
- .editor:not([type='checkbox']) { flex-grow: 1; }
40
- textarea.editor { resize: vertical; }
41
- .lang-chooser { border: 0; background-color: #e9e9ed; padding: 2px 4px; align-self: flex-start; }
42
- .validation-error { position: absolute; left: calc(var(--label-width) - 1em); color: var(--shacl-error-color); cursor: help; }
43
- .validation-error::before { content: '\\26a0' }
44
- .validation-error.node { left: -1em; }
45
- .invalid > .editor { border-color: red !important; }
46
- .ml-0 { margin-left: 0 !important; }
47
- .pr-0 { padding-right: 0 !important; }
48
- .mode-view .property-instance:not(:first-child) > label { visibility: hidden; }
49
- .mode-view .property-instance label { width: var(--label-width); }
50
-
51
- .d-flex { display: flex; }
52
- .lang { opacity: 0.65; font-size: 0.6em; }
53
- a, a:visited { color: inherit; }
54
- h3 { margin-top: 0; }
55
-
56
- .fadeIn, .fadeOut { animation: fadeIn 0.2s ease-out; }
57
- .fadeOut { animation-direction: reverse; animation-timing-function: ease-out;}
58
- @keyframes fadeIn {
59
- 0% { opacity: 0; transform: scaleY(0.8); }
60
- 100% { opacity: 1; transform: scaleY(1); }
61
- }
62
- .collapsible::part(label) { font-weight: 600; }
63
- .collapsible > .property-instance:nth-child(even) { background-color: var(--shacl-row-alt-bg); }
64
- .collapsible > .property-instance > shacl-node > h1 { display: none; }
65
- .ref-link { cursor: pointer; }
66
- .ref-link:hover { text-decoration: underline; }
67
- .node-id-display { color: var(--shacl-muted-color); font-size: 11px; }
68
- /* hierarchy colors */
69
- .colorize { --hierarchy-color-width: 3px; padding: 0 1px 0 calc(1px + var(--hierarchy-color-width)); align-self: stretch; position: relative; }
70
- .colorize::before {
71
- content: '';
72
- position: absolute;
73
- width: var(--hierarchy-color-width);
74
- top: 0; bottom: 0; left: 0;
75
- --index: mod(var(--hierarchy-level), var(--hierarchy-colors-length));
76
- background: linear-gradient(var(--hierarchy-colors)) no-repeat 0 calc(var(--index) * 100% / (var(--hierarchy-colors-length) - 1)) / 100% calc(1px * infinity);
77
- }
78
- .property-instance:not(:has(shacl-node)) > .colorize::before { background: 0; }
79
- .colorize:not(:has(.remove-button)) { padding-left: calc(8px + var(--hierarchy-color-width)); }
80
- .mode-view .property-instance > .colorize { order: -1; }
81
- .link-option { padding: 10px; }
82
- .link-option:hover { background-color: #F5F5F5; cursor: pointer; }
83
- rokit-dialog.link-chooser::part(dialog) { min-height: min(434px, 90vh); width: min(90vw, 600px); }
84
- rokit-select::part(facet-count) { color: var(--shacl-muted-color); }
85
- rokit-select::part(facet-count)::after { content: attr(data-count); color: inherit; display: inline-block; font-family: monospace; margin-left: 7px; font-size: 12px; }
86
- `,Je=class{constructor(e){this.dense=!0;let t=qe;e&&(t+=`
87
- `+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}setDense(e){this.dense=e}createViewer(e,t,i){let a=document.createElement(`div`),o=document.createElement(`label`);o.textContent=`${e}:`,i.description&&o.setAttribute(`title`,i.description.value),a.appendChild(o);let s=t.value,c=null;if(t instanceof r){let e=i.config.store.getQuads(s,null,null,null);if(e.length){let t=E(e,i.config.languages);t&&(s=t)}}else t instanceof n&&(t.language?(c=document.createElement(`span`),c.classList.add(`lang`),c.innerText=`@${t.language}`):t.datatype.value===`http://www.w3.org/2001/XMLSchema#date`?s=new Date(Date.parse(t.value)).toDateString():t.datatype.value===`http://www.w3.org/2001/XMLSchema#dateTime`&&(s=new Date(Date.parse(t.value)).toLocaleString()));let l;return j(t.value)?(l=document.createElement(`a`),l.setAttribute(`href`,t.value)):l=document.createElement(`div`),l.classList.add(`d-flex`),l.innerText=s,c&&l.appendChild(c),a.appendChild(l),a}};function Ye(e,t,r){if(r){let r=R(e)>0;if(e.class&&!e.hasValue)return e.config.theme.createListEditor(e.label,t,r,A(e.class,e),e);if(e.in){let n=e.config.lists[e.in];if(n?.length){let i=D(n,e.config.store,e.config.languages);return e.config.theme.createListEditor(e.label,t,r,i,e)}else console.error(`list not found:`,e.in,`existing lists:`,e.config.lists)}if(e.datatype?.equals(y)||e.languageIn?.length||e.datatype===void 0&&t instanceof n&&t.language)return e.config.theme.createLangStringEditor(e.label,t,r,e);switch(e.datatype?.value.replace(te,``)){case`integer`:case`float`:case`double`:case`decimal`:return e.config.theme.createNumberEditor(e.label,t,r,e);case`date`:case`dateTime`:return e.config.theme.createDateEditor(e.label,t,r,e);case`boolean`:return e.config.theme.createBooleanEditor(e.label,t,r,e);case`base64Binary`:return e.config.theme.createFileEditor(e.label,t,r,e)}return e.config.theme.createTextEditor(e.label,t,r,e)}else return t?e.config.theme.createViewer(e.label,t,e):document.createElement(`div`)}function Xe(e,t){e.rdfTerm=t??void 0,e.rdfTermState=t?nt(e):void 0}function Ze(e,t){e.rdfTerms=new Map;for(let n of t)e.rdfTerms.set(Qe(n),n)}function Qe(e){return c(e)}function $e(e){let t=e.rdfTerms?.get(e.value);if(t)return t;if(!(!e.rdfTerm||!rt(e.rdfTermState,nt(e))))return e.rdfTerm}function G(i){let a=$e(i);if(a)return a;let o=i.shaclDatatype,s=i.dataset.value||i.value;if((i.type===`file`||i.getAttribute(`type`)===`file`)&&i.binaryData)s=i.binaryData;else if(i.type===`checkbox`||i.getAttribute(`type`)===`checkbox`)return i.checked||parseInt(i.dataset.minCount||`0`)>0?t.literal(i.checked?`true`:`false`,o):void 0;if(!s)return;let c=i.dataset.nodeKind,l=et(s);if(i.dataset.link)return t.fromTerm(JSON.parse(i.dataset.link));if(i.dataset.class)return l instanceof r||l instanceof e?l:t.namedNode(s);if(c===`http://www.w3.org/ns/shacl#IRI`)return l instanceof r?l:t.namedNode(s);if(c===`http://www.w3.org/ns/shacl#BlankNode`)return l instanceof e?l:t.blankNode(s);if(c===`http://www.w3.org/ns/shacl#BlankNodeOrIRI`)return l instanceof r||l instanceof e?l:t.namedNode(s);if(l instanceof r||l instanceof e||l instanceof n&&!i.dataset.lang&&(!o||o instanceof r&&pe.equals(o)))return l;if(i.dataset.lang)o=i.dataset.lang;else if(o instanceof r&&_e.has(o.value)){let e=tt(s);if(e===void 0)return;s=e}else i.type===`number`?s=parseFloat(s):i.type===`datetime-local`?s=ke(s,i.dataset.xsdTemporalSuffix):i.type===`date`&&o instanceof r&&o.value===`http://www.w3.org/2001/XMLSchema#date`&&(s=Oe(s,i.dataset.xsdTemporalSuffix));return t.literal(s,o)}function et(i){let a=i;if(i.startsWith(`<`)&&i.endsWith(`>`))a=i.slice(1,-1);else if(!i.startsWith(`_:`)&&!i.startsWith(`"`))return;let o=s(a,t);return o instanceof r||o instanceof e||o instanceof n?o:void 0}function tt(e){let t=e.replace(`,`,`.`);return/^[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?$/.test(t)?t:void 0}function nt(e){return{value:e.value,language:e.dataset.lang,checked:e.checked,binaryData:e.binaryData}}function rt(e,t){return e?.value===t.value&&e.language===t.language&&e.checked===t.checked&&e.binaryData===t.binaryData}function it(e,t,n){if(t===`application/ld+json`)return at(e);{let r=new o({format:t,prefixes:n});r.addQuads(e);let i=``;return r.end((e,t)=>{e&&console.error(e),i=t}),i}}function at(e){let t=[];for(let r of e){let e={"@id":r.subject.id};if(r.predicate===v)e[`@type`]=r.object.id;else{let t=r.object.value;r.object instanceof n?r.object.language?t={"@language":r.object.language,"@value":r.object.value}:r.object.datatype&&r.object.datatype.value!==`http://www.w3.org/2001/XMLSchema##string`&&(t={"@type":r.object.datatype.value,"@value":r.object.value}):t={"@id":r.object.id},e[r.predicate.value]=t}t.push(e)}return JSON.stringify(t)}var K={};function ot(e){e.predicate===void 0&&e.datatype===void 0?console.warn(`not registering plugin because it does neither define "predicate" nor "datatype"`,e):K[`${e.predicate}^${e.datatype}`]=e}function st(){return Object.entries(K).map(e=>e[1])}function ct(e,t){let n=K[`${e}^${t}`];return n||(n=K[`${e}^undefined`],n)?n:K[`undefined^${t}`]}var lt=class{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)}};function ut(e){let t=new Set;for(let n of e.getQuads(null,b,null,_))n.subject.termType===`NamedNode`&&t.add(n.subject.value);if(t.size===1)return t.values().next().value}function dt(e,n){let r=t.namedNode(n);for(let t of e.getObjects(r,b,_))if(t.termType===`NamedNode`&&e.getQuads(t,v,le,null).length>0)return t}async function ft(e){let t={store:new i,importedUrls:[],atts:e},n=[];if(e.shapes?n.push(q(I({rdf:e.shapes}),t,g)):e.shapesUrl&&n.push(q(I({url:e.shapesUrl,proxy:t.atts.proxy,rdfUrlResolver:t.atts.rdfUrlResolver}),t,g)),e.values?n.push(q(I({rdf:e.values}),t,_)):e.valuesUrl&&n.push(q(I({url:e.valuesUrl,proxy:t.atts.proxy,rdfUrlResolver:t.atts.rdfUrlResolver}),t,_)),await Promise.all(n),e.classInstanceProvider)try{let n=Ae(t.store),r=await e.classInstanceProvider(n);r&&await q(I({rdf:r}),t,g)}catch(e){console.error(`failed loading class instances`,e)}if(e.valuesSubject||=ut(t.store)||null,e.valuesSubject&&t.store.countQuads(null,null,null,g)===0){let n=[...t.store.getObjects(e.valuesSubject,v,_),...t.store.getObjects(e.valuesSubject,b,_)],r=[];for(let e of n){let n=pt(e.value);!n&&e.value.startsWith(`urn:`)&&t.atts.proxy&&(n=e.value),n&&t.importedUrls.indexOf(n)<0&&(t.importedUrls.push(n),r.push(q(I({url:n,proxy:t.atts.proxy,rdfUrlResolver:t.atts.rdfUrlResolver}),t,g)))}try{await Promise.allSettled(r)}catch(e){console.warn(e)}}return t.store}async function q(e,n,r){let i=await e,a=[];for(let e of i){let i=r;if(n.atts.valuesSubject&&_.equals(r)&&e.graph.id&&e.graph.id!==n.atts.valuesSubject&&(i=e.graph),n.store.add(t.quad(e.subject,e.predicate,e.object,i)),n.atts.loadOwlImports&&x.equals(e.predicate)){let r=pt(e.object.value);r&&n.importedUrls.indexOf(r)<0&&(n.importedUrls.push(r),a.push(q(I({url:r,proxy:n.atts.proxy,rdfUrlResolver:n.atts.rdfUrlResolver}),n,t.namedNode(r))))}}await Promise.allSettled(a)}function pt(e){if(j(e))return e;let t=e.split(`:`);if(t.length===2){let n=F[t[0]];if(n&&(e=e.replace(`${t[0]}:`,n),j(e)))return e}return null}async function mt(e){if(e.template.nodeShapes.size===0)return;let t=e.template.config.resourceLinkProvider;if((!t||t&&!t.lazyLoad)&&(await yt(e.template),gt(e).length===0))return;let n=e.template.config.theme.createButton(e.template.label,!1);n.title=`Link existing `+e.template.label,n.classList.add(`link-button`),n.setAttribute(`text`,``);let r=n.getAttribute(`part`);return n.setAttribute(`part`,`${r?r+` `:``}link-button`),n.addEventListener(`click`,async()=>{t?.lazyLoad&&(n.classList.add(`loading`),await yt(e.template),n.classList.remove(`loading`));let r=gt(e);if(r.length===0)n.innerText=`No linkable resources found`,n.setAttribute(`disabled`,``),setTimeout(()=>n.remove(),2e3);else{let t=e.template.config.form.querySelector(`#dialog`);t||(t=new p,t.classList.add(`link-chooser`),t.closable=!0,e.template.config.form.appendChild(t)),t.title=`Link existing `+e.template.label,ht(t,e,r),t.open=!0}}),n}function ht(e,t,n){let r=document.createElement(`div`);for(let i of n){let n=document.createElement(`div`);n.classList.add(`link-option`),n.title=`Link this resource`,n.innerText=i.label||i.value.value,n.addEventListener(`click`,async()=>{await _t(i,t),e.open=!1}),r.appendChild(n)}e.replaceChildren(r)}function gt(e){let n=e.template.config,r=vt(e.template),a=new Set(Array.from(e.querySelectorAll(`:scope > .property-instance > shacl-node, :scope > .collapsible > .property-instance > shacl-node`)).map(e=>e.nodeId.id)),o=new Map;for(let t of n.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`)){if(!r.has(t.template.id.value)||a.has(t.nodeId.id))continue;let s=new i;t.toRDF(s),o.set(t.nodeId.id,{value:t.nodeId,label:E([...s.getQuads(t.nodeId,null,null,null),...n.store.getQuads(t.nodeId,null,null,null)],n.languages)||n.providedResourceLabels[t.nodeId.value],template:e.template})}if(n.resourceLinkProvider)for(let i of r)for(let r of n.providedConformingResourceIds[i]??[]){let i=t.namedNode(r);!a.has(i.id)&&!o.has(i.id)&&o.set(i.id,{value:i,label:n.providedResourceLabels[r]||E(n.store.getQuads(i,null,null,null),n.languages),template:e.template})}return[...o.values()]}async function _t(e,t){let n=e.value.value;if(e.value.termType===`NamedNode`&&e.template.config.providedResources[n]?.length>0){let t={store:e.template.config.store,importedUrls:[],atts:{loadOwlImports:!1}};await q(I({rdf:e.template.config.providedResources[n]}),t,g),e.template.config.providedResources[n]=``}let r=await X(e.template,e.value,!0,!0);t.container.insertBefore(r,t.querySelector(`:scope > .add-button-wrapper`)),await t.updateControls()}function vt(e){return new Set(Array.from(e.nodeShapes,e=>e.id.value))}async function yt(e){let t=e.config.resourceLinkProvider;if(!t)return;let n=vt(e);if(n.size===0)return;let r=je(Object.keys(e.config.providedConformingResourceIds),n);if(r.length!==0)try{let n=await t.listConformingResources(r,e);if(n){for(let t of Object.keys(n)){let r=new Set(n[t]);e.config.providedConformingResourceIds[t]=r,await bt(r,!1,e.config)}for(let t of r)e.config.providedConformingResourceIds[t]||(e.config.providedConformingResourceIds[t]=new Set)}}catch(e){console.error(`failed loading conforming resources`,e)}}async function bt(e,t,n){if(n.resourceLinkProvider&&e.size>0){let r=[];for(let t of e)n.providedResources[t]||r.push(t);if(r.length===0)return[];try{let e=await n.resourceLinkProvider.loadResources(r);if(e){let r={store:n.store,importedUrls:[],atts:{loadOwlImports:!1}};for(let i of e){n.providedResources[i.resourceId]=i.resourceRDF;let e=await I({rdf:i.resourceRDF});n.providedResourceLabels[i.resourceId]=E(e.filter(e=>e.subject.value===i.resourceId),n.languages),t&&await q(Promise.resolve(e),r,g)}return e}for(let e of r)n.providedResources[e]||(n.providedResources[e]=``)}catch(e){console.error(`failed loading resources`,e)}}return[]}async function xt(e){let t=new Set;for(let n of e.store.getQuads(null,null,null,_))St(n.object,e.store)&&t.add(n.object.value);await bt(t,!0,e)}function St(e,t){return e.termType===`NamedNode`&&t.countQuads(e,null,null,null)===0}var J=`:scope > .add-button-wrapper, :scope > .collapsible > .add-button-wrapper`,Ct=`:scope > .property-instance, :scope > .shacl-or-constraint, :scope > .alternative-path-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance, :scope > .collapsible > .alternative-path-constraint`,Y=class extends HTMLElement{constructor(e,t){if(super(),this.template=e,this.parent=t,this.container=this,this.setAttribute(`part`,`property`),this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){let t=new f;t.classList.add(`collapsible`,`shacl-group`),t.open=e.config.attributes.collapse===`open`,t.label=this.template.label,t.setAttribute(`part`,`collapsible`),this.container=t,this.appendChild(this.container)}this.template.cssClass&&this.classList.add(this.template.cssClass),e.config.editMode&&!t.linked&&this.addEventListener(`change`,async()=>{await this.updateControls()})}async bindValues(e,t){if(this.template.path){let n=!1;if(e){let r=(this.template.pathAlternatives??[this.template.path]).flatMap(t=>this.template.config.store.getQuads(e,t,null,this.parent.linked?null:_));t&&(r=await this.filterValidValues(r,e));for(let e of r)this.parent.linked||this.template.config.store.delete(e),await this.addPropertyInstance(e.object,!_.equals(e.graph)||this.template.config.providedResources[e.object.value]!==void 0,this.template.config.providedResources[e.object.value]!==void 0,e.predicate.value),this.template.hasValue&&e.object.equals(this.template.hasValue)&&(n=!0)}this.template.config.editMode&&this.template.hasValue&&!n&&!this.parent.linked&&await this.addPropertyInstance(this.template.hasValue)}}async initializeQuery(){let{initializeQueryProperty:e}=await U(async()=>{let{initializeQueryProperty:e}=await import(`./mode-_I_CsUK6.js`);return{initializeQueryProperty:e}},[]);await e(this)}async addPropertyInstance(e,t,n=!1,r,i=!0){let a;if(this.template.pathAlternatives&&!r)this.template.config.editMode&&(a=We(this,e,t,n));else{let i=r?this.template.pathAlternativeBranches?.[r]:void 0,o=r&&(r!==this.template.path||i)?z(this.template):this.template;if(r&&(o.path=r),i&&(Re(o,i,!0),o.label=i.name?.value||i.label||o.label),o.or?.length||o.xone?.length){let t=o.or?.length?o.or:o.xone,i=!1;if(e){let n=Ge(t,e,o.config);n.length&&(a=await X(B(z(o),n),e,!this.parent.linked,this.parent.linked,this.parent),i=!0)}!i&&o.config.editMode&&(a=W(t,this,o.config,r,o),Z(a,``,o.config.theme.dense,o.config.hierarchyColorsStyleSheet!==void 0,n))}else a=await X(o,e,n,t||this.parent.linked,this.parent)}return a&&(a.dataset.path=this.template.path,r&&(a.dataset.predicate=r),i&&this.container.insertBefore(a,this.querySelector(J))),a}async updateControls(){this.template.config.editMode&&!this.parent.linked&&!this.querySelector(J)&&this.container.appendChild(await this.createAddControls());let e=R(this.template),t=this.template.nodeShapes.size===0,n=this.querySelector(`:scope > .add-button-wrapper > .link-button, :scope > .collapsible > .add-button-wrapper > .link-button`)===null,r=t||!this.hasRecursiveNodeShape(),i=this.instanceCount();i===0&&r&&(t||n&&e>0)&&(await this.addPropertyInstance(),i=1),t||this.querySelector(J)?.classList.toggle(`required`,i<e);let a;a=e>0?i>e:!t||i>1;let o=i<Le(this.template);this.classList.toggle(`may-remove`,a),this.classList.toggle(`may-add`,o)}instanceCount(){return this.querySelectorAll(Ct).length}refreshClassInstances(){if(!(!this.template.class||this.template.hasValue||!this.template.config.editMode))for(let e of this.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`)){let t=e.querySelector(`:scope > .editor`);if(!t||t.dataset.class!==this.template.class.value)continue;let n=G(t),r=A(this.template.class,this.template);n&&!wt(r,n)&&r.push({value:n,children:[]});let i=Tt(r);if(t.dataset.classInstances===i)continue;let a=this.template.config.theme.createListEditor(this.template.label,n??null,R(this.template)>0,r,this.template).querySelector(`.editor`);a.dataset.classInstances=i,t.replaceWith(a)}}hasRecursiveNodeShape(){let e=new Set;this.parent.ancestorShapeIds.forEach(t=>e.add(t)),e.add(this.parent.template.id.value);for(let t of this.template.nodeShapes)if(e.has(t.id.value))return!0;return!1}toRDF(e,n){for(let r of this.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`)){let i=t.namedNode(r.dataset.predicate??this.template.path);if(r.firstChild instanceof $){let t=r.firstChild.toRDF(e);e.addQuad(n,i,t,this.template.config.valuesGraphId)}else if(this.template.config.editMode)for(let t of r.querySelectorAll(`:scope > .editor`)){let r=G(t);r&&e.addQuad(n,i,r,this.template.config.valuesGraphId)}else{let t=G(r);t&&e.addQuad(n,i,t,this.template.config.valuesGraphId)}}}async filterValidValues(e,t){let n=this.template.id,r=[t];if(this.template.qualifiedValueShape){n=this.template.qualifiedValueShape.id,r=[];for(let t of e)r.push(t.object)}let i=await this.template.config.validator.validate({dataset:this.template.config.store,terms:r},[{terms:[n]}]),a=new Set;for(let e of i.results){let t=this.template.qualifiedValueShape?e.focusNode:e.value;t?.ptrs?.length&&a.add(t.ptrs[0]._term.id)}return e.filter(e=>!a.has(e.object.id))}async createAddControls(){let e=document.createElement(`div`);e.classList.add(`add-button-wrapper`),e.setAttribute(`part`,`add-controls`);let t=await mt(this);t&&e.appendChild(t);let n=this.template.config.theme.createButton(this.template.label,!1);n.title=`Add `+this.template.label,n.classList.add(`add-button`),n.setAttribute(`text`,``);let r=n.getAttribute(`part`);return n.setAttribute(`part`,`${r?r+` `:``}add-button`),n.addEventListener(`click`,async()=>{let e=await this.addPropertyInstance();e&&(e.classList.add(`fadeIn`),await this.updateControls(),this.template.nodeShapes.size&&this.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0})),setTimeout(()=>{ye(e),e.classList.remove(`fadeIn`)},200))}),e.appendChild(n),e}};function wt(e,t){return e.some(e=>typeof e.value!=`string`&&e.value.equals(t)||wt(e.children??[],t))}function Tt(e){return JSON.stringify(e.map(e=>[typeof e.value==`string`?e.value:`${e.value.termType}:${e.value.value}`,e.label,Tt(e.children??[])]))}async function X(e,t,n=!1,r=!1,i){let a;if(e.nodeShapes.size){a=document.createElement(`div`),a.classList.add(`property-instance`),a.setAttribute(`part`,`property-instance`);let n=new Set(i?.ancestorShapeIds??[]);i&&n.add(i.template.id.value);for(let i of e.nodeShapes){let o=new $(i,t,e.nodeKind,e.label,r,n);a.appendChild(o),await o.ready}}else{let n=ct(e.path,e.datatype?.value);a=n?e.config.editMode&&!r?n.createEditor(e,t):n.createViewer(e,t):Ye(e,t||null,e.config.editMode&&!r),a.childNodes.length>0&&(a.classList.add(`property-instance`),a.setAttribute(`part`,`property-instance`)),r&&a.classList.add(`linked`)}return e.config.editMode&&(!r||n)?Z(a,e.label,e.config.theme.dense,e.config.hierarchyColorsStyleSheet!==void 0,n):e.config.hierarchyColorsStyleSheet!==void 0&&a.appendChild(Q(!0)),t&&!e.config.editMode&&Xe(a,t),a.dataset.path=e.path,a}function Z(e,t,n,r,i=!1){let a=Q(r),o=new d;o.classList.add(`remove-button`,`clear`),o.title=`Remove `+t,o.dense=n,o.icon=!0;let s=o.getAttribute(`part`);o.setAttribute(`part`,`${s?s+` `:``}remove-button`),o.addEventListener(`click`,()=>{e.classList.remove(`fadeIn`),e.classList.add(`fadeOut`),setTimeout(()=>{let t=e.parentElement;e.remove(),t?.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0}))},200)}),i&&o.classList.add(`persistent`),a.appendChild(o),e.appendChild(a)}function Q(e){let t=document.createElement(`div`);return t.className=`remove-button-wrapper`,t.setAttribute(`part`,`remove-controls`),e&&t.classList.add(`colorize`),t}window.customElements.define(`shacl-property`,Y);function Et(e,t){let n=e,r=t.store.getQuads(e,null,null,null),i=T(r,`label`,re,t.languages);i&&(n=i);let a;if(t.attributes.collapse!==null)a=new f,a.classList.add(`collapsible`),a.open=t.attributes.collapse===`open`,a.label=n,a.setAttribute(`part`,`group collapsible`);else{a=document.createElement(`div`);let e=document.createElement(`h1`);e.innerText=n,e.setAttribute(`part`,`group-title`),a.appendChild(e),a.setAttribute(`part`,`group`)}a.dataset.subject=e,a.classList.add(`shacl-group`);let o=parseInt(T(r,`order`)??``)||0;return{element:a,order:o}}var Dt={[`${h}node`]:(e,t)=>{e.extendedShapes.add(new Ot(t,e.config,e))},[`${h}and`]:(e,t)=>{for(let n of e.config.lists[t.value])e.extendedShapes.add(new Ot(n,e.config,e))},[`${h}property`]:(e,t)=>{let n=e.config.getPropertyTemplate(t,e),r=V(n);if(r){let t=e.properties[r];if(t||(t=[],e.properties[r]=t),n.qualifiedValueShape)t.push(n);else{let i;for(let t=0;t<e.properties[r].length&&!i;t++)e.properties[r][t].qualifiedValueShape||(i=e.properties[r][t]);i?Re(i,n):t.push(n)}}},[`${h}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${h}targetClass`]:(e,t)=>{e.targetClass=t},[`${h}or`]:(e,t)=>{e.or=e.config.lists[t.value]},[`${h}xone`]:(e,t)=>{e.xone=e.config.lists[t.value]},[x.id]:(e,t)=>{e.owlImports.add(t)},[`${ae}title`]:(e,t)=>{let n=t;e.label=M(e.config.languages,e.label,n)},[`${re}label`]:(e,t)=>{let n=t;e.label=M(e.config.languages,e.label,n)}},Ot=class{constructor(e,t,n){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.merged=!1,this.id=e,this.config=t,this.parent=n,t.registerNodeTemplate(this),kt(this,this.config.store.getQuads(e,null,null,null))}};function kt(e,t){for(let n of t)Dt[n.predicate.id]?.call(e,e,n.object);return At(e),e}function At(e){let t=Object.values(e.properties).flat().filter(e=>e.pathAlternatives?.length),n=new Set;for(let r of t){let t={};r.pathAlternatives.every(n=>{let r=e.properties[n];return r?.length!==1||jt(r[0])?!1:(t[n]=r[0],!0)})&&(r.pathAlternativeBranches=t,r.pathAlternatives.forEach(e=>n.add(e)))}for(let t of n)delete e.properties[t]}function jt(e){return e.minCount!==void 0||e.maxCount!==void 0||e.qualifiedMinCount!==void 0||e.qualifiedMaxCount!==void 0||e.qualifiedValueShape!==void 0}function Mt(e){if(!e.merged){e.merged=!0;for(let t of Object.values(e.properties))for(let n of t){let[t,r]=Rt(e,V(n)),i=t.some(e=>e.qualifiedValueShape!==void 0),a=Nt(t),o=i?a:r;if(t.length>1&&o){let e=t[t.length-1];for(let n=t.length-2;n>=0;n--){let r=t[n],i=a?e.qualifiedValueShape:void 0;delete r.parent.properties[V(r)],Re(e,r,!0),i&&e.nodeShapes.delete(i)}Ft(e)}}}}function Nt(e){if(e.length<2)return!1;for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(!n.qualifiedValueShape||!r.qualifiedValueShape||!Pt(n.parent,r.parent)||!Pt(n.qualifiedValueShape,r.qualifiedValueShape))return!1}return!0}function Pt(e,t){let n=[...e.extendedShapes],r=new Set;for(;n.length;){let e=n.pop();if(e.id.equals(t.id))return!0;r.has(e)||(r.add(e),n.push(...e.extendedShapes))}return!1}function Ft(e){for(let t of[`xone`,`or`]){let n=e[t];if(!n?.length)continue;let r=n.filter(t=>It(t,e));r.length>0&&r.length<n.length&&(r.length===1?(e[t]=void 0,B(e,e.config.store.getQuads(r[0],null,null,null))):e[t]=r)}}function It(e,t){let n=t.config.store.getQuads(e,null,null,null);return Lt(n,`http://www.w3.org/ns/shacl#datatype`,t.datatype)&&Lt(n,C.id,t.class)&&Lt(n,`http://www.w3.org/ns/shacl#nodeKind`,t.nodeKind)}function Lt(e,t,n){if(!n)return!0;let r=!1;for(let i of e)if(i.predicate.value===t&&(r=!0,i.object.equals(n)))return!0;return!r}function Rt(e,t,n=new Set,r=[],i=!1){if(!n.has(e.id.value)){n.add(e.id.value);let a=e.properties[t];if(a?.length===1){r.push(a[0]),i||=a[0].maxCount===1;for(let e of a[0].nodeShapes){let[a,o]=Rt(e,t,n,r,i);i||=o}}for(let a of e.extendedShapes){let[e,o]=Rt(a,t,n,r,i);i||=o}}return[r,i]}var $=class e extends HTMLElement{constructor(n,r,a,o,s,c=new Set,l){super(),this.template=n,this.linked=s??!1,this.ancestorShapeIds=c,this.queryContext=l,this.setAttribute(`part`,`node`);let u=r;u||=(!a&&n.nodeKind&&(a=n.nodeKind),a===void 0&&n.config.attributes.valuesNamespace||a?.value===`http://www.w3.org/ns/shacl#IRI`?t.namedNode(n.config.attributes.valuesNamespace+m()):t.blankNode(m())),this.nodeId=u;let d=JSON.stringify([n.id,this.nodeId]);if(r&&n.config.renderedNodes.has(d)){o||=`Link`;let e=document.createElement(`label`);e.innerText=o,e.classList.add(`linked`),this.appendChild(e);let t=this.getAttribute(`part`);this.setAttribute(`part`,`${t?t+` `:``}linked-node`),this.dataset.nodeId=this.nodeId.id;let n=document.createElement(`a`),a=r.termType===`BlankNode`?`_:`+r.value:r.value,s=Array.from(this.template.config.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`)).find(e=>e.nodeId.equals(r)),c=new i;s?.toRDF(c),n.innerText=E([...c.getQuads(r,null,null,null),...this.template.config.store.getQuads(r,null,null,null)],this.template.config.languages)||a,n.classList.add(`ref-link`),n.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${a}']:not([part~='linked-node'])`)?.scrollIntoView()},this.appendChild(n),this.style.flexDirection=`row`,this.ready=Promise.resolve()}else{n.config.renderedNodes.add(d);let t=this.ancestorShapeIds,i=this.template.id.value,a=this.queryContext;if(this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){let e=document.createElement(`div`);e.innerText=`id: ${this.nodeId.id}`,e.classList.add(`node-id-display`),this.appendChild(e)}Mt(n),this.ready=(async()=>{let c=new Set(t);c.add(i);for(let[e,t]of Object.entries(n.properties))for(let e of t)await this.addPropertyInstance(e,r,t.length>1);for(let t of n.extendedShapes){let n=new e(t,r,void 0,void 0,s,c,a);this.prepend(n),await n.ready}if(n.or?.length&&await this.tryResolve(n.or,r,n.config),n.xone?.length&&await this.tryResolve(n.xone,r,n.config),o){let e=document.createElement(`h1`);e.innerText=o,e.setAttribute(`part`,`node-title`),this.prepend(e)}})()}}toRDF(e,n,r=``){if(n||=this.nodeId,!this.linked){for(let t of this.querySelectorAll(`:scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property`))t.toRDF(e,n);this.template.targetClass&&e.addQuad(n,v,this.template.targetClass,this.template.config.valuesGraphId),r&&e.addQuad(n,t.namedNode(r),this.template.id,this.template.config.valuesGraphId)}return n}async addPropertyInstance(e,t,n){let r=null;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let t=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);if(!t){let n=Et(e.group,e.config);t=n.element,Bt(this,t,n.order)}r=t}else console.warn(`ignoring unknown group reference`,e.group,`existing groups:`,e.config.groups);let i=new Y(e,this);e.config.queryMode?await i.initializeQuery():await i.bindValues(t,n),(e.config.editMode||e.config.queryMode||i.instanceCount()>0)&&(Bt(r||this,i,e.order),e.config.queryMode||await i.updateControls())}async tryResolve(e,t,n){let r=!1;if(t){let i=Ke(e,t,n);if(i.length){for(let e of i)await this.addPropertyInstance(n.getPropertyTemplate(e,this.template),t);r=!0}}r||this.appendChild(W(e,this,n))}},zt=new WeakMap;function Bt(e,t,n=0){zt.set(t,n);let r=Array.from(e.children).find(e=>e!==t&&(zt.get(e)??0)>n);e.insertBefore(t,r??null)}window.customElements.define(`shacl-node`,$);function Vt(e){return e.datatype!==void 0&&he.has(e.datatype)}export{me as $,I as A,Ee as B,Ie as C,B as D,Fe as E,Me as F,h as G,b as H,Ce as I,v as J,te as K,A as L,F as M,P as N,ze as O,D as P,g as Q,E as R,U as S,z as T,_e as U,_ as V,ge as W,le as X,ue as Y,w as Z,Xe as _,Y as a,Je as b,dt as c,ft as d,lt as f,it as g,ot as h,Mt as i,L as j,Ne as k,ut as l,st as m,$ as n,Q as o,ct as p,y as q,Ot as r,xt as s,Vt as t,q as u,Ze as v,R as w,W as x,Qe as y,De as z};
@@ -1 +0,0 @@
1
- import{DataFactory as e}from"n3";import"rdfxml-streaming-parser";import"jsonld";var t=class{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)}},n=`http://www.w3.org/ns/shacl#`,r=`http://datashapes.org/dash#`,i=`http://www.w3.org/2001/XMLSchema#`,a=`http://www.w3.org/ns/oa#`,o=e.namedNode(`loaded-shapes`),s=e.namedNode(`loaded-data`),c=e.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`),l=e.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`);e.namedNode(`http://purl.org/dc/terms/conformsTo`);var u=e.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),d=e.namedNode(`http://www.w3.org/2002/07/owl#imports`),f=e.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),p=e.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`);e.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),e.namedNode(`http://www.w3.org/ns/shacl#IRI`),e.namedNode(`http://www.w3.org/ns/shacl#property`);var m=e.namedNode(`http://www.w3.org/ns/shacl#class`);e.namedNode(`http://www.w3.org/ns/shacl#node`),e.namedNode(`http://www.w3.org/ns/shacl#targetClass`),e.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),e.namedNode(`http://www.w3.org/2001/XMLSchema#string`),e.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`);function h(e,t,r=n,i){let a=``,o=g(e,t,r,i);return o&&(a=o.value),a}function g(e,t,r=n,i){let a,o=r+t;if(i?.length){for(let t of i)for(let n of e)if(n.predicate.value===o){if(n.object.id.endsWith(`@${t}`))return n.object;n.object.id.indexOf(`@`)<0?a=n.object:a||=n.object}}else for(let t of e)if(t.predicate.value===o)return t.object;return a}function _(e,t){return h(e,`prefLabel`,`http://www.w3.org/2004/02/skos/core#`,t)||h(e,`label`,`http://www.w3.org/2000/01/rdf-schema#`,t)||h(e,`title`,`http://purl.org/dc/terms/`,t)||h(e,`name`,`http://xmlns.com/foaf/0.1/`,t)}function v(e,t,n){let r=[];for(let i of e)r.push({value:i,label:_(t.getQuads(i,null,null,null),n),children:[]});return r}function y(t,n,r=new Map){r.set(o.id,o),r.set(s.id,s);let i=t.config.valuesGraphId??e.defaultGraph();r.set(i.id,i);for(let e of t.owlImports)b(e,n,r);return t.parent&&y(t.parent,n,r),[...r.values()]}function b(e,t,n){if(!n.has(e.id)){n.set(e.id,e);for(let r of t.getObjects(null,d,e))r.termType===`NamedNode`&&b(r,t,n)}}function x(e,t,n,r){return r.flatMap(r=>e.getSubjects(t,n,r))}function S(e,t,n,r){return r.flatMap(r=>e.getObjects(t,n,r))}function C(e,t){if(t.in){let e=t.config.lists[t.in];return v(e?.length?e:[],t.config.store,t.config.languages)}else{let n=y(t,t.config.store),r=x(t.config.store,c,e,n),i=new Map,a=new Map;for(let e of r)i.set(e.id,{value:e,label:_(t.config.store.getQuads(e,null,null,null),t.config.languages),children:[]});for(let e of r){for(let r of S(t.config.store,e,f,n))i.has(r.id)&&a.set(e.id,r.id);for(let r of S(t.config.store,e,p,n))i.has(r.id)&&a.set(r.id,e.id);for(let r of S(t.config.store,e,u,n))i.has(r.id)&&a.set(e.id,r.id)}for(let[e,t]of a.entries())i.get(t)?.children?.push(i.get(e));let o=[];for(let[e,t]of i.entries())a.has(e)||o.push(t);for(let r of x(t.config.store,u,e,n))o.push(...C(r,t));return o}}`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${r}`,`${r}`,`${a}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,`${n}`,d.id,m.id,`${n}`,`${n}`;function w(e){return Math.max(e.minCount??0,e.qualifiedMinCount??0)}export{l as a,i,v as n,t as o,C as r,w as t};