@ulb-darmstadt/shacl-form 1.5.3 → 1.6.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 CHANGED
@@ -22,9 +22,9 @@ HTML5 web component for editing/viewing [RDF](https://www.w3.org/RDF/) data that
22
22
  or can be loaded by setting attribute 'data-shapes-url'
23
23
  -->
24
24
  <shacl-form data-shapes="
25
- @prefix sh: <http://www.w3.org/ns/shacl#> .
26
- @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
27
- @prefix ex: <http://example.org#> .
25
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
26
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
27
+ @prefix ex: <http://example.org#> .
28
28
 
29
29
  ex:ExampleShape
30
30
  a sh:NodeShape, rdfs:Class ;
@@ -70,10 +70,11 @@ data-view | When set, turns the web component into a viewer that displays the gi
70
70
  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"`
71
71
  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
72
72
  data-generate-node-shape-reference | When generating the RDF data graph, &lt;shacl-form&gt; can create a triple that references the root `sh:NodeShape` of the data. Suggested values for this attribute are `http://www.w3.org/1999/02/22-rdf-syntax-ns#type` or `http://purl.org/dc/terms/conformsTo`. Default is empty, so that no such triple is created
73
- show-node-ids | When this attribute is set, shacl node shapes will have their subject id shown in the form
73
+ data-show-node-ids | When this attribute is set, shacl node shapes will have their subject id shown in the form
74
74
 
75
75
  ### Element functions
76
76
 
77
+ <a id="toRDF"></a>
77
78
  ```typescript
78
79
  toRDF(graph?: Store): Store
79
80
  ```
@@ -103,17 +104,13 @@ Set a design theme to use for rendering. See section [Theming](#Theming).
103
104
  ```typescript
104
105
  setClassInstanceProvider((className: string) => Promise<string>)
105
106
  ```
106
- Sets a callback function that is called when a SHACL property has an `sh:class` definition. The expected return value is 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:
107
- - `example:Instance a example:Class`
108
- - `example:Instance a owl:NamedIndividual; skos:broader example:Class`
109
-
110
- Class hierarchies can be built using `rdfs:subClassOf` or `skos:broader`.
107
+ Sets a callback function that is invoked when a SHACL property has an `sh:class` definition to retrieve class instances. See [below](#classInstanceProvider) for more information.
111
108
 
112
109
  ## Features
113
110
 
114
111
  ### Validation
115
112
 
116
- 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.
113
+ In edit mode, `<shacl-form>` validates the constructed data graph using the library [shacl-engine](https://github.com/rdf-ext/shacl-engine) and displays validation results as icons next to the respective form fields.
117
114
 
118
115
  ### Data graph binding
119
116
 
@@ -138,7 +135,7 @@ Apart from setting the element attributes `data-shapes` or `data-shapes-url`, th
138
135
  ```
139
136
  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.
140
137
 
141
- 2. The `<shacl-form>` element has a function `setClassInstanceProvider((className: string) => Promise<string>)` that registers a callback function which is invoked when a SHACL property has
138
+ 2. <a id="classInstanceProvider"></a>The `<shacl-form>` element has a function `setClassInstanceProvider((className: string) => Promise<string>)` that registers a callback function which is invoked when a SHACL property has
142
139
  an `sh:class` predicate. The expected return value 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:
143
140
  - `example:Instance a example:Class`
144
141
  - `example:Instance a owl:NamedIndividual; skos:broader example:Class`
@@ -216,6 +213,43 @@ When the element attribute `data-collapse` is set, `<shacl-form>` creates an acc
216
213
 
217
214
  Apart from grouped properties, all properties having an `sh:node` predicate and `sh:maxCount` != 1 are collapsed.
218
215
 
216
+ ### Use with Solid Pods
217
+
218
+ `<shacl-form>` can easily be integrated with [Solid Pods](https://solidproject.org/about). The output of `toRDF()` being a RDF/JS N3 Store, as explained [above](#toRDF), it can be presented to `solid-client`s `fromRdfJsDataset()` function, which converts the RDF graph into a Solid Dataset. The following example, based on Inrupt's basic [Solid Pod example](https://docs.inrupt.com/developer-tools/javascript/client-libraries/tutorial/getting-started/) shows how to merge data from a `<shacl-form>` with a Solid data resource at `readingListDataResourceURI`:
219
+
220
+ ```js
221
+ // Authentication is assumed, resulting in a fetch able to read and write into the Pod
222
+ try {
223
+ // Get data out of the shacl-form
224
+ const form = document.querySelector('shacl-form')
225
+
226
+ // Extract the RDF graph from the form
227
+ const shaclFormGraphStore = await form.toRDF()
228
+
229
+ // Convert RDF store into a Solid dataset
230
+ const shaclFormDataset = await fromRdfJsDataset(shaclFormGraphStore)
231
+
232
+ // First get the current dataset
233
+ myReadingList = await getSolidDataset(readingListDataResourceURI, { fetch: fetch })
234
+
235
+ // get all things from the shaclFormDataset
236
+ const shaclFormThings = getThingAll(shaclFormDataset)
237
+
238
+ // add the things from ShaclForm to the existing set
239
+ shaclFormThings.forEach((thing) => (myReadingList = setThing(myReadingList, thing)))
240
+
241
+ // save the new dataset
242
+ let savedReadingList = await saveSolidDatasetAt(readingListDataResourceURI, myReadingList, {
243
+ fetch: fetch
244
+ })
245
+
246
+ // Other handling here
247
+
248
+ } catch (err) {
249
+ console.error(`Storing SHACL data from Form failed with error ${err}!`)
250
+ }
251
+ ```
252
+
219
253
  ### Theming
220
254
 
221
255
  `<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.
@@ -8,11 +8,11 @@ export declare const PREFIX_OWL = "http://www.w3.org/2002/07/owl#";
8
8
  export declare const PREFIX_OA = "http://www.w3.org/ns/oa#";
9
9
  export declare const PREFIX_DCTERMS = "http://purl.org/dc/terms/";
10
10
  export declare const SHAPES_GRAPH: import("n3").NamedNode<"shapes">;
11
- export declare const OWL_IMPORTS: import("n3").NamedNode<string>;
12
11
  export declare const RDF_PREDICATE_TYPE: import("n3").NamedNode<string>;
13
12
  export declare const DCTERMS_PREDICATE_CONFORMS_TO: import("n3").NamedNode<string>;
14
13
  export declare const RDFS_PREDICATE_SUBCLASS_OF: import("n3").NamedNode<string>;
15
14
  export declare const SKOS_PREDICATE_BROADER: import("n3").NamedNode<string>;
15
+ export declare const OWL_PREDICATE_IMPORTS: import("n3").NamedNode<string>;
16
16
  export declare const OWL_OBJECT_NAMED_INDIVIDUAL: import("n3").NamedNode<string>;
17
17
  export declare const SHACL_OBJECT_NODE_SHAPE: import("n3").NamedNode<string>;
18
18
  export declare const SHACL_OBJECT_IRI: import("n3").NamedNode<string>;