Skip to content

Commit 80393b2

Browse files
committed
Make sparqljs dependency internal
sparqlToBlockly now takes a string
1 parent 988bc09 commit 80393b2

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

demo/src/BlocklyCanvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class BlocklyCanvas extends HTMLElement {
5656
private workspaceChanged(e: Blockly.Events.Ui) {
5757
switch (e.type) {
5858
case Blockly.Events.CHANGE:
59-
case Blockly.Events.DELETE:
59+
case Blockly.Events.BLOCK_DELETE:
6060
case Blockly.Events.MOVE:
6161
if (!this.typing) this.generateCode()
6262
break

demo/src/SparqlEditor.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as SparqlJS from "sparqljs"
2-
import * as SparqlBlockly from "sparql-blockly"
1+
import * as SparqlBlockly from "sparql-blockly"
32

43
export class SparqlEditor extends HTMLElement {
54
private async connectedCallback() {
@@ -36,26 +35,24 @@ export class SparqlEditor extends HTMLElement {
3635
const query = this.validate()
3736

3837
if (query) {
39-
this.dispatchEvent(new CustomEvent<Element>("sparql", { detail: SparqlBlockly.sparqlToBlockly(query) }))
38+
this.dispatchEvent(new CustomEvent<Element>("sparql", { detail: query }))
4039
}
4140
}
4241

43-
private validate(): SparqlJS.SparqlQuery {
42+
private validate(): Element {
4443
this.error = ""
4544
this.classList.remove("invalid")
4645
this.classList.remove("valid")
4746

4847
const sparql = this.value
4948

5049
if (sparql) {
51-
const parser = new SparqlJS.Parser({ sparqlStar: true })
52-
5350
try {
54-
const query = parser.parse(sparql)
51+
const blocklyDom = SparqlBlockly.sparqlToBlockly(sparql)
5552

5653
this.classList.add("valid")
5754

58-
return query
55+
return blocklyDom
5956
}
6057
catch (e) {
6158
this.error = e.message

docs/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sparql-blockly",
3-
"version": "0.0.4-17",
3+
"version": "0.0.4-18",
44
"description": "A library for working with SPARQL in Blockly",
55
"main": "dist/index.js",
66
"license": "MIT",

package/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import CodeGenerator from "./CodeGenerator"
44
import * as SparqlJS from "sparqljs"
55
import * as Blockly from "blockly"
66

7-
export function sparqlToBlockly(sparql: SparqlJS.SparqlQuery): Element {
8-
return new BlockGenerator().visit(sparql)?.xml
7+
export function sparqlToBlockly(sparql: string): Element {
8+
const parser = new SparqlJS.Parser({ sparqlStar: true })
9+
const query = parser.parse(sparql)
10+
11+
return new BlockGenerator().visit(query)?.xml
912
}
1013

1114
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)