Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0a6d16b
rdf forms component
timea-solid Jun 16, 2026
7c5a7c3
rendered first rdf forms elements
timea-solid Jun 16, 2026
35c066f
preliminary work for rdf-input
timea-solid Jun 17, 2026
a20fa4f
Merge branch 'staging' into rdfComponets
timea-solid Jun 22, 2026
5cd82c0
merge staging and moved components
timea-solid Jun 22, 2026
344b904
added also data to forms and wired the rdf input
timea-solid Jun 22, 2026
9d5565a
fixed rdf input
timea-solid Jun 22, 2026
0656653
Refactor for better readability
timea-solid Jun 22, 2026
84345df
fix types
timea-solid Jun 23, 2026
372135f
reverted the sortBySequence code back to original
timea-solid Jun 23, 2026
638786e
Merge branch 'staging' into rdfComponets
timea-solid Jun 24, 2026
235b0d0
vite config for generating custom elements tag name map
timea-solid Jun 24, 2026
da5c6fa
Merge branch 'staging' into rdfComponets
timea-solid Jun 25, 2026
35f4445
a first FormsContext with a default store from SolidLogic
timea-solid Jun 29, 2026
0d99a1b
added placeholder property to input
timea-solid Jun 29, 2026
7b7f9a9
added readonly to Input and used it in RDFinput
timea-solid Jun 29, 2026
65735ae
improved store usage
timea-solid Jun 29, 2026
cfb0475
added readonly style to input
timea-solid Jun 29, 2026
c81b17e
added save features, copied over code
timea-solid Jun 29, 2026
082b9ee
added an updater to the storybook store
timea-solid Jun 30, 2026
2b53d6c
added data change capabilities, 1st version
timea-solid Jun 30, 2026
403a143
Update src/components/input/Input.styles.css
timea-solid Jun 30, 2026
0af9ce9
rename to NoopStore
timea-solid Jun 30, 2026
9d9f48a
renamed NoopStore
timea-solid Jun 30, 2026
3da4992
cleanup from feedback
timea-solid Jun 30, 2026
643dc5a
imporved component type declarations
timea-solid Jun 30, 2026
d40ac8b
merge staging
timea-solid Jun 30, 2026
b076703
Addeda URL lit converter
timea-solid Jul 2, 2026
242180a
simplify components properties
timea-solid Jul 2, 2026
c410374
merge staging
timea-solid Jul 2, 2026
5fdb7bc
random name attribute
timea-solid Jul 2, 2026
bfeed32
rework logic of readonly
timea-solid Jul 2, 2026
eba9a70
use document instead of uri with fragment
timea-solid Jul 2, 2026
c9c7cf3
fixed statement insert
timea-solid Jul 2, 2026
a0eaae5
decode defensively
timea-solid Jul 2, 2026
d8604c6
small copilot suggested improvments
timea-solid Jul 2, 2026
6280cb4
chnaged from readonly to disabled on select
timea-solid Jul 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/combobox/Combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default class Combobox extends WebComponent {
@query('input')
private accessor inputElement: HTMLInputElement | null = null

@property({ type: Boolean, reflect: true })
accessor readonly = false

@state()
private accessor filter = ''

Expand Down Expand Up @@ -67,6 +70,7 @@ export default class Combobox extends WebComponent {
name=${this.name}
?placeholder=${this.placeholder}
?required=${this.required}
?readonly=${this.readonly}
.value=${this.value}
@keydown=${this.onInputKeyDown}
@click=${this.onInputClick}
Expand Down
7 changes: 7 additions & 0 deletions src/components/input/Input.styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
color: var(--solid-ui-color-gray-700);
font-size: inherit;
}

input:read-only {
border: none;
padding: 0;
cursor: pointer;
Comment thread
timea-solid marked this conversation as resolved.
Outdated
}
}

}
4 changes: 4 additions & 0 deletions src/components/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class Input extends WebComponent {
@property({ type: Boolean, reflect: true })
accessor required = false;

@property({ type: Boolean, reflect: true })
accessor readonly = false;

@query('input')
private accessor inputElement: HTMLInputElement | null = null;

Expand All @@ -54,6 +57,7 @@ export default class Input extends WebComponent {
placeholder=${this.placeholder}
?required=${this.required}
.value=${this.value}
?readonly=${this.readonly}
@input=${() => this.inputTrait.onInput()}
@keydown=${this.onKeyDown}
/>
Expand Down
205 changes: 205 additions & 0 deletions src/components/rdf-form/RDFForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import { property, state } from 'lit/decorators.js'
import { html } from 'lit/html.js'
import { consume } from '@lit/context'
import { customElement, WebComponent } from '@/lib/components'
import ns from '../../lib/ns'
import { loadDocument, sortBySequence } from '../../lib/forms/rdfFormsHelper'
import { sym, Namespace, LiveStore } from 'rdflib'
import '@/components/rdf-input'
import { DEFAULT_STORE, storeContext, StoreContext } from '@/lib/forms/store/StoreContext'

@customElement('solid-ui-rdf-form')
export default class RDFForm extends WebComponent {
@consume({ context: storeContext, subscribe: true })
private accessor storeContext: StoreContext = DEFAULT_STORE

@property({ attribute: false })
Comment thread
timea-solid marked this conversation as resolved.
accessor passedInStore: LiveStore | null = null

private get currentStoreContext (): StoreContext | null {
if (this.passedInStore) {
return { store: this.passedInStore }
}

return this.storeContext !== DEFAULT_STORE ? this.storeContext : null
Comment thread
timea-solid marked this conversation as resolved.
Outdated
}
Comment on lines +38 to +44

@state()
private accessor failed: boolean = false

@state()
private accessor submitting: boolean = false

@state()
private accessor entireDataIsReadonly: boolean = true

@state()
private accessor _parsedUrl: URL | null = null
Comment thread
timea-solid marked this conversation as resolved.
Outdated

@state()
private accessor _parsedUrl2: URL | null = null

@property({ type: String })
accessor whichForm = 'this'

@property({ type: String })
accessor rdfTurtleFormatSource = ''

@property({ type: String })
accessor rdfName = ''

@property({ type: String })
set rdfURI (value: string) {
Comment thread
timea-solid marked this conversation as resolved.
Outdated
try {
this._parsedUrl = new URL(value)
} catch {
this._parsedUrl = null // Handle invalid URL
}
}

get rdfURI (): string {
return this._parsedUrl ? this._parsedUrl.href : ''
}

@property({ type: String })
accessor whichSubject = 'me'

@property({ type: String })
accessor subjectTurtleFormatSource = ''

@property({ type: String })
accessor subjectName = ''

@property({ type: String })
set subjectURI (value: string) {
try {
this._parsedUrl2 = new URL(value)
} catch {
this._parsedUrl2 = null // Handle invalid URL
}
}

get subjectURI (): string {
return this._parsedUrl2 ? this._parsedUrl2.href : ''
}

render () {
const currentStoreContext = this.currentStoreContext

if (!currentStoreContext) {
console.warn('RDFForm: store context not available yet')
return html``
}

const store = currentStoreContext.store

if (!store.updater?.editable(this.subjectURI)) {
this.entireDataIsReadonly = true
}
Comment on lines +66 to +71

// TODO: detect format
loadDocument(store, this.rdfTurtleFormatSource, this.rdfName, this.rdfURI) // load form
Comment thread
timea-solid marked this conversation as resolved.
Outdated
loadDocument(store, this.subjectTurtleFormatSource, this.subjectName, this.subjectURI) // load data
const document = sym(this.rdfURI) // rdflib NamedNode for the document
const exactForm = this.whichForm // If there are more 'a ui:Form' elements in a form file
const formThis = Namespace(this.rdfURI + '#')(exactForm) // NamedNode for #this in the form

const parts = store.each(formThis, ns.ui('parts'), null, document)
const partsBySequence = sortBySequence(store, parts)
const partItems = (partsBySequence || []).flatMap(item => {
if (item && typeof item === 'object' && 'elements' in item && Array.isArray((item as any).elements)) {
return (item as any).elements
}
return [item]
})
const uiFields = partItems.map(item => {
const types = store.each(item as any, ns.rdf('type'), null, document)
const typeNode = types[0]
const value = typeNode ? ((typeNode as any).value || String(typeNode)) : ((item as any).value || String(item))
const hashIndex = value.lastIndexOf('#')
return {
value: item,
fieldValue: hashIndex >= 0 ? value.slice(hashIndex + 1) : value
}
})
const me = Namespace(this.subjectURI + '#')(this.whichSubject)

return html`
Comment thread
timea-solid marked this conversation as resolved.
<form @submit=${this.onSubmit}>
${uiFields.map(part => {
switch (part.fieldValue) {
case 'PhoneField':
case 'EmailField':
case 'ColorField':
case 'DateField':
case 'DateTimeField':
case 'TimeField':
case 'NumericField':
case 'IntegerField':
case 'DecimalField':
case 'FloatField':
case 'TextField':
case 'SingleLineTextField':
case 'NamedNodeURIField': {
return html` <solid-ui-rdf-input
.formSubject=${sym(part.value)}
.dataSubject=${me}
readonly=${this.entireDataIsReadonly}
></solid-ui-rdf-input>
<br>`
}
case 'MultiLineTextField':
return html`<input .rdf=${part}></input>`
case 'BooleanField':
return html`<input .rdf=${part}></input>`
case 'TristateField':
return html`<input .rdf=${part}></input>`
case 'Classifier':
return html`<input .rdf=${part}></input>`
case 'Choice':
return html`<input .rdf=${part}></input>`
case 'Multiple':
return html`<input .rdf=${part}></input>`
case 'Options':
return html`<input .rdf=${part}></input>`
case 'AutocompleteField':
return html`<input .rdf=${part}></input>`
case 'Comment':
case 'Heading':
return html`<input .rdf=${part}></input>`
default:
return html`<div>Unknown part type: ${part}</div>`
}
})}
<solid-ui-button
?disabled=${!store.updater?.editable(this.subjectURI) || this.submitting}
?loading=${this.submitting}
type="submit"
>
Save
</solid-ui-button>
</form>
`
}

private async onSubmit (e: Event) {
e.preventDefault()

this.failed = false

this.submitting = true

try {
const currentStoreContext = this.currentStoreContext
if (currentStoreContext?.store.updater?.editable(this.subjectURI)) {
// this.saveStatements()
}
} catch (error) {
console.error(error)

this.failed = true
} finally {
this.submitting = false
}
}
}
122 changes: 122 additions & 0 deletions src/components/rdf-form/RDForm.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { html } from 'lit'
import { defineStoryRender } from '../../storybook'
import './RDFForm'
Comment thread
timea-solid marked this conversation as resolved.

const meta = {
title: 'Design System/RDF Form',
args: {
rdfTurtleFormatSource: `
@prefix : <https://solidos.solidcommunity.net/public/2021/solidUiFormTestData/dummyFormTestFile.ttl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix sched: <http://www.w3.org/ns/pim/schedule#>.
@prefix cal: <http://www.w3.org/2002/12/cal/ical#>.
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix ui: <http://www.w3.org/ns/ui#>.
@prefix trip: <http://www.w3.org/ns/pim/trip#>.
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

# A Form with 3 fields and a nested subgroup

:form a ui:Form;
ui:parts (:nameField :emailField :phoneField :addresses) .

:nameField a ui:SingleLineTextField ;
ui:property vcard:fn;
ui:label "name" .


:emailField a ui:EmailField ;
ui:property vcard:hasEmail; # @@ check
ui:label "email" .

:phoneField a ui:PhoneField ;
ui:property vcard:hasTelephone;
ui:label "phone" .

:addresses
a ui:Multiple ; # -- Allows zero or one or more
ui:part :oneAddress ;
ui:property vcard:hasAddress .

:oneAddress
a ui:Group ; # A subgroup of the main form
ui:parts ( :street :locality :postcode :region :country ).

:street
a ui:SingleLineTextField ;
ui:maxLength "128" ;
ui:property vcard:street-address ;
ui:size "40" .

:locality
a ui:SingleLineTextField ;
ui:maxLength "128" ;
ui:property vcard:locality ;
ui:size "40" .

:postcode
a ui:SingleLineTextField ;
ui:maxLength "25" ;
ui:property vcard:postal-code ;
ui:size "25" .

:region
a ui:SingleLineTextField ;
ui:maxLength "128" ;
ui:property vcard:region ;
ui:size "40" .

:country
a ui:SingleLineTextField ;
ui:maxLength "128" ;
ui:property vcard:country-name ;
ui:size "40" .
`,
rdfURI: 'https://solidos.solidcommunity.net/public/2021/solidUiFormTestData/dummyFormTestFile.ttl', // we need a working URL
whichForm: 'form',
rdfName: 'dummyFormTestFile.ttl',
whichSubject: 'me',
subjectTurtleFormatSource: `
@prefix : <https://solidos.solidcommunity.net/public/2021/alice.ttl#>.
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.

:me a vcard:Individual ;
vcard:fn "Alice" ;
vcard:hasEmail <mailto:alice@example.com> .
`,
subjectName: 'alice.ttl',
subjectURI: 'https://solidos.solidcommunity.net/public/2021/alice.ttl'
},

argTypes: {
rdfTurtleFormatSource: { control: 'text' },
rdfURI: { control: 'text' },
whichForm: { control: 'text' },
rdfName: { control: 'text' },
subjectTurtleFormatSource: { control: 'text' },
subjectName: { control: 'text' },
subjectURI: { control: 'text' }
},
} as const

const render = defineStoryRender<typeof meta.argTypes>(({ rdfTurtleFormatSource, rdfURI, whichForm, rdfName, subjectTurtleFormatSource, subjectName, subjectURI }) => {
return html`
<storybook-provider>
Comment thread
timea-solid marked this conversation as resolved.
Outdated
<solid-ui-rdf-form
rdfTurtleFormatSource=${rdfTurtleFormatSource}
rdfURI=${rdfURI}
whichForm=${whichForm}
rdfName=${rdfName}
subjectTurtleFormatSource=${subjectTurtleFormatSource}
subjectName=${subjectName}
subjectURI=${subjectURI}>
Comment thread
timea-solid marked this conversation as resolved.
Outdated
</solid-ui-rdf-form>
</storybook-provider>
`
})

export default meta

export const Primary = { render }
4 changes: 4 additions & 0 deletions src/components/rdf-form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import RDFForm from './RDFForm'

export { RDFForm }
export default RDFForm
Loading
Loading