@matdata/yasqe 4.6.1
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.
- package/CHANGELOG.md +121 -0
- package/build/ts/grammar/tokenizer.d.ts +37 -0
- package/build/ts/src/CodeMirror.d.ts +21 -0
- package/build/ts/src/autocompleters/classes.d.ts +3 -0
- package/build/ts/src/autocompleters/index.d.ts +39 -0
- package/build/ts/src/autocompleters/prefixes.d.ts +3 -0
- package/build/ts/src/autocompleters/properties.d.ts +3 -0
- package/build/ts/src/autocompleters/variables.d.ts +3 -0
- package/build/ts/src/defaults.d.ts +75 -0
- package/build/ts/src/imgs.d.ts +7 -0
- package/build/ts/src/index.d.ts +303 -0
- package/build/ts/src/prefixFold.d.ts +8 -0
- package/build/ts/src/prefixUtils.d.ts +9 -0
- package/build/ts/src/sparql.d.ts +20 -0
- package/build/ts/src/tokenUtils.d.ts +4 -0
- package/build/ts/src/tooltip.d.ts +2 -0
- package/build/ts/src/trie.d.ts +13 -0
- package/build/yasqe.html +108 -0
- package/build/yasqe.min.css +2 -0
- package/build/yasqe.min.css.map +1 -0
- package/build/yasqe.min.js +3 -0
- package/build/yasqe.min.js.LICENSE.txt +3 -0
- package/build/yasqe.min.js.map +1 -0
- package/grammar/README.md +12 -0
- package/grammar/_tokenizer-table.js +4776 -0
- package/grammar/build.sh +2 -0
- package/grammar/sparql11-grammar.pl +834 -0
- package/grammar/sparqljs-browser-min.js +4535 -0
- package/grammar/tokenizer.ts +729 -0
- package/grammar/util/gen_ll1.pl +37 -0
- package/grammar/util/gen_sparql11.pl +11 -0
- package/grammar/util/ll1.pl +175 -0
- package/grammar/util/output_to_javascript.pl +75 -0
- package/grammar/util/prune.pl +49 -0
- package/grammar/util/rewrite.pl +104 -0
- package/package.json +40 -0
- package/src/CodeMirror.ts +54 -0
- package/src/autocompleters/classes.ts +32 -0
- package/src/autocompleters/index.ts +346 -0
- package/src/autocompleters/prefixes.ts +130 -0
- package/src/autocompleters/properties.ts +28 -0
- package/src/autocompleters/show-hint.scss +38 -0
- package/src/autocompleters/variables.ts +52 -0
- package/src/defaults.ts +149 -0
- package/src/imgs.ts +14 -0
- package/src/index.ts +1089 -0
- package/src/prefixFold.ts +93 -0
- package/src/prefixUtils.ts +65 -0
- package/src/scss/buttons.scss +275 -0
- package/src/scss/codemirrorMods.scss +36 -0
- package/src/scss/yasqe.scss +89 -0
- package/src/sparql.ts +215 -0
- package/src/tokenUtils.ts +121 -0
- package/src/tooltip.ts +31 -0
- package/src/trie.ts +238 -0
package/src/defaults.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default options of YASQE (check the CodeMirror documentation for even
|
|
3
|
+
* more options, such as disabling line numbers, or changing keyboard shortcut
|
|
4
|
+
* keys). Either change the default options by setting Yasqe.defaults, or by
|
|
5
|
+
* passing your own options as second argument to the YASQE constructor
|
|
6
|
+
*/
|
|
7
|
+
import { default as Yasqe, Config, PlainRequestConfig } from "./";
|
|
8
|
+
import * as queryString from "query-string";
|
|
9
|
+
//need to pass Yasqe object as argument, as the imported version might not have inherited all (e.g. `fold`) props of Codemirror yet
|
|
10
|
+
export default function get() {
|
|
11
|
+
const prefixCcApi = "https://prefix.cc/popular/all.file.json";
|
|
12
|
+
const CodeMirror = require("codemirror");
|
|
13
|
+
const config: Omit<Config, "requestConfig"> = {
|
|
14
|
+
mode: "sparql11",
|
|
15
|
+
value: `PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
16
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
17
|
+
SELECT * WHERE {
|
|
18
|
+
?sub ?pred ?obj .
|
|
19
|
+
} LIMIT 10`,
|
|
20
|
+
highlightSelectionMatches: {
|
|
21
|
+
showToken: /\w/,
|
|
22
|
+
},
|
|
23
|
+
tabMode: "indent",
|
|
24
|
+
lineNumbers: true,
|
|
25
|
+
lineWrapping: true,
|
|
26
|
+
foldGutter: {
|
|
27
|
+
rangeFinder: new (<any>CodeMirror).fold.combine((<any>CodeMirror).fold.brace, (<any>CodeMirror).fold.prefix),
|
|
28
|
+
},
|
|
29
|
+
collapsePrefixesOnLoad: false,
|
|
30
|
+
gutters: ["gutterErrorBar", "CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
|
31
|
+
matchBrackets: true,
|
|
32
|
+
fixedGutter: true,
|
|
33
|
+
syntaxErrorCheck: true,
|
|
34
|
+
autocompleters: [],
|
|
35
|
+
extraKeys: {
|
|
36
|
+
/**
|
|
37
|
+
* Need to use _yasqe:any as function parameter here. Otherwise ts will complain that we're not following
|
|
38
|
+
* the codemirror config interface (that specifies the type should be codemirror-editor)
|
|
39
|
+
*/
|
|
40
|
+
"Ctrl-Space": function (_yasqe: any) {
|
|
41
|
+
const yasqe: Yasqe = _yasqe;
|
|
42
|
+
yasqe.autocomplete();
|
|
43
|
+
},
|
|
44
|
+
"Shift-Ctrl-K": function (_yasqe: any) {
|
|
45
|
+
const yasqe: Yasqe = _yasqe;
|
|
46
|
+
const lineNumber = yasqe.getDoc().getCursor().line;
|
|
47
|
+
if (lineNumber === yasqe.getDoc().lastLine() && lineNumber > 1) {
|
|
48
|
+
//delete current line, and the linebreak just before
|
|
49
|
+
return yasqe
|
|
50
|
+
.getDoc()
|
|
51
|
+
.replaceRange(
|
|
52
|
+
"",
|
|
53
|
+
{ ch: yasqe.getDoc().getLine(lineNumber - 1).length, line: lineNumber - 1 },
|
|
54
|
+
{ ch: yasqe.getDoc().getLine(lineNumber).length, line: lineNumber },
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
//delete current line including the linebreak after
|
|
58
|
+
return yasqe.getDoc().replaceRange("", { ch: 0, line: lineNumber }, { ch: 0, line: lineNumber + 1 });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"Ctrl-/": function (_yasqe: any) {
|
|
62
|
+
const yasqe: Yasqe = _yasqe;
|
|
63
|
+
yasqe.commentLines();
|
|
64
|
+
},
|
|
65
|
+
"Shift-Ctrl-D": function (_yasqe: any) {
|
|
66
|
+
const yasqe: Yasqe = _yasqe;
|
|
67
|
+
yasqe.duplicateLine();
|
|
68
|
+
},
|
|
69
|
+
"Shift-Ctrl-F": function (_yasqe: any) {
|
|
70
|
+
const yasqe: Yasqe = _yasqe;
|
|
71
|
+
yasqe.autoformat();
|
|
72
|
+
},
|
|
73
|
+
"Ctrl-S": function (_yasqe: any) {
|
|
74
|
+
const yasqe: Yasqe = _yasqe;
|
|
75
|
+
yasqe.saveQuery();
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
"Cmd-Enter": function (_yasqe: any) {
|
|
79
|
+
const yasqe: Yasqe = _yasqe;
|
|
80
|
+
yasqe.query().catch(() => {}); //catch this to avoid unhandled rejection
|
|
81
|
+
},
|
|
82
|
+
"Ctrl-Enter": function (_yasqe: any) {
|
|
83
|
+
const yasqe: Yasqe = _yasqe;
|
|
84
|
+
yasqe.query().catch(() => {}); //catch this to avoid unhandled rejection
|
|
85
|
+
},
|
|
86
|
+
Esc: function (_yasqe: any) {
|
|
87
|
+
const yasqe: Yasqe = _yasqe;
|
|
88
|
+
yasqe.getInputField().blur();
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
createShareableLink: function (yasqe: Yasqe) {
|
|
93
|
+
return (
|
|
94
|
+
document.location.protocol +
|
|
95
|
+
"//" +
|
|
96
|
+
document.location.host +
|
|
97
|
+
document.location.pathname +
|
|
98
|
+
document.location.search +
|
|
99
|
+
"#" +
|
|
100
|
+
queryString.stringify(yasqe.configToQueryParams())
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
pluginButtons: undefined,
|
|
104
|
+
|
|
105
|
+
createShortLink: undefined,
|
|
106
|
+
|
|
107
|
+
consumeShareLink: function (yasqe: Yasqe) {
|
|
108
|
+
yasqe.queryParamsToConfig(yasqe.getUrlParams());
|
|
109
|
+
},
|
|
110
|
+
persistenceId: function (yasqe: Yasqe) {
|
|
111
|
+
//Traverse parents untl we've got an id
|
|
112
|
+
// Get matching parent elements
|
|
113
|
+
let id = "";
|
|
114
|
+
let elem: any = yasqe.rootEl;
|
|
115
|
+
if ((<any>elem).id) id = (<any>elem).id;
|
|
116
|
+
for (; elem && elem !== <any>document; elem = elem.parentNode) {
|
|
117
|
+
if (elem) {
|
|
118
|
+
if ((<any>elem).id) id = (<any>elem).id;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return "yasqe_" + id + "_query";
|
|
123
|
+
},
|
|
124
|
+
persistencyExpire: 60 * 60 * 24 * 30,
|
|
125
|
+
|
|
126
|
+
showQueryButton: true,
|
|
127
|
+
|
|
128
|
+
hintConfig: {},
|
|
129
|
+
resizeable: true,
|
|
130
|
+
editorHeight: "300px",
|
|
131
|
+
queryingDisabled: undefined,
|
|
132
|
+
prefixCcApi: prefixCcApi,
|
|
133
|
+
};
|
|
134
|
+
const requestConfig: PlainRequestConfig = {
|
|
135
|
+
queryArgument: undefined, //undefined means: get query argument based on query mode
|
|
136
|
+
endpoint: "https://dbpedia.org/sparql",
|
|
137
|
+
method: "POST",
|
|
138
|
+
acceptHeaderGraph: "application/n-triples,*/*;q=0.9",
|
|
139
|
+
acceptHeaderSelect: "application/sparql-results+json,*/*;q=0.9",
|
|
140
|
+
acceptHeaderUpdate: "text/plain,*/*;q=0.9",
|
|
141
|
+
namedGraphs: [],
|
|
142
|
+
defaultGraphs: [],
|
|
143
|
+
args: [],
|
|
144
|
+
headers: {},
|
|
145
|
+
withCredentials: false,
|
|
146
|
+
adjustQueryBeforeRequest: false,
|
|
147
|
+
};
|
|
148
|
+
return { ...config, requestConfig };
|
|
149
|
+
}
|
package/src/imgs.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var query =
|
|
2
|
+
'<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" height="81.9" width="72.9" version="1.1" y="0px" x="0px" viewBox="0 0 72.900002 81.900002"><path id="queryIcon" d="m69.6 35.2-60.3-34.3c-2.2-1.2-4.4-1.2-6.4 0s-2.9 3.4-2.9 5.6v68.8c0 2.2 1.2 4.4 2.9 5.6 1 0.5 2.2 1 3.4 1s2.2-0.5 2.9-1l60.3-34.3c2.2-1.2 3.4-3.4 3.4-5.6s-1.1-4.3-3.3-5.8z"/><path id="loadingIcon" d="m61.184 36.167-48.73-27.719c-1.7779-0.96976-3.5558-0.96976-5.172 0-1.6163 0.96976-2.3436 2.7476-2.3436 4.5255v55.599c0 1.7779 0.96976 3.5558 2.3436 4.5255 0.80813 0.40407 1.7779 0.80813 2.7476 0.80813 0.96975 0 1.7779-0.40406 2.3436-0.80813l48.73-27.719c1.7779-0.96976 2.7476-2.7476 2.7476-4.5255s-0.88894-3.475-2.6668-4.6872z" fill="none"/></svg>';
|
|
3
|
+
export var queryInvalid =
|
|
4
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 73.627 73.897"><path d="M61.627 0H12C5.373 0 0 5.373 0 12v49.897c0 6.627 5.373 12 12 12h49.627c6.627 0 12-5.373 12-12V12c0-6.628-5.373-12-12-12zM21.13 61.495V12.682l36.875 24.075L21.13 61.495z"/><path d="M66.13 65.904H49.77c-1.647 0-2.89-.58-3.5-1.636-.608-1.056-.49-2.422.334-3.848l8.18-14.167c.822-1.427 1.947-2.212 3.165-2.212s2.342.786 3.165 2.213l8.18 14.167c.824 1.426.942 2.792.333 3.848-.61 1.055-1.852 1.636-3.5 1.636zm-6.51-4.986c0-.85-.69-1.54-1.54-1.54-.85 0-1.54.69-1.54 1.54 0 .85.69 1.54 1.54 1.54.85 0 1.54-.69 1.54-1.54zm.04-9.266c0-.873-.708-1.58-1.58-1.58-.874 0-1.582.707-1.582 1.58l.374 5.61h.005c.054.62.568 1.108 1.202 1.108.586 0 1.075-.415 1.188-.968.01-.045.01-.093.014-.14h.01l.368-5.61z" fill="#a80"/></svg>';
|
|
5
|
+
export var download =
|
|
6
|
+
'<svg xmlns="http://www.w3.org/2000/svg" baseProfile="tiny" viewBox="0 0 100 100"><path fill-rule="evenodd" d="M88 84v-2c0-2.96-.86-4-4-4H16c-2.96 0-4 .98-4 4v2c0 3.102 1.04 4 4 4h68c3.02 0 4-.96 4-4zM58 12H42c-5 0-6 .94-6 6v22H16l34 34 34-34H64V18c0-5.06-1.06-6-6-6z"/></svg>';
|
|
7
|
+
export var share =
|
|
8
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M36.764 50c0 .308-.07.598-.088.905l32.247 16.12c2.76-2.34 6.293-3.798 10.195-3.798C87.89 63.227 95 70.337 95 79.11 95 87.89 87.89 95 79.118 95c-8.78 0-15.882-7.11-15.882-15.89 0-.317.07-.6.088-.906l-32.247-16.12c-2.77 2.33-6.293 3.79-10.195 3.79C12.11 65.873 5 58.77 5 50c0-8.78 7.11-15.89 15.882-15.89 3.902 0 7.427 1.467 10.195 3.796l32.247-16.12c-.018-.307-.088-.597-.088-.913C63.236 12.11 70.338 5 79.118 5 87.89 5 95 12.11 95 20.873c0 8.78-7.11 15.89-15.882 15.89-3.91 0-7.436-1.467-10.195-3.805L36.676 49.086c.017.308.088.598.088.914z"/></svg>';
|
|
9
|
+
export var warning =
|
|
10
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 66.399998 66.399998"><g><path d="M33.2 0C14.9 0 0 14.9 0 33.2c0 18.3 14.9 33.2 33.2 33.2 18.3 0 33.2-14.9 33.2-33.2C66.4 14.9 51.5 0 33.2 0zm0 59.4C18.7 59.4 7 47.6 7 33.2 7 18.7 18.8 7 33.2 7c14.4 0 26.2 11.8 26.2 26.2 0 14.4-11.8 26.2-26.2 26.2z"/><path d="M33.1 45.6c-1.4 0-2.5.5-3.5 1.5-.9 1-1.4 2.2-1.4 3.6 0 1.6.5 2.8 1.5 3.8 1 .9 2.1 1.3 3.4 1.3 1.3 0 2.4-.5 3.4-1.4 1-.9 1.5-2.2 1.5-3.7 0-1.4-.5-2.6-1.4-3.6-.9-1-2.1-1.5-3.5-1.5zM33.3 12.4c-1.5 0-2.8.5-3.7 1.6-.9 1-1.4 2.4-1.4 4.2 0 1.1.1 2.9.2 5.6l.8 13.1c.2 1.8.4 3.2.9 4.1.5 1.2 1.5 1.8 2.9 1.8 1.3 0 2.3-.7 2.9-1.9.5-1 .7-2.3.9-4l1.1-13.4c.1-1.3.2-2.5.2-3.8 0-2.2-.3-3.9-.8-5.1-.5-1-1.6-2.2-4-2.2z"/></g></svg>';
|
|
11
|
+
export var fullscreen =
|
|
12
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>';
|
|
13
|
+
export var fullscreenExit =
|
|
14
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"/></svg>';
|