Skip to content

Commit e1ef824

Browse files
committed
implement PR suggestions
1 parent 6dc7294 commit e1ef824

5 files changed

Lines changed: 16 additions & 66 deletions

File tree

src/components/source-provider/SourceProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NamedNode } from 'rdflib'
55
import { DataBrowserContext } from 'pane-registry'
66
import { renderHeader } from '../../Header'
77
import { getStatusSection } from '../../StatusSection'
8-
import WebComponent from '../../primitives/WebComponent'
8+
import { WebComponent } from 'solid-ui'
99
import { sourceContext, SourceContext } from '../../primitives/context'
1010
import { SourcePaneState } from '../../types'
1111

src/components/sourceEditorCard/SourceEditorCard.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { NamedNode, parse, serialize } from 'rdflib'
66
import type { SourceEditor } from './SourceEditor'
77
import { applyResponseHeaders, checkSyntax, fetchContentAndMetadata, getResponseHeaders, happy } from '../../helpers'
88
import styles from './SourceEditorCard.styles.css'
9-
import WebComponent from '../../primitives/WebComponent'
9+
import { WebComponent } from 'solid-ui'
1010
import { getStatusSection } from '../../StatusSection'
1111
import { SourceContext } from '../../primitives/context'
1212
import { sourceContext } from '../../primitives/context'
@@ -26,9 +26,13 @@ export default class SourceEditorCard extends WebComponent {
2626
private _editorMount = createRef<HTMLDivElement>()
2727

2828
@consume({ context: sourceContext, subscribe: true })
29-
accessor sourceContext!: SourceContext
29+
accessor sourceContext: SourceContext = undefined as unknown as SourceContext
30+
31+
private _requireSourceContext () {
32+
if (!this.sourceContext) {
33+
throw new Error('The element is missing the required `sourceContext` property.')
34+
}
3035

31-
private _getSourceContext () {
3236
return this.sourceContext
3337
}
3438

@@ -74,7 +78,7 @@ export default class SourceEditorCard extends WebComponent {
7478
private async _initializeEditor () {
7579
if (this._editor) return
7680
const sourcePaneEditor = this._editorMount.value
77-
const sourceContext = this._getSourceContext()
81+
const sourceContext = this.sourceContext
7882
if (!sourcePaneEditor || !sourceContext) {
7983
return
8084
}
@@ -120,8 +124,7 @@ export default class SourceEditorCard extends WebComponent {
120124
}
121125

122126
private saveBack = async () => {
123-
const sourceContext = this.sourceContext
124-
if (!sourceContext) return
127+
const sourceContext = this._requireSourceContext()
125128

126129
const store = sourceContext.context.session.store
127130
const subject = new NamedNode(sourceContext.subject)
@@ -156,8 +159,7 @@ export default class SourceEditorCard extends WebComponent {
156159
}
157160

158161
private prettyHandler = () => {
159-
const sourceContext = this.sourceContext
160-
if (!sourceContext) return
162+
const sourceContext = this._requireSourceContext()
161163

162164
const { contentType } = sourceContext.sourcePaneState
163165
const compactContentType = contentType?.split(';')[0]
@@ -181,16 +183,17 @@ export default class SourceEditorCard extends WebComponent {
181183
}
182184

183185
render() {
186+
const sourceContext = this._requireSourceContext()
184187
const sectionClass = this._editorReady ? 'sourcePaneCard' : 'sourcePaneCard sourcePaneCardLoading'
185-
const compactContentType = this.sourceContext?.sourcePaneState.contentType?.split(';')[0]
188+
const compactContentType = sourceContext.sourcePaneState.contentType?.split(';')[0]
186189
const showPrettyButton = !this._editingState && !!compactContentType && compactable[compactContentType]
187190
const prettyButton = showPrettyButton
188191
? html`
189192
<solid-ui-button class="sourcePanePrettyButton" variant="secondary" @click=${this.prettyHandler}>Prettify</solid-ui-button>
190193
`
191194
: html``
192195

193-
return this._getSourceContext() ? html`
196+
return html`
194197
<section class=${sectionClass}>
195198
<div class="sourcePaneEditor" ${ref(this._editorMount)}></div>
196199
<div class="sourcePaneEditorFooter">
@@ -202,6 +205,6 @@ export default class SourceEditorCard extends WebComponent {
202205
: prettyButton}
203206
</div>
204207
</section>
205-
` : html``
208+
`
206209
}
207210
}

src/helpers.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ const parseable: Record<string, boolean> = {
1010
'application/rdf+xml': true,
1111
'application/xhtml+xml': true, // For RDFa?
1212
'text/html': true, // For data island
13-
// 'application/sparql-update': true,
1413
'application/json': true,
1514
'application/ld+json': true
16-
// 'application/nquads' : true,
17-
// 'application/n-quads' : true
1815
}
1916

2017
export function happy (response: Response, method: string) {
@@ -141,7 +138,6 @@ export function applyResponseHeaders (sourcePaneState: SourcePaneState, metadata
141138
sourcePaneState.eTag = metadata.eTag
142139
}
143140

144-
// get response headers
145141
export function getResponseHeaders (store: LiveStore, subject: NamedNode, response: Response): HttpResourceMetadata {
146142
let contentType: string | undefined
147143
let allowed: string | undefined

src/primitives/WebComponent.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* Basic Options */
44
"target": "ES2019" /* Specify ECMAScript target version - matches your browser support */,
55
"module": "ESNext" /* Let bundlers handle module transformation for better tree-shaking */,
6-
"moduleResolution": "node", /* Use bundler-aware module resolution for modern Webpack builds. */
6+
"moduleResolution": "bundler", /* Use bundler-aware module resolution for modern Webpack builds. */
77
/* Crucial for library compatibility: */
88
"skipLibCheck": true, // Skip type checking of declaration files for faster builds
99
"allowSyntheticDefaultImports": true, // Often helps with ESM interop
@@ -56,11 +56,6 @@
5656
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
5757
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
5858
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
59-
// "typeRoots": [], /* List of folders to include type definitions from. */
60-
"typeRoots": [
61-
"node_modules/@types",
62-
"declarations.d.ts"
63-
] /* List of folders to include type definitions from. */,
6459
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
6560
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
6661
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

0 commit comments

Comments
 (0)