sparql-blockly 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -916,7 +916,6 @@ class BlockGenerator {
916
916
  return quads.reduce(process, new Set);
917
917
  }
918
918
  }
919
- exports.default = BlockGenerator;
920
919
  BlockGenerator.hierarchy = {
921
920
  unaryexpression: {
922
921
  operators: ["UMINUS", "!"],
@@ -947,6 +946,7 @@ BlockGenerator.hierarchy = {
947
946
  }
948
947
  }
949
948
  };
949
+ exports.default = BlockGenerator;
950
950
  function toCamel(value) {
951
951
  return value.charAt(0).toLowerCase() + value.substr(1);
952
952
  }
@@ -34,7 +34,7 @@ class CodeGenerator extends Blockly.Generator {
34
34
  const toWrappedGenerator = generatorName => block => this[generatorName](block);
35
35
  const addPropertyName = generatorName => [toPropertyName(generatorName), generatorName];
36
36
  const closeOverThis = ([propertyName, generatorName]) => [propertyName, toWrappedGenerator(generatorName)];
37
- const addToInstance = ([propertyName, generatorFunction]) => this[propertyName] = generatorFunction;
37
+ const addToInstance = ([propertyName, generatorFunction]) => this.forBlock[propertyName] = generatorFunction;
38
38
  // Generator functions on this class are the ones prefixed with 'sparql'.
39
39
  // Blockly expects them to be properties of the generator instance.
40
40
  // They need to be named exactly as the block type.
package/dist/aliases.js CHANGED
@@ -8,7 +8,7 @@ var RDF;
8
8
  RDF["nil"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
9
9
  RDF["first"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
10
10
  RDF["rest"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
11
- })(RDF = exports.RDF || (exports.RDF = {}));
11
+ })(RDF || (exports.RDF = RDF = {}));
12
12
  var XSD;
13
13
  (function (XSD) {
14
14
  XSD["string"] = "http://www.w3.org/2001/XMLSchema#string";
@@ -16,9 +16,9 @@ var XSD;
16
16
  XSD["decimal"] = "http://www.w3.org/2001/XMLSchema#decimal";
17
17
  XSD["double"] = "http://www.w3.org/2001/XMLSchema#double";
18
18
  XSD["boolean"] = "http://www.w3.org/2001/XMLSchema#boolean";
19
- })(XSD = exports.XSD || (exports.XSD = {}));
19
+ })(XSD || (exports.XSD = XSD = {}));
20
20
  var Order;
21
21
  (function (Order) {
22
22
  Order[Order["None"] = 0] = "None";
23
23
  Order[Order["Atomic"] = 1] = "Atomic";
24
- })(Order = exports.Order || (exports.Order = {}));
24
+ })(Order || (exports.Order = Order = {}));
@@ -1,32 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collection = exports.property = exports.workspace = exports.separator = exports.primaryPaths = exports.eltPaths = exports.eltOrInversePaths = exports.sequencePaths = exports.paths = exports.verbs = exports.functionExpressions = exports.constraints = exports.primaryExpressions = exports.unaryExpressions = exports.multiplicativeExpressions = exports.additiveExpressions = exports.relationalExpressions = exports.andExpressions = exports.expressions = exports.updateGraph = exports.updateGraphOrDefault = exports.updateGraphRefAll = exports.groupGraphPattern = exports.groupGraphPatternSubs = exports.iriRefs = exports.iris = exports.triplesNodes = exports.sameSubjectTriples = exports.terms = exports.graphNodes = exports.graphTerms = exports.varsOrIris = exports.vars = void 0;
3
+ exports.vars = vars;
4
+ exports.varsOrIris = varsOrIris;
5
+ exports.graphTerms = graphTerms;
6
+ exports.graphNodes = graphNodes;
7
+ exports.terms = terms;
8
+ exports.sameSubjectTriples = sameSubjectTriples;
9
+ exports.triplesNodes = triplesNodes;
10
+ exports.iris = iris;
11
+ exports.iriRefs = iriRefs;
12
+ exports.groupGraphPatternSubs = groupGraphPatternSubs;
13
+ exports.groupGraphPattern = groupGraphPattern;
14
+ exports.updateGraphRefAll = updateGraphRefAll;
15
+ exports.updateGraphOrDefault = updateGraphOrDefault;
16
+ exports.updateGraph = updateGraph;
17
+ exports.expressions = expressions;
18
+ exports.andExpressions = andExpressions;
19
+ exports.relationalExpressions = relationalExpressions;
20
+ exports.additiveExpressions = additiveExpressions;
21
+ exports.multiplicativeExpressions = multiplicativeExpressions;
22
+ exports.unaryExpressions = unaryExpressions;
23
+ exports.primaryExpressions = primaryExpressions;
24
+ exports.constraints = constraints;
25
+ exports.functionExpressions = functionExpressions;
26
+ exports.verbs = verbs;
27
+ exports.paths = paths;
28
+ exports.sequencePaths = sequencePaths;
29
+ exports.eltOrInversePaths = eltOrInversePaths;
30
+ exports.eltPaths = eltPaths;
31
+ exports.primaryPaths = primaryPaths;
32
+ exports.separator = separator;
33
+ exports.workspace = workspace;
34
+ exports.property = property;
35
+ exports.collection = collection;
4
36
  const Blockly = require("blockly");
5
37
  let separatorCounter = 0;
6
38
  function vars(parentBlockType, inputName, prefix) {
7
39
  property(parentBlockType, "sparql11_var1", inputName, "?s", prefix);
8
40
  property(parentBlockType, "sparql11_var2", inputName, "$s", prefix);
9
41
  }
10
- exports.vars = vars;
11
42
  function varsOrIris(parentBlockType, inputName, prefix) {
12
43
  vars(parentBlockType, inputName, prefix);
13
44
  iris(parentBlockType, inputName, prefix);
14
45
  }
15
- exports.varsOrIris = varsOrIris;
16
46
  function graphTerms(parentBlockType, inputName, prefix) {
17
47
  terms(parentBlockType, inputName, prefix);
18
48
  property(parentBlockType, "sparql11_anon", inputName, "[]", prefix);
19
49
  property(parentBlockType, "sparql11_blanknodelabel", inputName, "_:label", prefix);
20
50
  property(parentBlockType, "sparql11_nil", inputName, "()", prefix);
21
51
  }
22
- exports.graphTerms = graphTerms;
23
52
  function graphNodes(parentBlockType, inputName, prefix) {
24
53
  vars(parentBlockType, inputName, prefix);
25
54
  graphTerms(parentBlockType, inputName, prefix);
26
55
  triplesNodes(parentBlockType, inputName, prefix);
27
56
  property(parentBlockType, "sparql11_embtp", inputName, "<< >>", prefix);
28
57
  }
29
- exports.graphNodes = graphNodes;
30
58
  function terms(parentBlockType, inputName, prefix) {
31
59
  iris(parentBlockType, inputName, prefix);
32
60
  property(parentBlockType, "sparql11_typedliteral", inputName, "''^^<>", prefix);
@@ -35,17 +63,14 @@ function terms(parentBlockType, inputName, prefix) {
35
63
  property(parentBlockType, "sparql11_booleanliteral", inputName, "✓", prefix);
36
64
  property(parentBlockType, "sparql11_string", inputName, "''", prefix);
37
65
  }
38
- exports.terms = terms;
39
66
  function sameSubjectTriples(parentBlockType, inputName, prefix) {
40
67
  property(parentBlockType, "sparql11_triplessamesubject", inputName, "Triples same subject", prefix);
41
68
  triplesNodes(parentBlockType, inputName, prefix);
42
69
  }
43
- exports.sameSubjectTriples = sameSubjectTriples;
44
70
  function triplesNodes(parentBlockType, inputName, prefix) {
45
71
  property(parentBlockType, "sparql11_blanknodepropertylist", inputName, "Blank node property list", prefix);
46
72
  property(parentBlockType, "sparql11_collection", inputName, "Collection", prefix);
47
73
  }
48
- exports.triplesNodes = triplesNodes;
49
74
  function iris(parentBlockType, inputName, prefix) {
50
75
  iriRefs(parentBlockType, inputName, prefix);
51
76
  property(parentBlockType, "sparql11_prefixedname", inputName, ":", prefix);
@@ -53,12 +78,10 @@ function iris(parentBlockType, inputName, prefix) {
53
78
  property(parentBlockType, "sparql11_prefixednamelocalname", inputName, ":name", prefix);
54
79
  property(parentBlockType, "sparql11_prefixednameprefixlocalname", inputName, "prefix:name", prefix);
55
80
  }
56
- exports.iris = iris;
57
81
  function iriRefs(parentBlockType, inputName, prefix) {
58
82
  property(parentBlockType, "sparql11_iriref", inputName, "<iri>", prefix);
59
83
  property(parentBlockType, "sparql11_irirefdefault", inputName, "<>", prefix);
60
84
  }
61
- exports.iriRefs = iriRefs;
62
85
  function groupGraphPatternSubs(parentBlockType, inputName, prefix) {
63
86
  sameSubjectTriples(parentBlockType, inputName, prefix);
64
87
  property(parentBlockType, "sparql11_graphgraphpattern", inputName, "Graph", prefix);
@@ -70,68 +93,55 @@ function groupGraphPatternSubs(parentBlockType, inputName, prefix) {
70
93
  property(parentBlockType, "sparql11_optionalgraphpattern", inputName, "Optional", prefix);
71
94
  groupGraphPattern(parentBlockType, inputName, prefix);
72
95
  }
73
- exports.groupGraphPatternSubs = groupGraphPatternSubs;
74
96
  function groupGraphPattern(parentBlockType, inputName, prefix) {
75
97
  property(parentBlockType, "sparql11_groupgraphpattern", inputName, "{}", prefix);
76
98
  }
77
- exports.groupGraphPattern = groupGraphPattern;
78
99
  function updateGraphRefAll(parentBlockType, inputName, prefix) {
79
100
  updateGraphOrDefault(parentBlockType, inputName, prefix);
80
101
  property(parentBlockType, "sparql11_graphrefallnamed", inputName, "Named", prefix);
81
102
  property(parentBlockType, "sparql11_graphrefallall", inputName, "All", prefix);
82
103
  }
83
- exports.updateGraphRefAll = updateGraphRefAll;
84
104
  function updateGraphOrDefault(parentBlockType, inputName, prefix) {
85
105
  updateGraph(parentBlockType, inputName, prefix);
86
106
  property(parentBlockType, "sparql11_graphordefault", inputName, "Default", prefix);
87
107
  }
88
- exports.updateGraphOrDefault = updateGraphOrDefault;
89
108
  function updateGraph(parentBlockType, inputName, prefix) {
90
109
  property(parentBlockType, "sparql11_graphref", inputName, "Graph", prefix);
91
110
  }
92
- exports.updateGraph = updateGraph;
93
111
  function expressions(parentBlockType, inputName, prefix) {
94
112
  andExpressions(parentBlockType, inputName, prefix);
95
113
  property(parentBlockType, "sparql11_conditionalorexpression", inputName, "∨", prefix);
96
114
  }
97
- exports.expressions = expressions;
98
115
  function andExpressions(parentBlockType, inputName, prefix) {
99
116
  relationalExpressions(parentBlockType, inputName, prefix);
100
117
  property(parentBlockType, "sparql11_conditionalandexpression", inputName, "∧", prefix);
101
118
  }
102
- exports.andExpressions = andExpressions;
103
119
  function relationalExpressions(parentBlockType, inputName, prefix) {
104
120
  additiveExpressions(parentBlockType, inputName, prefix);
105
121
  property(parentBlockType, "sparql11_relationalexpression", inputName, "=≠<>≤≥", prefix);
106
122
  property(parentBlockType, "sparql11_relationalexpressionin", inputName, "in/not in", prefix);
107
123
  }
108
- exports.relationalExpressions = relationalExpressions;
109
124
  function additiveExpressions(parentBlockType, inputName, prefix) {
110
125
  multiplicativeExpressions(parentBlockType, inputName, prefix);
111
126
  property(parentBlockType, "sparql11_additiveexpression", inputName, "+−", prefix);
112
127
  }
113
- exports.additiveExpressions = additiveExpressions;
114
128
  function multiplicativeExpressions(parentBlockType, inputName, prefix) {
115
129
  unaryExpressions(parentBlockType, inputName, prefix);
116
130
  property(parentBlockType, "sparql11_multiplicativeexpression", inputName, "×÷", prefix);
117
131
  }
118
- exports.multiplicativeExpressions = multiplicativeExpressions;
119
132
  function unaryExpressions(parentBlockType, inputName, prefix) {
120
133
  primaryExpressions(parentBlockType, inputName, prefix);
121
134
  property(parentBlockType, "sparql11_unaryexpression", inputName, "¬+−", prefix);
122
135
  }
123
- exports.unaryExpressions = unaryExpressions;
124
136
  function primaryExpressions(parentBlockType, inputName, prefix) {
125
137
  vars(parentBlockType, inputName, prefix);
126
138
  terms(parentBlockType, inputName, prefix);
127
139
  constraints(parentBlockType, inputName, prefix);
128
140
  }
129
- exports.primaryExpressions = primaryExpressions;
130
141
  function constraints(parentBlockType, inputName, prefix) {
131
142
  functionExpressions(parentBlockType, inputName, prefix);
132
143
  property(parentBlockType, "sparql11_brackettedexpression", inputName, "()", prefix);
133
144
  }
134
- exports.constraints = constraints;
135
145
  function functionExpressions(parentBlockType, inputName, prefix) {
136
146
  property(parentBlockType, "sparql11_builtincall0", inputName, "𝛌0", prefix);
137
147
  property(parentBlockType, "sparql11_builtincall1", inputName, "𝛌1", prefix);
@@ -146,39 +156,32 @@ function functionExpressions(parentBlockType, inputName, prefix) {
146
156
  property(parentBlockType, "sparql11_count", inputName, "Count", prefix);
147
157
  property(parentBlockType, "sparql11_group_concat", inputName, "Group concatenation", prefix);
148
158
  }
149
- exports.functionExpressions = functionExpressions;
150
159
  function verbs(parentBlockType, inputName, prefix) {
151
160
  vars(parentBlockType, inputName, prefix);
152
161
  paths(parentBlockType, inputName, prefix);
153
162
  }
154
- exports.verbs = verbs;
155
163
  function paths(parentBlockType, inputName, prefix) {
156
164
  sequencePaths(parentBlockType, inputName, prefix);
157
165
  property(parentBlockType, "sparql11_pathalternative", inputName, "|", prefix);
158
166
  }
159
- exports.paths = paths;
160
167
  function sequencePaths(parentBlockType, inputName, prefix) {
161
168
  eltOrInversePaths(parentBlockType, inputName, prefix);
162
169
  property(parentBlockType, "sparql11_pathsequence", inputName, "/", prefix);
163
170
  }
164
- exports.sequencePaths = sequencePaths;
165
171
  function eltOrInversePaths(parentBlockType, inputName, prefix) {
166
172
  eltPaths(parentBlockType, inputName, prefix);
167
173
  property(parentBlockType, "sparql11_inversepath", inputName, "^", prefix);
168
174
  }
169
- exports.eltOrInversePaths = eltOrInversePaths;
170
175
  function eltPaths(parentBlockType, inputName, prefix) {
171
176
  primaryPaths(parentBlockType, inputName, prefix);
172
177
  property(parentBlockType, "sparql11_pathwithmodifier", inputName, "?*+", prefix);
173
178
  }
174
- exports.eltPaths = eltPaths;
175
179
  function primaryPaths(parentBlockType, inputName, prefix) {
176
180
  iris(parentBlockType, inputName, prefix);
177
181
  property(parentBlockType, "sparql11_a", inputName, "a", prefix);
178
182
  property(parentBlockType, "sparql11_negatedpath", inputName, "!", prefix);
179
183
  property(parentBlockType, "sparql11_bracketedpath", inputName, "()", prefix);
180
184
  }
181
- exports.primaryPaths = primaryPaths;
182
185
  function separator(parentBlockType) {
183
186
  const menuItem = {
184
187
  displayText: () => "==========",
@@ -191,7 +194,6 @@ function separator(parentBlockType) {
191
194
  };
192
195
  Blockly.ContextMenuRegistry.registry.register(menuItem);
193
196
  }
194
- exports.separator = separator;
195
197
  function workspace(displayText, newBlockType) {
196
198
  Blockly.ContextMenuRegistry.registry.register({
197
199
  displayText: () => displayText,
@@ -206,7 +208,6 @@ function workspace(displayText, newBlockType) {
206
208
  weight: 0,
207
209
  });
208
210
  }
209
- exports.workspace = workspace;
210
211
  function property(parentBlockType, newBlockType, inputName, displayText, prefix) {
211
212
  const callback = (scope) => {
212
213
  const block = scope.block.workspace.newBlock(newBlockType);
@@ -217,7 +218,6 @@ function property(parentBlockType, newBlockType, inputName, displayText, prefix)
217
218
  };
218
219
  block(parentBlockType, newBlockType, inputName, displayText, callback, prefix);
219
220
  }
220
- exports.property = property;
221
221
  function collection(parentBlockType, newBlockType, inputName, displayText, prefix) {
222
222
  const callback = (scope) => {
223
223
  const block = scope.block.workspace.newBlock(newBlockType);
@@ -233,7 +233,6 @@ function collection(parentBlockType, newBlockType, inputName, displayText, prefi
233
233
  };
234
234
  block(parentBlockType, newBlockType, inputName, displayText, callback, prefix);
235
235
  }
236
- exports.collection = collection;
237
236
  function block(parentBlockType, newBlockType, inputName, displayText, callback, prefix) {
238
237
  if (prefix) {
239
238
  displayText = `${prefix}: ${displayText}`;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const blockly_1 = require("blockly");
4
+ const field_multilineinput_1 = require("@blockly/field-multilineinput");
4
5
  // #region Prologue
5
6
  blockly_1.Blocks["sparql11_prologueitem"] = {
6
7
  init: function () {
@@ -1270,7 +1271,7 @@ blockly_1.Blocks["sparql11_var2"] = {
1270
1271
  blockly_1.Blocks["sparql11_numericliteral"] = {
1271
1272
  init: function () {
1272
1273
  const valueField = new blockly_1.FieldTextInput("");
1273
- valueField.setValidator(value => (isNaN(parseFloat(value)) || !isFinite(value)) ? null : value);
1274
+ valueField.setValidator(value => (isNaN(parseFloat(value)) || !isFinite(Number(value))) ? null : value);
1274
1275
  this.appendDummyInput()
1275
1276
  .appendField(valueField, "value");
1276
1277
  this.setInputsInline(true);
@@ -1290,7 +1291,7 @@ blockly_1.Blocks["sparql11_booleanliteral"] = {
1290
1291
  blockly_1.Blocks["sparql11_string"] = {
1291
1292
  init: function () {
1292
1293
  this.appendDummyInput()
1293
- .appendField(new blockly_1.FieldMultilineInput(""), "value");
1294
+ .appendField(new field_multilineinput_1.FieldMultilineInput(""), "value");
1294
1295
  this.setInputsInline(true);
1295
1296
  this.setOutput(true, ["EmbSubjectOrObject", "DataValueTerm", "VarOrTermOrEmbTP", "string", "RDFLiteral", "GraphNode", "VarOrTerm", "GraphTerm", "DataBlockValue", "Expression", "ConditionalOrExpression", "ConditionalAndExpression", "RelationalExpression", "AdditiveExpression", "MultiplicativeExpression", "UnaryExpression", "PrimaryExpression"]);
1296
1297
  this.setColour(163);
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blocklyToSparql = exports.sparqlToBlockly = void 0;
3
+ exports.sparqlToBlockly = sparqlToBlockly;
4
+ exports.blocklyToSparql = blocklyToSparql;
4
5
  require("./initialiseBlockly");
5
6
  const BlockGenerator_1 = require("./BlockGenerator");
6
7
  const CodeGenerator_1 = require("./CodeGenerator");
@@ -11,9 +12,7 @@ function sparqlToBlockly(sparql) {
11
12
  const query = parser.parse(sparql);
12
13
  return (_a = new BlockGenerator_1.default().visit(query)) === null || _a === void 0 ? void 0 : _a.xml;
13
14
  }
14
- exports.sparqlToBlockly = sparqlToBlockly;
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  function blocklyToSparql(block) {
17
17
  return new CodeGenerator_1.default().blockToCode(block);
18
18
  }
19
- exports.blocklyToSparql = blocklyToSparql;