Skip to content

Commit

Permalink
Make sparqljs dependency internal
Browse files Browse the repository at this point in the history
sparqlToBlockly now takes a string
  • Loading branch information
langsamu committed Apr 11, 2021
1 parent 988bc09 commit 80393b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion demo/src/BlocklyCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class BlocklyCanvas extends HTMLElement {
private workspaceChanged(e: Blockly.Events.Ui) {
switch (e.type) {
case Blockly.Events.CHANGE:
case Blockly.Events.DELETE:
case Blockly.Events.BLOCK_DELETE:
case Blockly.Events.MOVE:
if (!this.typing) this.generateCode()
break
Expand Down
13 changes: 5 additions & 8 deletions demo/src/SparqlEditor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as SparqlJS from "sparqljs"
import * as SparqlBlockly from "sparql-blockly"
import * as SparqlBlockly from "sparql-blockly"

export class SparqlEditor extends HTMLElement {
private async connectedCallback() {
Expand Down Expand Up @@ -36,26 +35,24 @@ export class SparqlEditor extends HTMLElement {
const query = this.validate()

if (query) {
this.dispatchEvent(new CustomEvent<Element>("sparql", { detail: SparqlBlockly.sparqlToBlockly(query) }))
this.dispatchEvent(new CustomEvent<Element>("sparql", { detail: query }))
}
}

private validate(): SparqlJS.SparqlQuery {
private validate(): Element {
this.error = ""
this.classList.remove("invalid")
this.classList.remove("valid")

const sparql = this.value

if (sparql) {
const parser = new SparqlJS.Parser({ sparqlStar: true })

try {
const query = parser.parse(sparql)
const blocklyDom = SparqlBlockly.sparqlToBlockly(sparql)

this.classList.add("valid")

return query
return blocklyDom
}
catch (e) {
this.error = e.message
Expand Down
2 changes: 1 addition & 1 deletion docs/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparql-blockly",
"version": "0.0.4-17",
"version": "0.0.4-18",
"description": "A library for working with SPARQL in Blockly",
"main": "dist/index.js",
"license": "MIT",
Expand Down
7 changes: 5 additions & 2 deletions package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import CodeGenerator from "./CodeGenerator"
import * as SparqlJS from "sparqljs"
import * as Blockly from "blockly"

export function sparqlToBlockly(sparql: SparqlJS.SparqlQuery): Element {
return new BlockGenerator().visit(sparql)?.xml
export function sparqlToBlockly(sparql: string): Element {
const parser = new SparqlJS.Parser({ sparqlStar: true })
const query = parser.parse(sparql)

return new BlockGenerator().visit(query)?.xml
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 80393b2

Please sign in to comment.