@ulb-darmstadt/shacl-form 1.1.2 → 1.1.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/README.md CHANGED
@@ -38,22 +38,34 @@ This library provides an HTML5 web component that renders [SHACL shapes](https:/
38
38
  Attribute | Description
39
39
  ---|---
40
40
  data-shapes | SHACL shape definitions (e.g. a turtle string) to generate the form from
41
- data-shapes-url | When `data-shapes` is not set, load the shapes graph from this URL
41
+ data-shapes-url | When `data-shapes` is not set, the shapes graph is loaded from this URL
42
42
  data-shape-subject | Optional subject (id) of the shacl node shape to use as root for the form. If not set, the first found shacl node shape will be used
43
43
  data-values | RDF triples (e.g. a turtle string) to use as existing data values in the generated form
44
- data-values-url | When `data-values` is not set, load the data graph from this URL
44
+ data-values-url | When `data-values` is not set, the data graph is loaded from this URL
45
45
  data-value-subject | The subject (id) of the generated data. If this is not set, a blank node with a new UUID will be used. If `data-values` or `data-values-url` is set, this id is also used to find existing data in the data graph to fill the form
46
- data-language | Language to use if shapes contain langStrings
47
- data‑load‑owl‑imports | Whether to fetch RDF data from `owl:imports` statements. Default: `true`
48
- data-submit-button | Whether to append a submit button to the form. The string value of this attribute is used as the button label. Submit events will only fire after successful validation
46
+ data-language | Language to use if shapes contain langStrings, e.g. in `sh:name` or `rdfs:label`
47
+ data‑ignore‑owl‑imports | By default, `owl:imports` IRIs are fetched and the resulting triples added to the shapes graph. Set this attribute in order to disable this feature
48
+ data-submit-button | Whether to append a submit button to the form. The string value of this attribute is used as the button label. `submit` events will only fire after successful validation
49
49
 
50
50
  ### Element functions
51
- Function | Description
52
- ---|---
53
- `serialize(format?: string): string \| {}[]` | Serializes the form data as RDF triples. Supported formats: `text/turtle` (default), `application/ld+json`, `application/n-triples`, `application/n-quads`, `application/trig`
54
- `validate(ignoreEmptyValues: boolean): Promise\<boolean\>` | Validates the form data against the SHACL shapes graph and displays validation results as icons. If `ignoreEmptyValues` is true, empty form fields will not be marked as having validation errors
55
- `registerPlugin(plugin: Plugin)` | TBD
51
+ ```typescript
52
+ serialize(format?: string): string | []
53
+ ```
54
+
55
+ Serializes the form data as RDF triples. Supported formats: `text/turtle` (default), `application/ld+json`, `application/n-triples`, `application/n-quads`, `application/trig`. Format `application/ld+json` returns a JSON array, all other formats return a string.
56
+
57
+ ```typescript
58
+ validate(ignoreEmptyValues: boolean): Promise<boolean>
59
+ ```
60
+ Validates the form data against the SHACL shapes graph and displays validation results as icons next to the respective input fields. If `ignoreEmptyValues` is true, empty form fields will not be marked as invalid. This function is also internally called on `change` and `submit` events.
61
+
62
+ ```typescript
63
+ registerPlugin(plugin: Plugin)
64
+ ```
65
+ WIP / TBD
56
66
 
57
- ## Theming
58
- TBD
67
+ ```typescript
68
+ setClassInstanceProvider((className: string) => Promise<string>)
69
+ ```
70
+ Sets a callback function that is called when a SHACL property has a `sh:class` definition. The expected return value is a string (e.g. in format `text/turtle`) that contains RDF instance definitions of the given class name.
59
71
 
package/dist/config.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Prefixes, Store } from 'n3';
2
2
  import { Term } from '@rdfjs/types';
3
- import { Theme } from './theme';
4
- import { Plugins } from './plugin';
5
- export declare class Config {
3
+ import { ClassInstanceProvider, Plugins } from './plugin';
4
+ import { Loader } from './loader';
5
+ export declare class ElementAttributes {
6
6
  shapes: string | null;
7
7
  shapesUrl: string | null;
8
8
  shapeSubject: string | null;
@@ -10,27 +10,22 @@ export declare class Config {
10
10
  valuesUrl: string | null;
11
11
  valueSubject: string | null;
12
12
  language: string | null;
13
- loadOwlImports: string;
13
+ ignoreOwlImports: string | null;
14
14
  submitButton: string | null;
15
- private _theme;
16
- private _lists;
17
- private _groups;
15
+ }
16
+ export declare class Config {
17
+ attributes: ElementAttributes;
18
+ loader: Loader;
19
+ classInstanceProvider: ClassInstanceProvider | undefined;
20
+ prefixes: Prefixes;
21
+ plugins: Plugins;
22
+ dataGraph: Store<import("@rdfjs/types").Quad, import("n3").Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>;
23
+ lists: Record<string, Term[]>;
24
+ groups: Array<string>;
18
25
  private _shapesGraph;
19
- private _dataGraph;
20
- private _plugins;
21
- private _prefixes;
22
- equals(other: Config): boolean;
26
+ updateAttributes(elem: HTMLElement): void;
27
+ static dataAttributes(): Array<string>;
23
28
  get shapesGraph(): Store;
24
29
  set shapesGraph(graph: Store);
25
- get dataGraph(): Store;
26
- set dataGraph(graph: Store);
27
- get lists(): Record<string, Term[]>;
28
- get groups(): string[];
29
- set theme(theme: Theme);
30
- get prefixes(): Prefixes<import("@rdfjs/types").NamedNode<string>>;
31
30
  registerPrefixes(prefixes: Prefixes): void;
32
- get plugins(): Plugins;
33
- set plugins(plugins: Plugins);
34
- static from(elem: HTMLElement): Config;
35
- static get keysAsDataAttributes(): Array<string>;
36
31
  }
@@ -10,3 +10,4 @@ export declare const OWL_IMPORTS: import("n3").NamedNode<string>;
10
10
  export declare const RDF_PREDICATE_TYPE: import("n3").NamedNode<string>;
11
11
  export declare const RDFS_PREDICATE_SUBCLASS_OF: import("n3").NamedNode<string>;
12
12
  export declare const SHACL_OBJECT_NODE_SHAPE: import("n3").NamedNode<string>;
13
+ export declare const SHACL_PREDICATE_CLASS: import("n3").NamedNode<string>;
@@ -2,6 +2,4 @@ import { Term } from '@rdfjs/types';
2
2
  import { ShaclNode } from "./node";
3
3
  import { ShaclProperty } from "./property";
4
4
  import { Config } from './config';
5
- export declare class ShaclOrConstraint extends HTMLElement {
6
- constructor(options: Term[], context: ShaclNode | ShaclProperty, config: Config);
7
- }
5
+ export declare function createShaclOrConstraint(options: Term[], context: ShaclNode | ShaclProperty, config: Config): HTMLElement;
@@ -0,0 +1,19 @@
1
+ import { Literal, NamedNode } from 'n3';
2
+ import { Term } from '@rdfjs/types';
3
+ import { ShaclPropertyTemplate } from './property-template';
4
+ export type Editor = HTMLElement & {
5
+ value: string;
6
+ };
7
+ export declare function createDefaultTemplate(template: ShaclPropertyTemplate, editor: Editor, value?: Term): HTMLElement;
8
+ export declare function createDateEditor(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
9
+ export declare function createTextEditor(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
10
+ export declare function createLangStringEditor(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
11
+ export declare function createBooleanEditor(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
12
+ export declare function createNumberEditor(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
13
+ export type InputListEntry = {
14
+ value: Term;
15
+ label?: string;
16
+ };
17
+ export declare function createListEditor(template: ShaclPropertyTemplate, listEntries: InputListEntry[], value?: Term): HTMLElement;
18
+ export declare function toRDF(editor: Editor): Literal | NamedNode | undefined;
19
+ export declare function editorFactory(template: ShaclPropertyTemplate, value?: Term): HTMLElement;
package/dist/form.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import { ShaclNode } from './node';
2
2
  import { Config } from './config';
3
- import { Plugin } from './plugin';
3
+ import { ClassInstanceProvider, Plugin } from './plugin';
4
4
  import './styles.css';
5
- import { Loader } from './loader';
6
5
  export declare class ShaclForm extends HTMLElement {
7
6
  static get observedAttributes(): string[];
8
7
  config: Config;
9
- loader: Loader;
10
8
  shape: ShaclNode | null;
11
9
  form: HTMLFormElement;
12
10
  initDebounceTimeout: ReturnType<typeof setTimeout> | undefined;
@@ -16,6 +14,7 @@ export declare class ShaclForm extends HTMLElement {
16
14
  private initialize;
17
15
  serialize(format?: string): string | {}[];
18
16
  registerPlugin(plugin: Plugin): void;
17
+ setClassInstanceProvider(provider: ClassInstanceProvider): void;
19
18
  validate(ignoreEmptyValues?: boolean): Promise<boolean>;
20
19
  private createValidationErrorDisplay;
21
20
  private findRootShaclShapeSubject;
package/dist/group.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  import { Config } from './config';
2
- export declare class ShaclGroup extends HTMLElement {
3
- constructor(groupSubject: string, config: Config);
4
- }
2
+ export declare function createShaclGroup(groupSubject: string, config: Config): HTMLElement;