@ulb-darmstadt/shacl-form 1.10.2 → 1.10.3

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.
@@ -1,4 +1,4 @@
1
1
  import { NamedNode, Quad, Literal, Prefixes } from 'n3';
2
2
  import { Editor } from './theme';
3
3
  export declare function serialize(quads: Quad[], format: string, prefixes?: Prefixes): string;
4
- export declare function toRDF(editor: Editor): Literal | NamedNode | undefined;
4
+ export declare function toRDF(editor: Editor): NamedNode | Literal | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulb-darmstadt/shacl-form",
3
- "version": "1.10.2",
3
+ "version": "1.10.3",
4
4
  "description": "SHACL form generator",
5
5
  "main": "dist/form-default.js",
6
6
  "module": "dist/form-default.js",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "peerDependencies": {
79
79
  "lit": "^3.3.1",
80
- "@ro-kit/ui-widgets": "^0.0.43",
80
+ "@ro-kit/ui-widgets": "^0.0.44",
81
81
  "mdui": "^2.1.4"
82
82
  }
83
83
  }
package/src/form.ts CHANGED
@@ -43,11 +43,11 @@ export class ShaclForm extends HTMLElement {
43
43
 
44
44
  private initialize() {
45
45
  clearTimeout(this.initDebounceTimeout)
46
+ // set loading attribute on element so that hosting app can apply special css rules
47
+ this.setAttribute('loading', '')
48
+ // remove all child elements from form and show loading indicator
49
+ this.form.replaceChildren(document.createTextNode(this.config.attributes.loading))
46
50
  this.initDebounceTimeout = setTimeout(async () => {
47
- // set loading attribute on element so that hosting app can apply special css rules
48
- this.setAttribute('loading', '')
49
- // remove all child elements from form and show loading indicator
50
- this.form.replaceChildren(document.createTextNode(this.config.attributes.loading))
51
51
  try {
52
52
  await this.config.loader.loadGraphs()
53
53
  // remove loading indicator
package/src/serialize.ts CHANGED
@@ -45,7 +45,7 @@ function serializeJsonld(quads: Quad[]): string {
45
45
  return JSON.stringify(triples)
46
46
  }
47
47
 
48
- export function toRDF(editor: Editor): Literal | NamedNode | undefined {
48
+ export function toRDF(editor: Editor): NamedNode | Literal | undefined {
49
49
  let languageOrDatatype: NamedNode<string> | string | undefined = editor.shaclDatatype
50
50
  let value: number | string = editor.value
51
51
  if (value) {
@@ -69,15 +69,20 @@ export function toRDF(editor: Editor): Literal | NamedNode | undefined {
69
69
  // if seconds in value are 0, the input field omits them which is then not a valid xsd:dateTime
70
70
  value = new Date(value).toISOString().slice(0, 19)
71
71
  }
72
- // check if value is a typed rdf literal
72
+ // check if value is a typed rdf literal or langString
73
73
  if (!languageOrDatatype && typeof value === 'string') {
74
- const tokens = value.split('^^')
75
- if (tokens.length === 2 &&
76
- ((tokens[0].startsWith('"') && tokens[0].endsWith('"') || tokens[0].startsWith('\'') && tokens[0].endsWith('\''))) &&
77
- tokens[1].split(':').length === 2
78
- ) {
74
+ // check for typed rdf literal
75
+ let tokens = value.split('^^')
76
+ if (tokens.length === 2 && tokens[0].startsWith('"') && tokens[0].endsWith('"') && tokens[1].split(':').length === 2) {
79
77
  value = tokens[0].substring(1, tokens[0].length - 1)
80
78
  languageOrDatatype = DataFactory.namedNode(tokens[1])
79
+ } else {
80
+ // check for langString
81
+ tokens = value.split('@')
82
+ if (tokens.length === 2 && tokens[0].startsWith('"') && tokens[0].endsWith('"')) {
83
+ value = tokens[0].substring(1, tokens[0].length - 1)
84
+ languageOrDatatype = tokens[1]
85
+ }
81
86
  }
82
87
  }
83
88
  return DataFactory.literal(value, languageOrDatatype)
@@ -1,7 +1,7 @@
1
1
  import { Term } from '@rdfjs/types'
2
2
  import { ShaclPropertyTemplate } from "../property-template"
3
3
  import { Editor, InputListEntry, Theme } from "../theme"
4
- import { PREFIX_SHACL, PREFIX_XSD, XSD_DATATYPE_STRING } from '../constants'
4
+ import { PREFIX_SHACL, PREFIX_XSD } from '../constants'
5
5
  import { Literal, NamedNode } from 'n3'
6
6
  import { Term as N3Term } from 'n3'
7
7
  import css from './default.css?raw'
@@ -218,14 +218,7 @@ export class DefaultTheme extends Theme {
218
218
  li.dataset.value = entry.value
219
219
  li.innerText = entry.label ? entry.label : entry.value
220
220
  } else {
221
- if (entry.value instanceof Literal && entry.value.datatype.equals(XSD_DATATYPE_STRING)) {
222
- li.dataset.value = entry.value.value
223
- } else if (entry.value instanceof NamedNode) {
224
- li.dataset.value = '<' + entry.value.value + ">"
225
- } else {
226
- // this is needed for typed rdf literals e.g. "ex"^^xsd:anyUri
227
- li.dataset.value = (entry.value as N3Term).id
228
- }
221
+ li.dataset.value = (entry.value as N3Term).id
229
222
  li.innerText = entry.label ? entry.label : entry.value.value
230
223
  }
231
224
  parent.appendChild(li)
@@ -248,7 +241,7 @@ export class DefaultTheme extends Theme {
248
241
 
249
242
  editor.appendChild(ul)
250
243
  if (value) {
251
- editor.value = value.value
244
+ editor.value = (value as N3Term).id
252
245
  }
253
246
  return result
254
247
  }