@ulb-darmstadt/shacl-form 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -16
- package/dist/config.d.ts +1 -1
- package/dist/exports.d.ts +2 -0
- package/dist/form-bootstrap.d.ts +3 -2
- package/dist/form-bootstrap.js +2 -0
- package/dist/form-default.d.ts +5 -0
- package/dist/form-default.js +2 -0
- package/dist/form-material.d.ts +3 -2
- package/dist/form-material.js +335 -0
- package/dist/plugins/mapbox.d.ts +11 -6
- package/dist/plugins/mapbox.js +1 -1
- package/dist/property-template.d.ts +2 -0
- package/dist/theme.d.ts +3 -0
- package/dist/themes/bootstrap.d.ts +2 -2
- package/dist/themes/{native.d.ts → default.d.ts} +1 -1
- package/package.json +13 -9
- package/dist/bootstrap.js +0 -2
- package/dist/form-native.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/material.js +0 -335
- package/dist/themes/material.js +0 -335
- package/dist/themes/material.js.LICENSE.txt +0 -65
- /package/dist/{bootstrap.js.LICENSE.txt → form-bootstrap.js.LICENSE.txt} +0 -0
- /package/dist/{index.js.LICENSE.txt → form-default.js.LICENSE.txt} +0 -0
- /package/dist/{material.js.LICENSE.txt → form-material.js.LICENSE.txt} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SHACL Form Generator
|
|
2
2
|
|
|
3
|
-
```
|
|
3
|
+
```console
|
|
4
4
|
npm i @ulb-darmstadt/shacl-form
|
|
5
5
|
```
|
|
6
6
|
|
|
@@ -9,11 +9,12 @@ An HTML5 web component for editing/viewing [RDF](https://www.w3.org/RDF/) data t
|
|
|
9
9
|
## [See demo here](https://ulb-darmstadt.github.io/shacl-form/)
|
|
10
10
|
|
|
11
11
|
### Basic usage
|
|
12
|
+
|
|
12
13
|
```html
|
|
13
14
|
<html>
|
|
14
15
|
<head>
|
|
15
16
|
<!-- load web component -->
|
|
16
|
-
<script src="https://cdn.jsdelivr.net/npm/@ulb-darmstadt/shacl-form/dist/
|
|
17
|
+
<script src="https://cdn.jsdelivr.net/npm/@ulb-darmstadt/shacl-form/dist/form-default.js" type="module"></script>
|
|
17
18
|
</head>
|
|
18
19
|
<body>
|
|
19
20
|
<!--
|
|
@@ -38,8 +39,8 @@ An HTML5 web component for editing/viewing [RDF](https://www.w3.org/RDF/) data t
|
|
|
38
39
|
form.addEventListener('change', event => {
|
|
39
40
|
// check if form data validates according to the SHACL shapes
|
|
40
41
|
if (event.detail?.valid) {
|
|
41
|
-
// get data graph as RDF triples
|
|
42
|
-
//
|
|
42
|
+
// get data graph as RDF triples and
|
|
43
|
+
// log them to the browser console
|
|
43
44
|
const triples = form.serialize()
|
|
44
45
|
console.log('entered form data', triples)
|
|
45
46
|
// store the data somewhere, e.g. in a triple store
|
|
@@ -51,6 +52,7 @@ An HTML5 web component for editing/viewing [RDF](https://www.w3.org/RDF/) data t
|
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
### Element attributes
|
|
55
|
+
|
|
54
56
|
Attribute | Description
|
|
55
57
|
---|---
|
|
56
58
|
data-shapes | SHACL shape definitions (e.g. a turtle string) to generate the form from
|
|
@@ -58,20 +60,21 @@ data-shapes-url | When `data-shapes` is not set, the SHACL shapes are loaded fro
|
|
|
58
60
|
data-shape-subject | Optional subject (id) of the SHACL node shape to use as root for the form. If not set, the first found node shape will be used
|
|
59
61
|
data-values | RDF triples (e.g. a turtle string) to use as existing data graph to fill the form
|
|
60
62
|
data-values-url | When `data-values` is not set, the data graph triples are loaded from this URL
|
|
61
|
-
data-value-subject | The subject (id) of the generated data. If this is not set, a blank node with a new UUID
|
|
63
|
+
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
|
|
62
64
|
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)
|
|
63
65
|
data-loading | Text to display while the web component is initializing. Default: `"Loading..."`
|
|
64
66
|
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
|
|
65
|
-
data-
|
|
66
|
-
data-collapse | When
|
|
67
|
-
data-submit-button | [
|
|
67
|
+
data-view | When set, turns the web component into a viewer that displays the given data graph without editing functionality
|
|
68
|
+
data-collapse | When set, `sh:group`s and properties with `sh:node` and `sh:maxCount` != 1 are displayed in a collapsible accordion-like widget to reduce visual complexity of the form. The collapsible element is initially shown closed, except when this attribute's value is `"open"`
|
|
69
|
+
data-submit-button | [Ignored when `data-view` attribute is set] Whether to add a submit button to the form. The value of this attribute is used as the button label. `submit` events get emitted only when the form data validates
|
|
68
70
|
|
|
69
71
|
### Element functions
|
|
72
|
+
|
|
70
73
|
```typescript
|
|
71
74
|
serialize(format?: string): string
|
|
72
75
|
```
|
|
73
76
|
|
|
74
|
-
Serializes the form data to RDF triples. Supported formats: `text/turtle` (default), `application/ld+json`, `application/n-triples`, `application/n-quads`, `application/trig`.
|
|
77
|
+
Serializes the form data to RDF triples. <a name="formats"></a>Supported formats: `text/turtle` (default), `application/ld+json`, `application/n-triples`, `application/n-quads`, `application/trig`.
|
|
75
78
|
|
|
76
79
|
```typescript
|
|
77
80
|
validate(ignoreEmptyValues: boolean): Promise<boolean>
|
|
@@ -86,7 +89,7 @@ Register a [plugin](./src/plugin.ts) to customize editing/viewing certain proper
|
|
|
86
89
|
```typescript
|
|
87
90
|
setTheme(theme: Theme)
|
|
88
91
|
```
|
|
89
|
-
Set a design theme to use for rendering. See section
|
|
92
|
+
Set a design theme to use for rendering. See section [Theming](#Theming).
|
|
90
93
|
```typescript
|
|
91
94
|
setClassInstanceProvider((className: string) => Promise<string>)
|
|
92
95
|
```
|
|
@@ -96,13 +99,121 @@ Sets a callback function that is called when a SHACL property has an `sh:class`
|
|
|
96
99
|
|
|
97
100
|
Class hierarchies can be built using `rdfs:subClassOf` or `skos:broader`.
|
|
98
101
|
|
|
99
|
-
##
|
|
100
|
-
|
|
102
|
+
## Features
|
|
103
|
+
|
|
104
|
+
### Validation
|
|
105
|
+
|
|
106
|
+
In edit mode, `<shacl-form>` validates the constructed data graph using the library [rdf-validate-shacl](https://github.com/zazuko/rdf-validate-shacl) and displays validation results as icons next to the respective form fields.
|
|
107
|
+
|
|
108
|
+
### Data graph binding
|
|
109
|
+
|
|
110
|
+
`<shacl-form>` requires only a shapes graph as input via the attribute `data-shapes` (or `data-shapes-url`) to generate an empty form and create new RDF data from the form input fields. Using the attributes `data-values` (or `data-values-url`) and `data-value-subject`, you can also bind an existing data graph to the form. The given data graph is then used to fill the form input fields.
|
|
111
|
+
|
|
112
|
+
### Viewer mode
|
|
113
|
+
|
|
114
|
+
`<shacl-form>` not only is an RDF data editor, but can also be used as a viewer by setting attribute `data-view` and binding both, a shapes and a data graph. See the [demo](https://ulb-darmstadt.github.io/shacl-form/#viewer-mode) for an example.
|
|
115
|
+
|
|
116
|
+
### Providing additional data to the shapes graph
|
|
117
|
+
|
|
118
|
+
Apart from setting the element attributes `data-shapes` or `data-shapes-url`, there are two ways of adding RDF data to the shapes graph:
|
|
119
|
+
1. While parsing the triples of the shapes graph, any encountered `owl:imports` predicate that has a valid HTTP URL value will tried to be fetched with the HTTP Accept header set to all of the [supported](#formats) MIME types. A successful response will be parsed and added to the shapes graph. The [example shapes graph](https://ulb-darmstadt.github.io/shacl-form/#example) contains the following triples:
|
|
120
|
+
```
|
|
121
|
+
example:Attribution
|
|
122
|
+
owl:imports <https://w3id.org/nfdi4ing/metadata4ing/> ;
|
|
123
|
+
sh:property [
|
|
124
|
+
sh:name "Role" ;
|
|
125
|
+
sh:path dcat:hadRole ;
|
|
126
|
+
sh:class prov:Role ;
|
|
127
|
+
] .
|
|
128
|
+
```
|
|
129
|
+
In this case, the URL references an ontology which among other things defines instances of class `prov:Role` that are then used to populate the "Role" dropdown in the form.
|
|
130
|
+
|
|
131
|
+
2. The `<shacl-form>` element has a function `setClassInstanceProvider((className: string) => Promise<string>)` that registers a callback function which is called when a SHACL property has
|
|
132
|
+
an `sh:class` predicate. The expected return value of this callback function is a (promise of a) string (e.g. in format `text/turtle`) that contains RDF class instance definitions of the given class. Instances can be defined e.g. like:
|
|
133
|
+
- `example:Instance a example:Class`
|
|
134
|
+
- `example:Instance a owl:NamedIndividual; skos:broader example:Class`
|
|
135
|
+
|
|
136
|
+
Class hierarchies can be built using `rdfs:subClassOf` or `skos:broader`.
|
|
137
|
+
|
|
138
|
+
In [this example](https://ulb-darmstadt.github.io/shacl-form/#example), the code:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
form.setClassInstanceProvider((clazz) => {
|
|
142
|
+
if (clazz === 'http://example.org/Material') {
|
|
143
|
+
return `
|
|
144
|
+
<http://example.org/steel> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Steel".
|
|
145
|
+
<http://example.org/wood> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Wood".
|
|
146
|
+
<http://example.org/alloy> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Alloy".
|
|
147
|
+
<http://example.org/plaster> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Plaster".
|
|
148
|
+
`
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
returns instances of the class `http://example.org/Material` that are then used to populate the "Artwork material" dropdown in the form.
|
|
153
|
+
|
|
154
|
+
A more realistic use case of this feature is calling some API endpoint to fetch class instance definitions from existing ontologies.
|
|
155
|
+
|
|
156
|
+
### SHACL "or" constraint
|
|
157
|
+
|
|
158
|
+
`<shacl-form>` supports using [sh:or](https://www.w3.org/TR/shacl/#OrConstraintComponent) to let users select between different options on nodes or properties.
|
|
159
|
+
The [example shapes graph](https://ulb-darmstadt.github.io/shacl-form/#example) has the following triples:
|
|
160
|
+
```
|
|
161
|
+
example:Attribution
|
|
162
|
+
a sh:NodeShape ;
|
|
163
|
+
sh:property [
|
|
164
|
+
sh:maxCount 1 ;
|
|
165
|
+
sh:minCount 1 ;
|
|
166
|
+
sh:path prov:agent ;
|
|
167
|
+
sh:or (
|
|
168
|
+
[ sh:node example:Person ; rdfs:label "Person" ]
|
|
169
|
+
[ sh:node example:Organisation ; rdfs:label "Organisation" ]
|
|
170
|
+
)
|
|
171
|
+
] .
|
|
172
|
+
```
|
|
173
|
+
When adding a new attribution, `<shacl-form>` renders a dropdown to let the user select between the two options Person/Organisation. After selecting one of the options, the dropdown is replaced by the input fields of the selected node shape.
|
|
174
|
+
|
|
175
|
+
When binding an existing data graph to the form, the `sh:or` constraint is tried to be resolved depending on the respective data value:
|
|
176
|
+
- For RDF literals, an `sh:or` option with a matching `sh:datatype` is chosen
|
|
177
|
+
- For blank nodes or named nodes, the `rdf:type` of the value is tried to be matched with a node shape having a corresponding `sh:targetClass` or with a property shape having a corresponding `sh:class`
|
|
178
|
+
|
|
179
|
+
### SHACL shape inheritance
|
|
180
|
+
|
|
181
|
+
SHACL defines two ways of inheriting shapes: [sh:and](https://www.w3.org/TR/shacl/#AndConstraintComponent)
|
|
182
|
+
and [sh:node](https://www.w3.org/TR/shacl/#NodeConstraintComponent). `<shacl-form>` supports both. In [this example](https://ulb-darmstadt.github.io/shacl-form/#example), node shape `example:ArchitectureModelDataset` extends `example:Dataset` by defining the following RDF triple:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
example:ArchitectureModelDataset sh:node example:Dataset .
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Properties of inherited shapes are displayed first.
|
|
189
|
+
|
|
190
|
+
### Plugins
|
|
191
|
+
|
|
192
|
+
Plugins can modify rendering of the form and add functionality to edit and view certain RDF datatypes or predicates (or a combination of both). As an example, the JavaScript of [this page](https://ulb-darmstadt.github.io/shacl-form/#example) contains the following code:
|
|
193
|
+
```typescript
|
|
194
|
+
import { MapboxPlugin } from '@ulb-darmstadt/shacl-form/plugins/mapbox.js'
|
|
195
|
+
const form = document.getElementById("shacl-form")
|
|
196
|
+
form.registerPlugin(new MapboxPlugin({ datatype: 'http://www.opengis.net/ont/geosparql#wktLiteral' }, API_KEY))
|
|
197
|
+
```
|
|
198
|
+
In effect, whenever a SHACL property has an `sh:datatype` of `http://www.opengis.net/ont/geosparql#wktLiteral`, the plugin is called to create the editor and/or viewer HTML elements. This specific plugin uses [Mapbox GL](https://docs.mapbox.com/mapbox-gl-js/guides/) to edit or view geometry in format [well known text](http://giswiki.org/wiki/Well_Known_Text) on a map.
|
|
199
|
+
Custom plugins can be built by extending class [Plugin](https://github.com/ULB-Darmstadt/shacl-form/blob/main/src/plugin.ts#L40).
|
|
200
|
+
|
|
201
|
+
### Property grouping and collapsing
|
|
202
|
+
|
|
203
|
+
Properties can be grouped using [sh:group](https://www.w3.org/TR/shacl/#group) in the shapes graph. [This example](https://ulb-darmstadt.github.io/shacl-form/#example) defines a group "Physical properties" and assigns certain properties to it.
|
|
204
|
+
|
|
205
|
+
When the element attribute `data-collapse` is set, `<shacl-form>` creates an accordion-like widget that toggles the visibility of grouped properties in order to reduce the visual complexity of the form. If the grouped properties should initially be shown, set `data-collapse="open"`.
|
|
206
|
+
|
|
207
|
+
Apart from grouped properties, all properties having an `sh:node` predicate and `sh:maxCount` != 1 are collapsed.
|
|
208
|
+
|
|
209
|
+
### Theming
|
|
210
|
+
|
|
211
|
+
`<shacl-form>` comes in 3 different bundles, each providing a specific theme. See the [demo page](https://ulb-darmstadt.github.io/shacl-form/#theming) for an example.
|
|
101
212
|
|
|
102
213
|
Theme | Import statement
|
|
103
214
|
--- | ---
|
|
104
|
-
Default (
|
|
105
|
-
[Bootstrap](./src/themes/bootstrap.ts) [alpha status] | `import '@ulb-darmstadt/shacl-form/bootstrap.js'`
|
|
106
|
-
[Material Design](./src/themes/material.ts) [alpha status] | `import '@ulb-darmstadt/shacl-form/material.js'`
|
|
215
|
+
[Default]((./src/themes/default.ts)) (slightly customized default browser styles) | `import '@ulb-darmstadt/shacl-form/form-default.js'`
|
|
216
|
+
[Bootstrap](./src/themes/bootstrap.ts) [alpha status] | `import '@ulb-darmstadt/shacl-form/form-bootstrap.js'`
|
|
217
|
+
[Material Design](./src/themes/material.ts) [alpha status] | `import '@ulb-darmstadt/shacl-form/form-material.js'`
|
|
107
218
|
|
|
108
|
-
Custom themes can be employed by
|
|
219
|
+
Custom themes can be employed by extending class [Theme](./src/theme.ts), then calling function `setTheme()` on the `<shacl-form>` element.
|
package/dist/config.d.ts
CHANGED
package/dist/form-bootstrap.d.ts
CHANGED