@ulb-darmstadt/shacl-form 1.6.3 → 1.6.5

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/dist/util.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NamedNode, Prefixes, Quad, Store } from 'n3';
1
+ import { Literal, NamedNode, Prefixes, Quad, Store } from 'n3';
2
2
  import { Term } from '@rdfjs/types';
3
3
  import { InputListEntry } from './theme';
4
4
  import { ShaclPropertyTemplate } from './property-template';
@@ -10,3 +10,4 @@ export declare function createInputListEntries(subjects: Term[], shapesGraph: St
10
10
  export declare function removePrefixes(id: string, prefixes: Prefixes): string;
11
11
  export declare function findInstancesOf(clazz: NamedNode, template: ShaclPropertyTemplate, indent?: number): InputListEntry[];
12
12
  export declare function isURL(input: string): boolean;
13
+ export declare function prioritizeByLanguage(languages: string[], text1?: Literal, text2?: Literal): Literal | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulb-darmstadt/shacl-form",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "SHACL form generator",
5
5
  "main": "dist/form-default.js",
6
6
  "module": "dist/form-default.js",
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Prefixes, Store } from 'n3'
1
+ import { DataFactory, NamedNode, Prefixes, Store } from 'n3'
2
2
  import { Term } from '@rdfjs/types'
3
3
  import { PREFIX_SHACL, RDF_PREDICATE_TYPE } from './constants'
4
4
  import { ClassInstanceProvider } from './plugin'
@@ -17,6 +17,7 @@ export class ElementAttributes {
17
17
  valueSubject: string | null = null // for backward compatibility
18
18
  valuesSubject: string | null = null
19
19
  valuesNamespace = ''
20
+ valuesGraph: string | null = null
20
21
  view: string | null = null
21
22
  language: string | null = null
22
23
  loading: string = 'Loading\u2026'
@@ -41,6 +42,7 @@ export class Config {
41
42
  theme: Theme
42
43
  form: HTMLElement
43
44
  renderedNodes = new Set<string>()
45
+ valuesGraph: NamedNode | undefined
44
46
  private _shapesGraph = new Store()
45
47
 
46
48
  constructor(theme: Theme, form: HTMLElement) {
@@ -49,10 +51,10 @@ export class Config {
49
51
  this.languages = [...new Set(navigator.languages.flatMap(lang => {
50
52
  if (lang.length > 2) {
51
53
  // for each 5 letter lang code (e.g. de-DE) append its corresponding 2 letter code (e.g. de) directly afterwards
52
- return [lang, lang.substring(0, 2)]
54
+ return [lang.toLocaleLowerCase(), lang.substring(0, 2)]
53
55
  }
54
56
  return lang
55
- }))]
57
+ })), ''] // <-- append empty string to accept RDF literals with no language
56
58
  }
57
59
 
58
60
  updateAttributes(elem: HTMLElement) {
@@ -78,6 +80,7 @@ export class Config {
78
80
  // now prepend preferred language at start of the list of languages
79
81
  this.languages.unshift(atts.language)
80
82
  }
83
+ this.valuesGraph = atts.valuesGraph ? DataFactory.namedNode(atts.valuesGraph) : undefined
81
84
  }
82
85
 
83
86
  static dataAttributes(): Array<string> {
package/src/node.ts CHANGED
@@ -154,11 +154,11 @@ export class ShaclNode extends HTMLElement {
154
154
  (shape as ShaclNode | ShaclProperty).toRDF(graph, subject)
155
155
  }
156
156
  if (this.targetClass) {
157
- graph.addQuad(subject, RDF_PREDICATE_TYPE, this.targetClass)
157
+ graph.addQuad(subject, RDF_PREDICATE_TYPE, this.targetClass, this.config.valuesGraph)
158
158
  }
159
159
  // if this is the root shacl node, check if we should add one of the rdf:type or dcterms:conformsTo predicates
160
160
  if (this.config.attributes.generateNodeShapeReference && !this.parent) {
161
- graph.addQuad(subject, DataFactory.namedNode(this.config.attributes.generateNodeShapeReference), this.shaclSubject)
161
+ graph.addQuad(subject, DataFactory.namedNode(this.config.attributes.generateNodeShapeReference), this.shaclSubject, this.config.valuesGraph)
162
162
  }
163
163
  return subject
164
164
  }
@@ -2,12 +2,12 @@ import { Literal, NamedNode, Quad, DataFactory } from 'n3'
2
2
  import { Term } from '@rdfjs/types'
3
3
  import { OWL_PREDICATE_IMPORTS, PREFIX_DASH, PREFIX_OA, PREFIX_RDF, PREFIX_SHACL, SHACL_PREDICATE_CLASS, SHACL_PREDICATE_TARGET_CLASS } from './constants'
4
4
  import { Config } from './config'
5
- import { findLabel, removePrefixes } from './util'
5
+ import { findLabel, prioritizeByLanguage, removePrefixes } from './util'
6
6
  import { ShaclNode } from './node'
7
7
 
8
8
  const mappers: Record<string, (template: ShaclPropertyTemplate, term: Term) => void> = {
9
- [`${PREFIX_SHACL}name`]: (template, term) => { const literal = term as Literal; if (!template.name || literal.language === template.config.attributes.language) { template.name = literal } },
10
- [`${PREFIX_SHACL}description`]: (template, term) => { const literal = term as Literal; if (!template.description || literal.language === template.config.attributes.language) { template.description = literal } },
9
+ [`${PREFIX_SHACL}name`]: (template, term) => { const literal = term as Literal; template.name = prioritizeByLanguage(template.config.languages, template.name, literal) },
10
+ [`${PREFIX_SHACL}description`]: (template, term) => { const literal = term as Literal; template.description = prioritizeByLanguage(template.config.languages, template.description, literal) },
11
11
  [`${PREFIX_SHACL}path`]: (template, term) => { template.path = term.value },
12
12
  [`${PREFIX_SHACL}node`]: (template, term) => { template.node = term as NamedNode },
13
13
  [`${PREFIX_SHACL}datatype`]: (template, term) => { template.datatype = term as NamedNode },
package/src/property.ts CHANGED
@@ -123,14 +123,13 @@ export class ShaclProperty extends HTMLElement {
123
123
  for (const instance of this.querySelectorAll(':scope > .property-instance')) {
124
124
  const pathNode = DataFactory.namedNode((instance as HTMLElement).dataset.path!)
125
125
  if (instance.firstChild instanceof ShaclNode) {
126
- const quadCount = graph.size
127
126
  const shapeSubject = instance.firstChild.toRDF(graph)
128
- graph.addQuad(subject, pathNode, shapeSubject)
127
+ graph.addQuad(subject, pathNode, shapeSubject, this.template.config.valuesGraph)
129
128
  } else {
130
129
  const editor = instance.querySelector('.editor') as Editor
131
130
  const value = toRDF(editor)
132
131
  if (value) {
133
- graph.addQuad(subject, pathNode, value)
132
+ graph.addQuad(subject, pathNode, value, this.template.config.valuesGraph)
134
133
  }
135
134
  }
136
135
  }
@@ -3,5 +3,12 @@
3
3
  --mdui-color-primary-dark: var(--mdui-color-primary-dark);
4
4
  --mdui-color-background-light: var(--mdui-color-background-light);
5
5
  }
6
+ /* this prevents hiding the date picker icon and number controls */
7
+ mdui-text-field::part(input) {
8
+ clip-path: none;
9
+ appearance: inherit;
10
+ }
6
11
  form.mode-edit { --label-width: 0em; }
7
12
  .property-instance { margin-bottom:14px; }
13
+ .mode-edit .property-instance *[required]::part(icon) { align-self: flex-start; padding-top: 0.7em; }
14
+ .mode-edit .property-instance *[required]::part(icon)::before { color: red; content: '\2736'; font-size: 0.6em; }
@@ -93,6 +93,7 @@ export class MaterialTheme extends Theme {
93
93
  editor.variant = 'outlined'
94
94
  editor.label = label
95
95
  editor.helper = template?.description?.value
96
+ editor.clearable = true
96
97
  // @ts-ignore
97
98
  const result = this.createDefaultTemplate('', null, required, editor, template)
98
99
  let addEmptyOption = true
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NamedNode, Prefixes, Quad, Store } from 'n3'
1
+ import { Literal, NamedNode, Prefixes, Quad, Store } from 'n3'
2
2
  import { OWL_OBJECT_NAMED_INDIVIDUAL, PREFIX_RDFS, PREFIX_SHACL, PREFIX_SKOS, RDFS_PREDICATE_SUBCLASS_OF, RDF_PREDICATE_TYPE, SHAPES_GRAPH, SKOS_PREDICATE_BROADER } from './constants'
3
3
  import { Term } from '@rdfjs/types'
4
4
  import { InputListEntry } from './theme'
@@ -114,3 +114,21 @@ export function isURL(input: string): boolean {
114
114
  }
115
115
  return url.protocol === 'http:' || url.protocol === 'https:'
116
116
  }
117
+
118
+ export function prioritizeByLanguage(languages: string[], text1?: Literal, text2?: Literal): Literal | undefined {
119
+ if (text1 === undefined) {
120
+ return text2
121
+ }
122
+ if (text2 === undefined) {
123
+ return text1
124
+ }
125
+ const index1 = languages.indexOf(text1.language)
126
+ if (index1 < 0) {
127
+ return text2
128
+ }
129
+ const index2 = languages.indexOf(text2.language)
130
+ if (index2 < 0) {
131
+ return text1
132
+ }
133
+ return index2 > index1 ? text1 : text2
134
+ }