@ulb-darmstadt/shacl-form 1.10.3 → 2.0.0-rc1

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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/dist/bundle.js +412 -0
  3. package/dist/constants.d.ts +16 -16
  4. package/dist/constraints.d.ts +2 -2
  5. package/dist/form.d.ts +4 -3
  6. package/dist/index.js +62 -0
  7. package/dist/plugins/assets/plugin-VN3CfgGe.js +1 -0
  8. package/dist/plugins/file-upload.js +1 -0
  9. package/dist/plugins/leaflet.d.ts +3 -1
  10. package/dist/plugins/leaflet.js +5 -708
  11. package/dist/plugins/map-util.js +1 -0
  12. package/dist/{themes/default.d.ts → theme.default.d.ts} +2 -2
  13. package/package.json +28 -33
  14. package/dist/form-bootstrap.d.ts +0 -5
  15. package/dist/form-bootstrap.js +0 -413
  16. package/dist/form-default.d.ts +0 -5
  17. package/dist/form-default.js +0 -402
  18. package/dist/form-material.d.ts +0 -5
  19. package/dist/form-material.js +0 -722
  20. package/dist/plugins/fixed-list.d.ts +0 -9
  21. package/dist/plugins/mapbox.d.ts +0 -19
  22. package/dist/plugins/mapbox.js +0 -2870
  23. package/dist/themes/bootstrap.d.ts +0 -10
  24. package/dist/themes/material.d.ts +0 -15
  25. package/src/config.ts +0 -110
  26. package/src/constants.ts +0 -30
  27. package/src/constraints.ts +0 -149
  28. package/src/exports.ts +0 -7
  29. package/src/form-bootstrap.ts +0 -12
  30. package/src/form-default.ts +0 -12
  31. package/src/form-material.ts +0 -12
  32. package/src/form.ts +0 -319
  33. package/src/globals.d.ts +0 -2
  34. package/src/group.ts +0 -34
  35. package/src/loader.ts +0 -187
  36. package/src/node.ts +0 -192
  37. package/src/plugin.ts +0 -60
  38. package/src/plugins/file-upload.ts +0 -26
  39. package/src/plugins/fixed-list.ts +0 -19
  40. package/src/plugins/leaflet.ts +0 -196
  41. package/src/plugins/map-util.ts +0 -41
  42. package/src/plugins/mapbox.ts +0 -157
  43. package/src/property-template.ts +0 -151
  44. package/src/property.ts +0 -309
  45. package/src/serialize.ts +0 -96
  46. package/src/shacl-engine.d.ts +0 -2
  47. package/src/styles.css +0 -49
  48. package/src/theme.ts +0 -132
  49. package/src/themes/bootstrap.css +0 -6
  50. package/src/themes/bootstrap.ts +0 -44
  51. package/src/themes/default.css +0 -4
  52. package/src/themes/default.ts +0 -255
  53. package/src/themes/material.css +0 -14
  54. package/src/themes/material.ts +0 -250
  55. package/src/util.ts +0 -275
@@ -1,10 +0,0 @@
1
- import { DefaultTheme } from './default';
2
- import { Term } from '@rdfjs/types';
3
- import { ShaclPropertyTemplate } from '../property-template';
4
- import { Editor } from '../theme';
5
- export declare class BootstrapTheme extends DefaultTheme {
6
- constructor();
7
- apply(root: HTMLFormElement): void;
8
- createDefaultTemplate(label: string, value: Term | null, required: boolean, editor: Editor, template?: ShaclPropertyTemplate | undefined): HTMLElement;
9
- createButton(label: string, primary: boolean): HTMLElement;
10
- }
@@ -1,15 +0,0 @@
1
- import { ShaclPropertyTemplate } from '../property-template';
2
- import { Term } from '@rdfjs/types';
3
- import { Theme, InputListEntry, Editor } from '../theme';
4
- export declare class MaterialTheme extends Theme {
5
- constructor();
6
- createDefaultTemplate(label: string, value: Term | null, required: boolean, editor: Editor, template?: ShaclPropertyTemplate): HTMLElement;
7
- createTextEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
8
- createNumberEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
9
- createListEditor(label: string, value: Term | null, required: boolean, listEntries: InputListEntry[], template?: ShaclPropertyTemplate): HTMLElement;
10
- createBooleanEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
11
- createDateEditor(_: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
12
- createLangStringEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
13
- createFileEditor(label: string, value: Term | null, required: boolean, template: ShaclPropertyTemplate): HTMLElement;
14
- createButton(label: string, primary: boolean): HTMLElement;
15
- }
package/src/config.ts DELETED
@@ -1,110 +0,0 @@
1
- import { DataFactory, NamedNode, Prefixes, Store } from 'n3'
2
- import { Term } from '@rdfjs/types'
3
- import { PREFIX_SHACL, RDF_PREDICATE_TYPE } from './constants'
4
- import { ClassInstanceProvider } from './plugin'
5
- import { Loader } from './loader'
6
- import { Theme } from './theme'
7
- import { extractLists } from './util'
8
-
9
- export class ElementAttributes {
10
- shapes: string | null = null
11
- shapesUrl: string | null = null
12
- shapeSubject: string | null = null
13
- values: string | null = null
14
- valuesUrl: string | null = null
15
- /**
16
- * @deprecated Use valuesSubject instead
17
- */
18
- valueSubject: string | null = null // for backward compatibility
19
- valuesSubject: string | null = null
20
- valuesNamespace = ''
21
- valuesGraph: string | null = null
22
- view: string | null = null
23
- language: string | null = null
24
- loading: string = 'Loading\u2026'
25
- proxy: string | null = null
26
- ignoreOwlImports: string | null = null
27
- collapse: string | null = null
28
- submitButton: string | null = null
29
- generateNodeShapeReference: string | null = null
30
- showNodeIds: string | null = null
31
- }
32
-
33
- export class Config {
34
- attributes = new ElementAttributes()
35
- loader = new Loader(this)
36
- classInstanceProvider: ClassInstanceProvider | undefined
37
- prefixes: Prefixes = {}
38
- editMode = true
39
- languages: string[]
40
-
41
- lists: Record<string, Term[]> = {}
42
- groups: Array<string> = []
43
- theme: Theme
44
- form: HTMLElement
45
- renderedNodes = new Set<string>()
46
- valuesGraphId: NamedNode | undefined
47
- private _store = new Store()
48
-
49
- constructor(theme: Theme, form: HTMLElement) {
50
- this.theme = theme
51
- this.form = form
52
- this.languages = [...new Set(navigator.languages.flatMap(lang => {
53
- if (lang.length > 2) {
54
- // for each 5 letter lang code (e.g. de-DE) append its corresponding 2 letter code (e.g. de) directly afterwards
55
- return [lang.toLocaleLowerCase(), lang.substring(0, 2)]
56
- }
57
- return lang
58
- })), ''] // <-- append empty string to accept RDF literals with no language
59
- }
60
-
61
- updateAttributes(elem: HTMLElement) {
62
- const atts = new ElementAttributes();
63
- (Object.keys(atts) as Array<keyof ElementAttributes>).forEach(key => {
64
- const value = elem.dataset[key]
65
- if (value !== undefined) {
66
- atts[key] = value
67
- }
68
- })
69
- this.editMode = atts.view === null
70
- this.attributes = atts
71
- // for backward compatibility
72
- if (this.attributes.valueSubject && !this.attributes.valuesSubject) {
73
- this.attributes.valuesSubject = this.attributes.valueSubject
74
- }
75
- if (atts.language) {
76
- const index = this.languages.indexOf(atts.language)
77
- if (index > -1) {
78
- // remove preferred language from the list of languages
79
- this.languages.splice(index, 1)
80
- }
81
- // now prepend preferred language at start of the list of languages
82
- this.languages.unshift(atts.language)
83
- }
84
- if (atts.valuesGraph) {
85
- this.valuesGraphId = DataFactory.namedNode(atts.valuesGraph)
86
- }
87
- }
88
-
89
- static dataAttributes(): Array<string> {
90
- const atts = new ElementAttributes()
91
- return Object.keys(atts).map(key => {
92
- // convert camelcase key to kebap case
93
- key = key.replace(/[A-Z]/g, m => "-" + m.toLowerCase());
94
- return 'data-' + key
95
- })
96
- }
97
-
98
- get store() {
99
- return this._store
100
- }
101
-
102
- set store(store: Store) {
103
- this._store = store
104
- this.lists = extractLists(store, { ignoreErrors: true })
105
- this.groups = []
106
- store.forSubjects(subject => {
107
- this.groups.push(subject.id)
108
- }, RDF_PREDICATE_TYPE, `${PREFIX_SHACL}PropertyGroup`, null)
109
- }
110
- }
package/src/constants.ts DELETED
@@ -1,30 +0,0 @@
1
- import { DataFactory } from "n3"
2
-
3
- export const PREFIX_SHACL = 'http://www.w3.org/ns/shacl#'
4
- export const PREFIX_DASH = 'http://datashapes.org/dash#'
5
- export const PREFIX_XSD = 'http://www.w3.org/2001/XMLSchema#'
6
- export const PREFIX_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
7
- export const PREFIX_RDFS = 'http://www.w3.org/2000/01/rdf-schema#'
8
- export const PREFIX_SKOS = 'http://www.w3.org/2004/02/skos/core#'
9
- export const PREFIX_OWL = 'http://www.w3.org/2002/07/owl#'
10
- export const PREFIX_OA = 'http://www.w3.org/ns/oa#'
11
- export const PREFIX_DCTERMS = 'http://purl.org/dc/terms/'
12
- export const PREFIX_FOAF = 'http://xmlns.com/foaf/0.1/'
13
-
14
- export const SHAPES_GRAPH = DataFactory.namedNode('loaded-shapes')
15
- export const DATA_GRAPH = DataFactory.namedNode('loaded-data')
16
-
17
- export const RDF_PREDICATE_TYPE = DataFactory.namedNode(PREFIX_RDF + 'type')
18
- export const DCTERMS_PREDICATE_CONFORMS_TO = DataFactory.namedNode(PREFIX_DCTERMS + 'conformsTo')
19
- export const RDFS_PREDICATE_SUBCLASS_OF = DataFactory.namedNode(PREFIX_RDFS + 'subClassOf')
20
- export const OWL_PREDICATE_IMPORTS = DataFactory.namedNode(PREFIX_OWL + 'imports')
21
- export const SKOS_PREDICATE_BROADER = DataFactory.namedNode(PREFIX_SKOS + 'broader')
22
- export const SKOS_PREDICATE_NARROWER = DataFactory.namedNode(PREFIX_SKOS + 'narrower')
23
- export const SHACL_OBJECT_NODE_SHAPE = DataFactory.namedNode(PREFIX_SHACL + 'NodeShape')
24
- export const SHACL_OBJECT_IRI = DataFactory.namedNode(PREFIX_SHACL + 'IRI')
25
- export const SHACL_PREDICATE_PROPERTY = DataFactory.namedNode(PREFIX_SHACL + 'property')
26
- export const SHACL_PREDICATE_CLASS = DataFactory.namedNode(PREFIX_SHACL + 'class')
27
- export const SHACL_PREDICATE_NODE = DataFactory.namedNode(PREFIX_SHACL + 'node')
28
- export const SHACL_PREDICATE_TARGET_CLASS = DataFactory.namedNode(PREFIX_SHACL + 'targetClass')
29
- export const SHACL_PREDICATE_NODE_KIND = DataFactory.namedNode(PREFIX_SHACL + 'nodeKind')
30
- export const XSD_DATATYPE_STRING = DataFactory.namedNode(PREFIX_XSD + 'string')
@@ -1,149 +0,0 @@
1
- import { BlankNode, Literal, NamedNode, Quad } from 'n3'
2
- import { Term } from '@rdfjs/types'
3
- import { ShaclNode } from "./node"
4
- import { ShaclProperty, createPropertyInstance } from "./property"
5
- import { Config } from './config'
6
- import { PREFIX_SHACL, RDF_PREDICATE_TYPE, SHACL_PREDICATE_CLASS, SHACL_PREDICATE_TARGET_CLASS, SHACL_PREDICATE_NODE_KIND, SHACL_OBJECT_IRI, SHACL_PREDICATE_PROPERTY } from './constants'
7
- import { findLabel, removePrefixes } from './util'
8
- import { Editor, InputListEntry } from './theme'
9
-
10
-
11
- export function createShaclOrConstraint(options: Term[], context: ShaclNode | ShaclProperty, config: Config): HTMLElement {
12
- const constraintElement = document.createElement('div')
13
- constraintElement.classList.add('shacl-or-constraint')
14
-
15
- const optionElements: InputListEntry[] = []
16
-
17
- if (context instanceof ShaclNode) {
18
- const properties: ShaclProperty[][] = []
19
- // options can be shacl properties or blank nodes referring to (list of) properties
20
- let optionsAreReferencedProperties = false
21
- if (options.length) {
22
- optionsAreReferencedProperties = config.store.countQuads(options[0], SHACL_PREDICATE_PROPERTY, null, null) > 0
23
- }
24
- for (let i = 0; i < options.length; i++) {
25
- if (optionsAreReferencedProperties) {
26
- const quads = config.store.getObjects(options[i] , SHACL_PREDICATE_PROPERTY, null)
27
- // option can be single property or list of properties
28
- const list: ShaclProperty[] = []
29
- let combinedText = ''
30
- for (const subject of quads) {
31
- const property = new ShaclProperty(subject as NamedNode | BlankNode, context, config)
32
- list.push(property)
33
- combinedText += (combinedText.length > 1 ? ' / ' : '') + property.template.label
34
- }
35
- properties.push(list)
36
- optionElements.push({ label: combinedText, value: i.toString() })
37
- } else {
38
- const property = new ShaclProperty(options[i] as NamedNode | BlankNode, context, config)
39
- properties.push([property])
40
- optionElements.push({ label: property.template.label, value: i.toString() })
41
- }
42
- }
43
- const editor = config.theme.createListEditor('Please choose', null, false, optionElements)
44
- const select = editor.querySelector('.editor') as Editor
45
- select.onchange = () => {
46
- if (select.value) {
47
- const selectedOptions = properties[parseInt(select.value)]
48
- let lastAddedProperty: ShaclProperty
49
- if (selectedOptions.length) {
50
- lastAddedProperty = selectedOptions[0]
51
- constraintElement.replaceWith(selectedOptions[0])
52
- }
53
- for (let i = 1; i < selectedOptions.length; i++) {
54
- lastAddedProperty!.after(selectedOptions[i])
55
- lastAddedProperty = selectedOptions[i]
56
- }
57
- }
58
- }
59
- constraintElement.appendChild(editor)
60
- } else {
61
- const values: Quad[][] = []
62
- for (let i = 0; i < options.length; i++) {
63
- const quads = config.store.getQuads(options[i], null, null, null)
64
- if (quads.length) {
65
- values.push(quads)
66
- optionElements.push({ label: findLabel(quads, config.languages) || (removePrefixes(quads[0].predicate.value, config.prefixes) + ' = ' + removePrefixes(quads[0].object.value, config.prefixes)), value: i.toString() })
67
- }
68
- }
69
- const editor = config.theme.createListEditor(context.template.label + '?', null, false, optionElements, context.template)
70
- const select = editor.querySelector('.editor') as Editor
71
- select.onchange = () => {
72
- if (select.value) {
73
- constraintElement.replaceWith(createPropertyInstance(context.template.clone().merge(values[parseInt(select.value)]), undefined, true))
74
- }
75
- }
76
- constraintElement.appendChild(editor)
77
- }
78
-
79
- return constraintElement
80
- }
81
-
82
- export function resolveShaclOrConstraintOnProperty(subjects: Term[], value: Term, config: Config): Quad[] {
83
- if (value instanceof Literal) {
84
- // value is a literal, try to resolve sh:or/sh:xone by matching on given value datatype
85
- const valueType = value.datatype
86
- for (const subject of subjects) {
87
- const options = config.store.getQuads(subject, null, null, null)
88
- for (const quad of options) {
89
- if (quad.predicate.value === `${PREFIX_SHACL}datatype` && quad.object.equals(valueType)) {
90
- return options
91
- }
92
- }
93
- }
94
- } else {
95
- // value is a NamedNode or BlankNode, try to resolve sh:or/sh:xone by matching rdf:type of given value with sh:node or sh:class in data graph or shapes graph
96
- const types = config.store.getObjects(value, RDF_PREDICATE_TYPE, null)
97
- for (const subject of subjects) {
98
- const options = config.store.getQuads(subject, null, null, null)
99
- for (const quad of options) {
100
- if (types.length > 0) {
101
- // try to find matching sh:node in sh:or/sh:xone values
102
- if (quad.predicate.value === `${PREFIX_SHACL}node`) {
103
- for (const type of types) {
104
- if (config.store.getQuads(quad.object, SHACL_PREDICATE_TARGET_CLASS, type, null).length > 0) {
105
- return options
106
- }
107
- }
108
- }
109
- // try to find matching sh:class in sh:or/sh:xone values
110
- if (quad.predicate.equals(SHACL_PREDICATE_CLASS)) {
111
- for (const type of types) {
112
- if (quad.object.equals(type)) {
113
- return options
114
- }
115
- }
116
- }
117
- } else if (quad.predicate.equals(SHACL_PREDICATE_NODE_KIND) && quad.object.equals(SHACL_OBJECT_IRI)) {
118
- // if sh:nodeKind is sh:IRI, just use that
119
- return options
120
- }
121
- }
122
- }
123
- }
124
- console.error('couldn\'t resolve sh:or/sh:xone on property for value', value)
125
- return []
126
- }
127
-
128
- export function resolveShaclOrConstraintOnNode(subjects: Term[], value: Term, config: Config): Term[] {
129
- for (const subject of subjects) {
130
- let subjectMatches = false
131
- const propertySubjects = config.store.getObjects(subject, SHACL_PREDICATE_PROPERTY, null)
132
- for (const propertySubject of propertySubjects) {
133
- const paths = config.store.getObjects(propertySubject, `${PREFIX_SHACL}path`, null)
134
- for (const path of paths) {
135
- // this allows partial matches in data or shapes graph on properties
136
- subjectMatches = config.store.countQuads(value, path, null, null) > 0
137
- if (subjectMatches) {
138
- break
139
- }
140
- }
141
- }
142
- if (subjectMatches) {
143
- return propertySubjects
144
- }
145
- }
146
-
147
- console.error('couldn\'t resolve sh:or/sh:xone on node for value', value)
148
- return []
149
- }
package/src/exports.ts DELETED
@@ -1,7 +0,0 @@
1
- export type { InputListEntry, Editor } from './theme'
2
- export { Theme } from './theme'
3
- export { Loader } from './loader'
4
- export { Config } from './config'
5
- export { Plugin, registerPlugin } from './plugin'
6
- export { ShaclPropertyTemplate } from './property-template'
7
- export { findLabel } from './util'
@@ -1,12 +0,0 @@
1
- import { ShaclForm as FormBase } from "./form"
2
- import { BootstrapTheme } from "./themes/bootstrap"
3
-
4
- export * from './exports'
5
-
6
- export class ShaclForm extends FormBase {
7
- constructor() {
8
- super(new BootstrapTheme())
9
- }
10
- }
11
-
12
- window.customElements.define('shacl-form', ShaclForm)
@@ -1,12 +0,0 @@
1
- import { ShaclForm as FormBase } from "./form"
2
- import { DefaultTheme } from "./themes/default"
3
-
4
- export * from './exports'
5
-
6
- export class ShaclForm extends FormBase {
7
- constructor() {
8
- super(new DefaultTheme())
9
- }
10
- }
11
-
12
- window.customElements.define('shacl-form', ShaclForm)
@@ -1,12 +0,0 @@
1
- import { ShaclForm as FormBase } from "./form"
2
- import { MaterialTheme } from "./themes/material"
3
-
4
- export * from './exports'
5
-
6
- export class ShaclForm extends FormBase {
7
- constructor() {
8
- super(new MaterialTheme())
9
- }
10
- }
11
-
12
- window.customElements.define('shacl-form', ShaclForm)