Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
72 changes: 56 additions & 16 deletions dev/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@ import * as paneRegistry from 'pane-registry'
import * as $rdf from 'rdflib'
import { solidLogicSingleton, store, authSession } from 'solid-logic'
import { getOutliner } from '../src'
import Pane from 'profile-pane'
import { formPane as Pane } from '../src/form/pane'
import './dev-mash.css'

function registerPaneModule (moduleOrPane: any) {
const pane = moduleOrPane?.default || moduleOrPane
paneRegistry.register(pane)
}

async function preloadFormOntologies () {
const ontologyDocs = [
'https://www.w3.org/ns/ui.ttl'
]

await Promise.all(
ontologyDocs.map(async uri => {
try {
await store.fetcher.load($rdf.sym(uri))
} catch (error) {
console.warn('Could not preload ontology:', uri, error)
}
})
)
}

// Add custom properties to the Window interface for TypeScript
declare global {
interface Window {
Expand All @@ -23,10 +44,22 @@ async function renderPane (uri: string) {
}
const subject = $rdf.sym(uri)
const doc = subject.doc()
const paneSubject = Pane.name === 'dataContents' ? doc : subject

const target = document.getElementById('render')

try {
await new Promise((resolve, reject) => {
store.fetcher.load(doc).then(resolve, reject)
})
} catch (error) {
console.error('Failed to load document for pane rendering', error)
if (target) {
target.innerHTML = `<pre>Failed to load ${doc.uri}\n${String(error)}</pre>`
}
return
}

await new Promise((resolve, reject) => {
store.fetcher.load(doc).then(resolve, reject)
})
const context = {
// see https://github.com/solidos/solid-panes/blob/005f90295d83e499fd626bd84aeb3df10135d5c1/src/index.ts#L30-L34
dom: document,
Expand All @@ -39,16 +72,21 @@ async function renderPane (uri: string) {
}

console.log(subject, context)
const icon = createIconElement(Pane)
const paneDiv = Pane.render(subject, context)

const target = document.getElementById('render')
if (target) {
target.innerHTML = ''
target.appendChild(icon)
target.appendChild(paneDiv)
} else {
console.error("Element with id 'render' not found.")
try {
const icon = createIconElement(Pane)
const paneDiv = Pane.render(paneSubject, context, {})
if (target) {
target.innerHTML = ''
target.appendChild(icon)
target.appendChild(paneDiv)
} else {
console.error("Element with id 'render' not found.")
}
} catch (error) {
console.error('Pane render failed', error)
if (target) {
target.innerHTML = `<pre>Pane render failed\n${String(error)}</pre>`
}
}
}

Expand All @@ -63,7 +101,9 @@ function createIconElement (Pane: { icon: string }) {
window.onload = async () => {
console.log('document ready')
// registerPanes((cjsOrEsModule: any) => paneRegistry.register(cjsOrEsModule.default || cjsOrEsModule))
paneRegistry.register(require('contacts-pane'))
registerPaneModule(Pane)
registerPaneModule(require('contacts-pane'))
await preloadFormOntologies()
await authSession.handleIncomingRedirect({
restorePreviousSession: true
})
Expand All @@ -82,7 +122,7 @@ window.onload = async () => {
loginBanner.innerHTML = `Logged in as ${session.info.webId} <button onclick="logout()">Log out</button>`;
}
}
renderPane('https://testingsolidos.solidcommunity.net/profile/card#me')
renderPane('https://sstratsianis.solidcommunity.net/formtest.ttl#this')
}
window.logout = () => {
authSession.logout()
Expand Down
6 changes: 6 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default {
'^.+\\.[tj]sx?$': ['babel-jest', { configFile: './babel.config.mjs' }],
},
transformIgnorePatterns: ['/node_modules/(?!lit-html).+\\.js'],
moduleNameMapper: {
'^SolidLogic$': 'solid-logic',
'^UI$': 'solid-ui',
'^\\$rdf$': 'rdflib',
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js'
},
setupFilesAfterEnv: ['./test/helpers/setup.ts'],
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
roots: ['<rootDir>/src', '<rootDir>/test'],
Expand Down
Loading