55 ** in generated N3 syntax.
66 */
77
8- import * as UI from 'solid-ui'
9- import * as $rdf from 'rdflib'
10- import type { DataBrowserContext , RenderEnvironment } from 'pane-registry'
11- import type { NamedNode , Statement } from 'rdflib'
8+ import { ns , icons } from 'solid-ui'
9+ import type { DataBrowserContext } from 'pane-registry'
10+ import { Serializer , type NamedNode , type Statement } from 'rdflib'
1211import './RDFXMLPane.css'
13-
14- const ns = UI . ns
12+ import './components/editor-card/EditorCard'
1513
1614type RDFXMLPaneDefinition = {
1715 icon : string
@@ -21,32 +19,8 @@ type RDFXMLPaneDefinition = {
2119 render : ( subject : NamedNode , context : DataBrowserContext ) => HTMLDivElement
2220}
2321
24- function leadingIndentWidth ( line : string ) : number {
25- if ( line . trim ( ) . length === 0 ) {
26- return 0
27- }
28-
29- let width = 0
30- for ( const character of line ) {
31- if ( character === ' ' ) {
32- width += 1
33- continue
34- }
35- if ( character === '\t' ) {
36- width += 2
37- continue
38- }
39- break
40- }
41- return Math . max ( width , 2 )
42- }
43-
44- function trimLeadingIndent ( line : string ) : string {
45- return line . replace ( / ^ [ \t ] + / , '' )
46- }
47-
4822export const RDFXMLPane : RDFXMLPaneDefinition = {
49- icon : UI . icons . originalIconBase + '22-text-xml4.png' ,
23+ icon : icons . originalIconBase + '22-text-xml4.png' ,
5024
5125 name : 'RDFXML' ,
5226
@@ -74,60 +48,30 @@ export const RDFXMLPane: RDFXMLPaneDefinition = {
7448 const myDocument = context . dom
7549 const kb = context . session . store
7650
77- function applyEnvironmentAttributes ( element : HTMLDivElement ) : void {
78- const environment = ( context . environment ?? { } ) as Partial < RenderEnvironment >
79- element . dataset . layout = environment . layout ?? 'desktop'
80- }
81-
8251 const div = myDocument . createElement ( 'div' )
8352 div . setAttribute ( 'class' , 'rdfxml-pane' )
84- applyEnvironmentAttributes ( div )
8553 // Because of smushing etc, this will not be a copy of the original source
8654 // We could instead either fetch and re-parse the source,
8755 // or we could keep all the pre-smushed triples.
88- const sts = kb . statementsMatching (
56+ const statements = kb . statementsMatching (
8957 undefined ,
9058 undefined ,
9159 undefined ,
9260 subject
93- ) as Statement [ ] // @@ slow with current store!
94- /*
95- var kludge = kb.formula([]) // No features
96- for (var i=0; i< sts.length; i++) {
97- s = sts[i]
98- kludge.add(s.subject, s.predicate, s.object)
99- }
100- */
101- const sz = $rdf . Serializer ( kb )
61+ ) as Statement [ ]
62+
63+ const sz = Serializer ( kb )
10264 sz . suggestNamespaces ( kb . namespaces )
10365 sz . setBase ( subject . uri )
104- const str = sz . statementsToXML ( sts )
105- const source = myDocument . createElement ( 'div' )
106- source . classList . add ( 'rdfxml-pane__source' )
107-
108- str . split ( '\n' ) . forEach ( line => {
109- const lineElement = myDocument . createElement ( 'div' )
110- const indentElement = myDocument . createElement ( 'span' )
111- const contentElement = myDocument . createElement ( 'span' )
112- const indentWidth = leadingIndentWidth ( line )
113-
114- lineElement . classList . add ( 'rdfxml-pane__line' )
115- lineElement . style . setProperty ( '--rdfxml-indent' , `${ indentWidth } ch` )
116-
117- indentElement . classList . add ( 'rdfxml-pane__line-indent' )
118- indentElement . setAttribute ( 'aria-hidden' , 'true' )
119-
120- contentElement . classList . add ( 'rdfxml-pane__line-content' )
121- contentElement . textContent = line . length > 0 ? trimLeadingIndent ( line ) : ' '
122-
123- lineElement . appendChild ( indentElement )
124- lineElement . appendChild ( contentElement )
125- source . appendChild ( lineElement )
126- } )
66+ const serializedContent = sz . statementsToXML ( statements )
67+ const source = myDocument . createElement ( 'solid-panes-editor-card' ) as HTMLElement & {
68+ contentType ?: string
69+ content ?: string
70+ }
71+ source . contentType = 'application/rdf+xml'
72+ source . content = serializedContent
12773
12874 div . appendChild ( source )
12975 return div
13076 }
13177}
132-
133- // ends
0 commit comments