@@ -3,8 +3,8 @@ import { html } from 'lit/html.js'
33import { consume } from '@lit/context'
44import { customElement , WebComponent } from '@/lib/components'
55import ns from '../../lib/ns'
6- import { loadDocument , sortBySequence } from '../../lib/forms/rdfFormsHelper'
7- import { sym , Namespace , LiveStore } from 'rdflib'
6+ import { fetchData , findForm , sortBySequence } from '../../lib/forms/rdfFormsHelper'
7+ import { sym , LiveStore } from 'rdflib'
88import '@/components/rdf-input'
99import { DEFAULT_STORE , storeContext , StoreContext } from '@/lib/forms/store/StoreContext'
1010
@@ -52,49 +52,29 @@ export default class RDFForm extends WebComponent {
5252 @state ( )
5353 private accessor _documentsLoaded = false
5454
55- @property ( { type : String } )
56- accessor whichForm = 'this'
57-
58- @property ( { type : String } )
59- accessor rdfTurtleFormatSource = ''
60-
61- @property ( { type : String } )
62- accessor rdfName = ''
63-
6455 @property ( { converter : urlConverter } )
65- accessor rdfURI : URL | null = null
66-
67- @property ( { type : String } )
68- accessor whichSubject = 'me'
69-
70- @property ( { type : String } )
71- accessor subjectTurtleFormatSource = ''
72-
73- @property ( { type : String } )
74- accessor subjectName = ''
56+ accessor formUrl : URL | null = null
7557
7658 @property ( { converter : urlConverter } )
77- accessor subjectURI : URL | null = null
59+ accessor subjectUrl : URL | null = null
7860
7961 render ( ) {
80- console . log ( 'subjectURI ' , this . subjectURI )
81- console . log ( 'rdfURI ' , this . rdfURI )
8262 if ( ! this . _documentsLoaded ) {
8363 return html ``
8464 }
8565
8666 const store = this . currentStoreContext . store
87- const subjectURI = hrefFromUrlValue ( this . subjectURI )
8867
89- if ( subjectURI && store . updater ?. editable ( subjectURI ) === false ) {
68+ const subjectUrl = hrefFromUrlValue ( this . subjectUrl )
69+ if ( subjectUrl && store . updater ?. editable ( subjectUrl ) === false ) {
9070 this . entireDataIsReadonly = true
9171 }
9272
93- const document = sym ( hrefFromUrlValue ( this . rdfURI ) ) // rdflib NamedNode for the document
94- const exactForm = this . whichForm // If there are more 'a ui:Form' elements in a form file
95- const formThis = Namespace ( `${ hrefFromUrlValue ( this . rdfURI ) } #` ) ( exactForm ) // NamedNode for #this in the form
73+ const formRoot = findForm ( this . currentStoreContext . store , hrefFromUrlValue ( this . formUrl ) ) // If there are more 'a ui:Form' elements in a form file
74+ if ( ! formRoot ) throw new Error ( 'No ui:Form found in ' + hrefFromUrlValue ( this . formUrl ) )
9675
97- const parts = store . each ( formThis , ns . ui ( 'parts' ) , null , document )
76+ const formDocument = sym ( hrefFromUrlValue ( this . formUrl ) ) // rdflib NamedNode for the document
77+ const parts = store . each ( formRoot , ns . ui ( 'parts' ) , null , formDocument )
9878 const partsBySequence = sortBySequence ( store , parts )
9979 const partItems = ( partsBySequence || [ ] ) . flatMap ( item => {
10080 if ( item && typeof item === 'object' && 'elements' in item && Array . isArray ( ( item as any ) . elements ) ) {
@@ -103,7 +83,7 @@ export default class RDFForm extends WebComponent {
10383 return [ item ]
10484 } )
10585 const uiFields = partItems . map ( item => {
106- const types = store . each ( item as any , ns . rdf ( 'type' ) , null , document )
86+ const types = store . each ( item as any , ns . rdf ( 'type' ) , null , formDocument )
10787 const typeNode = types [ 0 ]
10888 const value = typeNode ? ( ( typeNode as any ) . value || String ( typeNode ) ) : ( ( item as any ) . value || String ( item ) )
10989 const hashIndex = value . lastIndexOf ( '#' )
@@ -112,7 +92,6 @@ export default class RDFForm extends WebComponent {
11292 fieldValue : hashIndex >= 0 ? value . slice ( hashIndex + 1 ) : value
11393 }
11494 } )
115- const me = Namespace ( `${ hrefFromUrlValue ( this . subjectURI ) } #` ) ( this . whichSubject )
11695
11796 return html `
11897 < form >
@@ -133,7 +112,7 @@ export default class RDFForm extends WebComponent {
133112 case 'NamedNodeURIField' : {
134113 return html ` < solid-ui-rdf-input
135114 .formSubject =${ sym ( part . value ) }
136- .dataSubject =${ me }
115+ .dataSubject =${ sym ( subjectUrl ) }
137116 .storeVersion=${ this . _loadVersion }
138117 .readonly=${ this . entireDataIsReadonly }
139118 > </ solid-ui-rdf-input >
@@ -168,13 +147,8 @@ export default class RDFForm extends WebComponent {
168147
169148 protected updated ( changedProperties : Map < PropertyKey , unknown > ) {
170149 super . updated ( changedProperties )
171- if (
172- changedProperties . has ( 'rdfTurtleFormatSource' ) ||
173- changedProperties . has ( 'rdfName' ) ||
174- changedProperties . has ( 'rdfURI' ) ||
175- changedProperties . has ( 'subjectTurtleFormatSource' ) ||
176- changedProperties . has ( 'subjectName' ) ||
177- changedProperties . has ( 'subjectURI' ) ||
150+ if ( changedProperties . has ( 'formUrl' ) ||
151+ changedProperties . has ( 'subjectUrl' ) ||
178152 changedProperties . has ( 'passedInStore' )
179153 ) {
180154 this . loadDocumentsIfNeeded ( )
@@ -183,14 +157,14 @@ export default class RDFForm extends WebComponent {
183157
184158 private async loadDocumentsIfNeeded ( ) {
185159 const store = this . currentStoreContext . store
186- const rdfURI = hrefFromUrlValue ( this . rdfURI )
187- const subjectURI = hrefFromUrlValue ( this . subjectURI )
160+ const formUrl = hrefFromUrlValue ( this . formUrl )
161+ const subjectUrl = hrefFromUrlValue ( this . subjectUrl )
188162
189- if ( ! rdfURI || ! subjectURI ) return
163+ if ( ! formUrl || ! subjectUrl ) return
190164
191165 try {
192- await loadDocument ( store , this . rdfTurtleFormatSource , this . rdfName , rdfURI , false )
193- await loadDocument ( store , this . subjectTurtleFormatSource , this . subjectName , subjectURI , true )
166+ await fetchData ( store , formUrl )
167+ await fetchData ( store , subjectUrl )
194168 this . _loadVersion += 1
195169 this . _documentsLoaded = true
196170 } catch ( error ) {
0 commit comments