@ulb-darmstadt/shacl-form 1.6.3 → 1.6.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/dist/form-bootstrap.js +1 -1
- package/dist/form-default.js +1 -1
- package/dist/form-material.js +1 -1
- package/dist/util.d.ts +2 -1
- package/package.json +1 -1
- package/src/config.ts +2 -2
- package/src/property-template.ts +3 -3
- package/src/themes/material.css +7 -0
- package/src/themes/material.ts +1 -0
- package/src/util.ts +19 -1
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
package/src/config.ts
CHANGED
|
@@ -49,10 +49,10 @@ export class Config {
|
|
|
49
49
|
this.languages = [...new Set(navigator.languages.flatMap(lang => {
|
|
50
50
|
if (lang.length > 2) {
|
|
51
51
|
// 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)]
|
|
52
|
+
return [lang.toLocaleLowerCase(), lang.substring(0, 2)]
|
|
53
53
|
}
|
|
54
54
|
return lang
|
|
55
|
-
}))]
|
|
55
|
+
})), ''] // <-- append empty string to accept RDF literals with no language
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
updateAttributes(elem: HTMLElement) {
|
package/src/property-template.ts
CHANGED
|
@@ -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;
|
|
10
|
-
[`${PREFIX_SHACL}description`]: (template, term) => { const literal = term as 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/themes/material.css
CHANGED
|
@@ -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; }
|
package/src/themes/material.ts
CHANGED
|
@@ -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
|
+
}
|