Skip to content

Commit

Permalink
fix issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tittel committed Mar 31, 2024
1 parent 257a0ed commit e8501e8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data-shape-subject | Optional subject (id) of the SHACL node shape to use as roo
data-values | RDF triples (e.g. a turtle string) to use as existing data graph to fill the form
data-values-url | When `data-values` is not set, the data graph triples are loaded from this URL
data-value-subject | The subject (id) of the generated data. If this is not set, a blank node with a new UUID is created. If `data-values` or `data-values-url` is set, this id is also used to find the root node in the data graph to fill the form
data-values-namespace | RDF namespace to use when generating new RDF subjects. Default is empty, so that subjects will be blank nodes.
data-language | Language to use if shapes contain langStrings, e.g. in `sh:name` or `rdfs:label`. Default is [`navigator.language`](https://www.w3schools.com/jsref/prop_nav_language.asp)
data-loading | Text to display while the web component is initializing. Default: `"Loading..."`
data‑ignore‑owl‑imports | By default, `owl:imports` URLs are fetched and the resulting RDF triples are added to the shapes graph. Setting this attribute to any value disables this feature
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulb-darmstadt/shacl-form",
"version": "1.4.1",
"version": "1.4.2",
"description": "SHACL form generator",
"main": "dist/form-default.js",
"module": "dist/form-default.js",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ElementAttributes {
values: string | null = null
valuesUrl: string | null = null
valueSubject: string | null = null
valuesNamespace = ''
view: string | null = null
language: string = navigator.language
loading: string = 'Loading\u2026'
Expand Down
29 changes: 26 additions & 3 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,38 @@ export class ShaclNode extends HTMLElement {
targetClass: NamedNode | undefined
config: Config

constructor(shaclSubject: NamedNode, config: Config, valueSubject: NamedNode | BlankNode | undefined, label?: string) {
constructor(shaclSubject: NamedNode, config: Config, valueSubject: NamedNode | BlankNode | undefined, nodeKind?: NamedNode, label?: string) {
super()

this.config = config
this.shaclSubject = shaclSubject
this.nodeId = valueSubject || DataFactory.blankNode(uuidv4())
let nodeId: NamedNode | BlankNode | undefined = valueSubject
if (!nodeId) {
// if no value subject given, create new node id with a type depending on own nodeKind or given parent property nodeKind
if (!nodeKind) {
const spec = config.shapesGraph.getObjects(shaclSubject, `${PREFIX_SHACL}nodeKind`, SHAPES_GRAPH)
if (spec.length) {
nodeKind = spec[0] as NamedNode
}
}
if (nodeKind === undefined && config.attributes.valuesNamespace) {
// no requirements on node type, so create a NamedNode and use configured value namespace
nodeId = DataFactory.namedNode(config.attributes.valuesNamespace + uuidv4())
}
else if (nodeKind?.id === `${PREFIX_SHACL}IRI`) {
nodeId = DataFactory.namedNode(config.attributes.valuesNamespace + uuidv4())
}
else {
// default to BlankNode
nodeId = DataFactory.blankNode(uuidv4())
}
}
this.nodeId = nodeId
this.dataset.nodeId = this.nodeId.id


const quads = config.shapesGraph.getQuads(shaclSubject, null, null, SHAPES_GRAPH)
let list: Term[] | undefined
this.dataset.nodeId = this.nodeId.id

for (const quad of quads) {
switch (quad.predicate.id) {
Expand Down
4 changes: 2 additions & 2 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ShaclProperty extends HTMLElement {

constructor(shaclSubject: BlankNode | NamedNode, config: Config, nodeId: NamedNode | BlankNode, valueSubject?: NamedNode | BlankNode) {
super()

console.log('--- new shacl property', nodeId)
this.template = new ShaclPropertyTemplate(config.shapesGraph.getQuads(shaclSubject, null, null, SHAPES_GRAPH), nodeId, config)
this.dataset.nodeId = this.template.nodeId.id

Expand Down Expand Up @@ -142,7 +142,7 @@ export function createPropertyInstance(template: ShaclPropertyTemplate, value?:
instance = document.createElement('div')
instance.classList.add('property-instance')
for (const node of template.extendedShapes) {
instance.appendChild(new ShaclNode(node, template.config, value as NamedNode | BlankNode | undefined, template.label))
instance.appendChild(new ShaclNode(node, template.config, value as NamedNode | BlankNode | undefined, template.nodeKind, template.label))
}
} else {
const plugin = template.config.plugins.find(template.path, template.datatype?.value)
Expand Down

0 comments on commit e8501e8

Please sign in to comment.