@ulb-darmstadt/shacl-form 1.8.3 → 1.8.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulb-darmstadt/shacl-form",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "description": "SHACL form generator",
5
5
  "main": "dist/form-default.js",
6
6
  "module": "dist/form-default.js",
@@ -55,7 +55,7 @@
55
55
  "@types/uuid": "^10.0.0",
56
56
  "rollup-plugin-peer-deps-external": "^2.2.4",
57
57
  "typescript": "^5.8.3",
58
- "vite": "^7.0.4",
58
+ "vite": "^7.0.5",
59
59
  "vite-plugin-dts": "^4.5.4"
60
60
  },
61
61
  "dependencies": {
@@ -71,7 +71,7 @@
71
71
  "uuid": "^11.1.0"
72
72
  },
73
73
  "peerDependencies": {
74
- "@ro-kit/ui-widgets": "^0.0.31",
74
+ "@ro-kit/ui-widgets": "^0.0.32",
75
75
  "mdui": "^2.1.4"
76
76
  }
77
77
  }
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Literal, NamedNode, Prefixes, Quad, Term as N3Term, Store } from 'n3'
1
+ import { Literal, NamedNode, Prefixes, Quad, Store } from 'n3'
2
2
  import { DATA_GRAPH, PREFIX_FOAF, PREFIX_RDFS, PREFIX_SHACL, PREFIX_SKOS, RDFS_PREDICATE_SUBCLASS_OF, RDF_PREDICATE_TYPE, SHAPES_GRAPH, SKOS_PREDICATE_BROADER, SKOS_PREDICATE_NARROWER } from './constants'
3
3
  import { Term } from '@rdfjs/types'
4
4
  import { InputListEntry } from './theme'
@@ -88,32 +88,44 @@ export function findInstancesOf(clazz: NamedNode, template: ShaclPropertyTemplat
88
88
  const list = template.config.lists[template.shaclIn]
89
89
  return createInputListEntries(list?.length ? list : [], template.config.store, template.config.languages)
90
90
  } else {
91
+ // find instances in the shapes graph
91
92
  const instances = template.config.store.getSubjects(RDF_PREDICATE_TYPE, clazz, SHAPES_GRAPH)
92
93
  // find instances in the data graph
93
94
  instances.push(...template.config.store.getSubjects(RDF_PREDICATE_TYPE, clazz, DATA_GRAPH))
94
95
  // find instances in imported taxonomies
95
96
  findClassInstancesFromOwlImports(clazz, template, template.config.store, instances)
96
97
 
97
- // structures needed for build a class instance hierarchy
98
+ // initialize structures needed for building a class instance hierarchy
98
99
  const nodes = new Map<string, InputListEntry>() // URI -> InputListEntry
99
100
  const childToParent = new Map<string, string>() // URI -> parentURI
100
101
 
101
- // Step 1: Initialize all instances as InputListEntry's with no children
102
+ // initialize all instances as InputListEntry's with no children
102
103
  for (const instance of instances) {
103
104
  nodes.set(instance.id, { value: instance, label: findLabel(template.config.store.getQuads(instance, null, null, null), template.config.languages), children: [] })
104
105
  }
105
106
 
106
- // Step 2: Record broader/narrower relationships (child -> parent)
107
+ // record broader/narrower relationships (child -> parent)
107
108
  for (const instance of instances) {
108
- appendSkosBroaderNarrower(instance, nodes, childToParent, template)
109
+ for (const parent of template.config.store.getObjects(instance, SKOS_PREDICATE_BROADER, null)) {
110
+ childToParent.set(instance.id, parent.id)
111
+ if (!nodes.has(parent.id)) {
112
+ nodes.set(parent.id, { value: parent, label: findLabel(template.config.store.getQuads(parent, null, null, null), template.config.languages), children: [] })
113
+ }
114
+ }
115
+ for (const child of template.config.store.getObjects(instance, SKOS_PREDICATE_NARROWER, null)) {
116
+ childToParent.set(child.id, instance.id)
117
+ if (!nodes.has(child.id)) {
118
+ nodes.set(child.id, { value: child, label: findLabel(template.config.store.getQuads(child, null, null, null), template.config.languages), children: [] })
119
+ }
120
+ }
109
121
  }
110
122
 
111
- // Step 3: Build hierarchy by nesting children under parents
123
+ // build hierarchy by nesting children under parents
112
124
  for (const [child, parent] of childToParent.entries()) {
113
- nodes.get(parent)!.children!.push(nodes.get(child)!)
125
+ nodes.get(parent)?.children?.push(nodes.get(child)!)
114
126
  }
115
127
 
116
- // Step 4: Find root nodes (no broader relationship)
128
+ // find root nodes (no parent relationship)
117
129
  const roots: InputListEntry[] = []
118
130
  for (const [uri, node] of nodes.entries()) {
119
131
  if (!childToParent.has(uri)) {
@@ -121,7 +133,7 @@ export function findInstancesOf(clazz: NamedNode, template: ShaclPropertyTemplat
121
133
  }
122
134
  }
123
135
 
124
- // Step 5: Add sub class instances
136
+ // add sub class instances
125
137
  for (const subClass of template.config.store.getSubjects(RDFS_PREDICATE_SUBCLASS_OF, clazz, null)) {
126
138
  roots.push(...findInstancesOf(subClass as NamedNode, template))
127
139
  }
@@ -129,23 +141,6 @@ export function findInstancesOf(clazz: NamedNode, template: ShaclPropertyTemplat
129
141
  }
130
142
  }
131
143
 
132
- function appendSkosBroaderNarrower(subject: N3Term, nodes: Map<string, InputListEntry>, childToParent: Map<string, string>, template: ShaclPropertyTemplate) {
133
- for (const parent of template.config.store.getObjects(subject, SKOS_PREDICATE_BROADER, null)) {
134
- childToParent.set(subject.id, parent.id)
135
- if (!nodes.has(parent.id)) {
136
- nodes.set(parent.id, { value: parent, label: findLabel(template.config.store.getQuads(parent, null, null, null), template.config.languages), children: [] })
137
- }
138
- appendSkosBroaderNarrower(parent, nodes, childToParent, template)
139
- }
140
- for (const child of template.config.store.getObjects(subject, SKOS_PREDICATE_NARROWER, null)) {
141
- childToParent.set(child.id, subject.id)
142
- if (!nodes.has(child.id)) {
143
- nodes.set(child.id, { value: child, label: findLabel(template.config.store.getQuads(child, null, null, null), template.config.languages), children: [] })
144
- }
145
- appendSkosBroaderNarrower(child, nodes, childToParent, template)
146
- }
147
- }
148
-
149
144
  export function isURL(input: string): boolean {
150
145
  let url: URL
151
146
  try {