0.2.1 • Published 1 year ago

@rdfjs-elements/sparql-editor v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

sparql-editor

A text editor custom element which highlights and parses SPARQL queries.

It uses sparqljs to parse the query text.

Usage

Simply add the element to a page. It is possible to provide common prefixes and a base IRI so that they don't have to be explicitly added in the SPARQL string

import '@rdfjs-elements/sparql-editor'
import { html } from 'lit'

const value = `CONSTRUCT { ?s ?p ?o }
FROM <john-doe>
WHERE {
  <john-doe> a schema:Person ;
  schema:name "John Doe" .
}`

const template = html`<rdf-editor prefixes="schema" baseIRI="http://example.com/" .value="${value}"></rdf-editor>`

Properties

PropertyAttributeModifiersTypeDefaultDescription
autoParseauto-parsebooleanif set to true, parses the contents automatically when typing. Otherwise, parses on blur event
baseIRIbase-iristringValue of the BASE directive which will be injected to the query
codeMirrorreadonlyElement \| nullThe underlying <wc-codemirror> element
customPrefixescustomPrefixesRecord<string, string>{}a map of custom prefixes or overrides
formatreadonlystring
isParsingis-parsingbooleanset to true while the elements parses data when the code has changed
parseDelayparseDelayNumber250time in milliseconds after which parsing will begin while typing. Only applies when autoParse is set
prefixesprefixesstringa comma-separated list of prefixes to use for serializing. Any prefix included in the @zazuko/vocabularies package can be used
queryobjectThe JS object representing the query
readonlyreadonlyboolean
readyreadyPromise<void>a one-time promise which resolves when CodeMirror has been initialized
valuevaluestringThe raw contents of the code editor

Methods

MethodType
parse(): Promise<void>

Events

EventTypeDescription
parsedCustomEvent<{ value: string; query: object }>when the editor contents have changed and have been successfully parsed
parsing-failedCustomEventwhen there as in an error in parsing the query

CSS Shadow Parts

PartDescription
CodeMirrorThe main CodeMirror wrapper element. This and other parts are directly generated from CSS classes set by CodeMirror and should be fairly self-explanatory but not equally useful 😉
CodeMirror-code
CodeMirror-cursors
CodeMirror-gutter-filler
CodeMirror-gutters
CodeMirror-hscrollbar
CodeMirror-linenumbers
CodeMirror-lines
CodeMirror-measure
CodeMirror-scroll
CodeMirror-scrollbar-filler
CodeMirror-sizer
CodeMirror-vscrollbar
errorLine or part of line highlighted as result of parsing error. By default style is red wavy underline
0.2.1

1 year ago

0.2.0

2 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago