@matdata/yasqe 5.20.3 → 6.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +76 -59
  3. package/build/prefixes.json +2190 -2136
  4. package/build/ts/grammar/tokenizer.d.ts +9 -3
  5. package/build/ts/grammar/tokenizer.js +34 -6
  6. package/build/ts/grammar/tokenizer.js.map +1 -1
  7. package/build/ts/src/autocompleters/index.d.ts +4 -2
  8. package/build/ts/src/autocompleters/index.js +9 -33
  9. package/build/ts/src/autocompleters/index.js.map +1 -1
  10. package/build/ts/src/autocompleters/variables.js +17 -19
  11. package/build/ts/src/autocompleters/variables.js.map +1 -1
  12. package/build/ts/src/defaults.d.ts +17 -53
  13. package/build/ts/src/defaults.js +2 -5
  14. package/build/ts/src/defaults.js.map +1 -1
  15. package/build/ts/src/editor/autocompletion.d.ts +32 -0
  16. package/build/ts/src/editor/autocompletion.js +94 -0
  17. package/build/ts/src/editor/autocompletion.js.map +1 -0
  18. package/build/ts/src/editor/doc.d.ts +32 -0
  19. package/build/ts/src/editor/doc.js +121 -0
  20. package/build/ts/src/editor/doc.js.map +1 -0
  21. package/build/ts/src/editor/facade.d.ts +94 -0
  22. package/build/ts/src/editor/facade.js +392 -0
  23. package/build/ts/src/editor/facade.js.map +1 -0
  24. package/build/ts/src/editor/folding.d.ts +16 -0
  25. package/build/ts/src/editor/folding.js +190 -0
  26. package/build/ts/src/editor/folding.js.map +1 -0
  27. package/build/ts/src/editor/gutters.d.ts +8 -0
  28. package/build/ts/src/editor/gutters.js +113 -0
  29. package/build/ts/src/editor/gutters.js.map +1 -0
  30. package/build/ts/src/editor/keymap.d.ts +11 -0
  31. package/build/ts/src/editor/keymap.js +88 -0
  32. package/build/ts/src/editor/keymap.js.map +1 -0
  33. package/build/ts/src/editor/language.d.ts +11 -0
  34. package/build/ts/src/editor/language.js +19 -0
  35. package/build/ts/src/editor/language.js.map +1 -0
  36. package/build/ts/src/editor/tokenizerRunner.d.ts +37 -0
  37. package/build/ts/src/editor/tokenizerRunner.js +115 -0
  38. package/build/ts/src/editor/tokenizerRunner.js.map +1 -0
  39. package/build/ts/src/index.d.ts +49 -100
  40. package/build/ts/src/index.js +179 -100
  41. package/build/ts/src/index.js.map +1 -1
  42. package/build/ts/src/prefixes.json +2191 -2137
  43. package/build/ts/src/tooltip.js +9 -6
  44. package/build/ts/src/tooltip.js.map +1 -1
  45. package/build/yasqe.min.css +1 -1
  46. package/build/yasqe.min.css.map +3 -3
  47. package/build/yasqe.min.js +76 -91
  48. package/build/yasqe.min.js.map +4 -4
  49. package/grammar/tokenizer.ts +62 -8
  50. package/package.json +11 -6
  51. package/src/autocompleters/index.ts +24 -53
  52. package/src/autocompleters/show-hint.scss +17 -9
  53. package/src/autocompleters/variables.ts +20 -24
  54. package/src/defaults.ts +2 -6
  55. package/src/editor/autocompletion.ts +147 -0
  56. package/src/editor/doc.ts +151 -0
  57. package/src/editor/facade.ts +558 -0
  58. package/src/editor/folding.ts +225 -0
  59. package/src/editor/gutters.ts +152 -0
  60. package/src/editor/keymap.ts +133 -0
  61. package/src/editor/language.ts +47 -0
  62. package/src/editor/tokenizerRunner.ts +198 -0
  63. package/src/index.ts +193 -127
  64. package/src/prefixes.json +2190 -2136
  65. package/src/scss/buttons.scss +4 -2
  66. package/src/scss/codemirrorMods.scss +107 -11
  67. package/src/scss/yasqe.scss +4 -2
  68. package/src/tooltip.ts +16 -13
  69. package/build/ts/src/CodeMirror.d.ts +0 -30
  70. package/build/ts/src/CodeMirror.js +0 -20
  71. package/build/ts/src/CodeMirror.js.map +0 -1
  72. package/build/ts/src/prefixFold.d.ts +0 -8
  73. package/build/ts/src/prefixFold.js +0 -87
  74. package/build/ts/src/prefixFold.js.map +0 -1
  75. package/src/CodeMirror.ts +0 -54
  76. package/src/prefixFold.ts +0 -94
@@ -597,7 +597,8 @@
597
597
  margin: 0;
598
598
  padding-top: 100px;
599
599
 
600
- .CodeMirror-wrap {
600
+ .CodeMirror-wrap,
601
+ .cm-editor {
601
602
  padding-top: 10px;
602
603
  }
603
604
 
@@ -617,7 +618,8 @@
617
618
  }
618
619
  }
619
620
 
620
- .CodeMirror {
621
+ .CodeMirror,
622
+ .cm-editor {
621
623
  height: calc(100vh - 150px) !important;
622
624
  }
623
625
  }
@@ -1,18 +1,105 @@
1
1
  .yasqe {
2
- .CodeMirror {
2
+ .CodeMirror,
3
+ .cm-editor {
3
4
  line-height: 1.5em;
4
5
  font-size: 14px;
5
- border: 1px solid var(--yasgui-border-color);
6
+ border: 1px solid var(--yasgui-border-color, #ddd);
7
+ background: var(--yasgui-bg-primary, #fff);
8
+ color: var(--yasgui-text-primary, #000);
9
+ height: 100%;
10
+ }
11
+ .cm-editor.cm-focused {
12
+ outline: none;
13
+ }
14
+ .cm-scroller {
15
+ font-family: monospace;
16
+ overflow: auto;
17
+ }
18
+ .cm-gutters {
19
+ background-color: var(--yasgui-bg-secondary, #f7f7f7);
20
+ border-right: 1px solid var(--yasgui-border-color, #ddd);
21
+ color: var(--yasgui-text-secondary, #999);
22
+ }
23
+ .cm-activeLineGutter {
24
+ background-color: transparent;
25
+ }
26
+
27
+ // Default (light) token colors, mirroring the CodeMirror 5 default theme
28
+ .cm-s-default {
29
+ span.cm-keyword {
30
+ color: #708;
31
+ }
32
+ span.cm-atom {
33
+ color: #219;
34
+ }
35
+ span.cm-number {
36
+ color: #164;
37
+ }
38
+ span.cm-variable-3 {
39
+ color: #085;
40
+ }
41
+ span.cm-string {
42
+ color: #a11;
43
+ }
44
+ span.cm-string-2 {
45
+ color: #f50;
46
+ }
47
+ span.cm-meta {
48
+ color: #555;
49
+ }
50
+ span.cm-comment {
51
+ color: #a50;
52
+ }
53
+ span.cm-punc {
54
+ color: inherit;
55
+ }
6
56
  }
7
57
 
8
58
  span.cm-error {
9
59
  border-bottom: 2px dotted red;
10
60
  }
11
- .gutterErrorBar {
12
- width: 4px;
61
+ .cm-syntax-error-token {
62
+ color: #d32f2f;
63
+ text-decoration-line: underline;
64
+ text-decoration-style: wavy;
65
+ text-decoration-color: #d32f2f;
66
+ text-underline-offset: 2px;
67
+ }
68
+ // Reserve a fixed width for the marker gutters so that adding an error/warning
69
+ // icon does not increase the gutter width (which would shift the whole editor).
70
+ .cm-gutter-gutterErrorBar,
71
+ .cm-gutter-gutterConstructWarning {
72
+ width: 16px;
73
+ }
74
+ .cm-gutter-gutterErrorBar .cm-gutterElement,
75
+ .cm-gutter-gutterConstructWarning .cm-gutterElement {
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ // Let the tooltip escape the (small) gutter element
80
+ overflow: visible;
13
81
  }
14
82
 
15
- .CodeMirror-foldmarker {
83
+ // Fold gutter arrows. The fold markers (see editor/folding.ts) only carry the
84
+ // CodeMirror-foldgutter-open / -folded classes; provide the arrow glyphs here.
85
+ .cm-foldGutter .cm-gutterElement {
86
+ padding: 0 1px;
87
+ cursor: pointer;
88
+ color: var(--yasgui-text-secondary, #999);
89
+ }
90
+ .cm-foldMarker {
91
+ display: inline-block;
92
+ line-height: 1;
93
+ }
94
+ .CodeMirror-foldgutter-open::after {
95
+ content: "\25BE"; // ▾
96
+ }
97
+ .CodeMirror-foldgutter-folded::after {
98
+ content: "\25B8"; // ▸
99
+ }
100
+
101
+ .CodeMirror-foldmarker,
102
+ .cm-foldPlaceholder {
16
103
  color: #6e2500;
17
104
  text-shadow:
18
105
  #ff935e 1px 1px 2px,
@@ -21,12 +108,18 @@
21
108
  #ff935e -1px 1px 2px;
22
109
  font-size: 19px;
23
110
  }
111
+ .cm-foldPlaceholder {
112
+ background: transparent;
113
+ border: none;
114
+ padding: 0 0.2em;
115
+ cursor: pointer;
116
+ }
24
117
  }
25
118
 
26
119
  // Rainbow bracket colors for default theme
27
- .cm-s-default {
120
+ .yasqe .cm-s-default {
28
121
  span.cm-bracket-level-0 {
29
- color: #ffd700;
122
+ color: #c4b878;
30
123
  } // Gold
31
124
  span.cm-bracket-level-1 {
32
125
  color: #da70d6;
@@ -38,22 +131,25 @@
38
131
  color: #439143;
39
132
  } // Pale green
40
133
  span.cm-bracket-paren {
41
- color: #997;
134
+ color: #654;
42
135
  } // Constant color for () and []
43
136
  span.cm-bracket-mismatch {
44
137
  color: #f00;
45
138
  } // Red for mismatched brackets
46
139
  }
47
140
  // Put these outside of yasqe as the root element can be changed
48
- .CodeMirror-hints.default {
141
+ .CodeMirror-hints.default,
142
+ .cm-tooltip.CodeMirror-hints {
49
143
  max-width: 1000px;
50
144
  }
51
- .CodeMirror-hints.default li {
145
+ .CodeMirror-hints.default li,
146
+ .cm-tooltip.CodeMirror-hints li {
52
147
  text-overflow: ellipsis;
53
148
  overflow: hidden;
54
149
  }
55
150
  @media only screen and (max-width: 1000px) {
56
- .CodeMirror-hints.default {
151
+ .CodeMirror-hints.default,
152
+ .cm-tooltip.CodeMirror-hints {
57
153
  max-width: 800px;
58
154
  }
59
155
  }
@@ -7,7 +7,8 @@
7
7
  min-height: 0;
8
8
  overflow: hidden;
9
9
 
10
- .CodeMirror {
10
+ .CodeMirror,
11
+ .cm-editor {
11
12
  min-height: 60px;
12
13
  // Height is set via inline style by the resize handler
13
14
  }
@@ -19,7 +20,8 @@
19
20
  float: left;
20
21
  }
21
22
 
22
- .CodeMirror-hint {
23
+ .CodeMirror-hint,
24
+ .CodeMirror-hints > ul > li {
23
25
  max-width: 30em;
24
26
  }
25
27
 
package/src/tooltip.ts CHANGED
@@ -7,25 +7,28 @@
7
7
  import Yasqe from "./";
8
8
 
9
9
  export default function tooltip(_yasqe: Yasqe, parent: HTMLElement, html: string) {
10
- var tooltip: HTMLDivElement;
11
- parent.onmouseover = function () {
10
+ // Render the tooltip inside the yasqe root (so the scoped `.yasqe .yasqe_tooltip`
11
+ // styles apply) but position it `fixed` relative to the icon. Fixed positioning
12
+ // escapes the `overflow` clipping of the CodeMirror gutter/scroller, which would
13
+ // otherwise hide the tooltip behind the editor.
14
+ let tooltip: HTMLDivElement | undefined;
15
+ parent.onmouseover = function (this: HTMLElement) {
12
16
  if (!tooltip) {
13
17
  tooltip = document.createElement("div");
14
18
  tooltip.className = "yasqe_tooltip";
19
+ _yasqe.rootEl.appendChild(tooltip);
15
20
  }
16
- // if ($(yasqe.getWrapperElement()).offset().top >= tooltip.offset().top) {
17
- //shit, move the tooltip down. The tooltip now hovers over the top edge of the yasqe instance
18
- // tooltip.css("bottom", "auto");
19
- // tooltip.css("top", "26px");
20
- // }
21
- tooltip.style.display = "block";
22
21
  tooltip.innerHTML = html;
23
- parent.appendChild(tooltip);
22
+ tooltip.style.display = "block";
23
+ // `this` is the element the handler fires on. The gutter marker is rendered as a clone of
24
+ // `parent`, so position relative to `this` rather than the (possibly detached) `parent`.
25
+ const rect = this.getBoundingClientRect();
26
+ tooltip.style.position = "fixed";
27
+ tooltip.style.left = `${rect.right + 6}px`;
28
+ tooltip.style.top = `${rect.top}px`;
29
+ tooltip.style.zIndex = "10000";
24
30
  };
25
31
  parent.onmouseout = function () {
26
- if (tooltip) {
27
- tooltip.style.display = "none";
28
- }
29
- tooltip.innerHTML = html;
32
+ if (tooltip) tooltip.style.display = "none";
30
33
  };
31
34
  }
@@ -1,30 +0,0 @@
1
- import { Editor as CmEditor, Doc as CmDoc, Token as CmToken, Position as CmPosition, EditorConfiguration as CmEditorConfiguration } from "codemirror";
2
- import * as sparql11Mode from "../grammar/tokenizer";
3
- import { TokenizerState } from "./index";
4
- import "codemirror/addon/fold/foldcode.js";
5
- import "codemirror/addon/fold/foldgutter.js";
6
- import "codemirror/addon/fold/xml-fold.js";
7
- import "codemirror/addon/fold/brace-fold.js";
8
- import "codemirror/addon/hint/show-hint.js";
9
- import "codemirror/addon/search/searchcursor.js";
10
- import "codemirror/addon/search/match-highlighter.js";
11
- import "codemirror/addon/edit/matchbrackets.js";
12
- import "codemirror/addon/runmode/runmode.js";
13
- import "codemirror/lib/codemirror.css";
14
- import "codemirror/addon/fold/foldgutter.css";
15
- import "./scss/codemirrorMods.scss";
16
- declare namespace CodeMirror {
17
- type Doc = CmDoc;
18
- type Position = CmPosition;
19
- type EditorConfiguration = CmEditorConfiguration;
20
- interface Token extends CmToken {
21
- state: sparql11Mode.State;
22
- }
23
- }
24
- interface CodeMirror extends Omit<CmEditor, "getOption" | "setOption" | "on" | "off"> {
25
- getOption(opt: "queryType"): TokenizerState["queryType"];
26
- setOption(opt: "queryType", val: TokenizerState["queryType"]): void;
27
- foldCode(firstPrefixLine: number, prefix: string, collapse: "fold" | "unfold"): void;
28
- }
29
- declare const CodeMirror: any;
30
- export default CodeMirror;
@@ -1,20 +0,0 @@
1
- import _CodeMirror from "codemirror";
2
- import * as sparql11Mode from "../grammar/tokenizer";
3
- import { default as prefixFold } from "./prefixFold";
4
- import "codemirror/addon/fold/foldcode.js";
5
- import "codemirror/addon/fold/foldgutter.js";
6
- import "codemirror/addon/fold/xml-fold.js";
7
- import "codemirror/addon/fold/brace-fold.js";
8
- import "codemirror/addon/hint/show-hint.js";
9
- import "codemirror/addon/search/searchcursor.js";
10
- import "codemirror/addon/search/match-highlighter.js";
11
- import "codemirror/addon/edit/matchbrackets.js";
12
- import "codemirror/addon/runmode/runmode.js";
13
- import "codemirror/lib/codemirror.css";
14
- import "codemirror/addon/fold/foldgutter.css";
15
- import "./scss/codemirrorMods.scss";
16
- _CodeMirror.registerHelper("fold", "prefix", prefixFold);
17
- _CodeMirror.defineMode("sparql11", sparql11Mode.default);
18
- const CodeMirror = _CodeMirror;
19
- export default CodeMirror;
20
- //# sourceMappingURL=CodeMirror.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CodeMirror.js","sourceRoot":"","sources":["../../../../../packages/yasqe/src/CodeMirror.ts"],"names":[],"mappings":"AAUA,OAAO,WAAW,MAAM,YAAY,CAAC;AAErC,OAAO,KAAK,YAAY,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,oCAAoC,CAAC;AAC5C,OAAO,yCAAyC,CAAC;AACjD,OAAO,8CAA8C,CAAC;AACtD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,+BAA+B,CAAC;AACvC,OAAO,sCAAsC,CAAC;AAC9C,OAAO,4BAA4B,CAAC;AAEpC,WAAW,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AACzD,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;AAsBzD,MAAM,UAAU,GAAQ,WAAW,CAAC;AACpC,eAAe,UAAU,CAAC"}
@@ -1,8 +0,0 @@
1
- import { default as Yasqe, Position } from "./";
2
- import CodeMirror from "codemirror";
3
- export declare function findFirstPrefixLine(yasqe: Yasqe): number;
4
- export declare function findFirstPrefix(yasqe: Yasqe, line: number, startFromCharIndex?: number, lineText?: string): number;
5
- export default function (yasqe: Yasqe, start: Position): {
6
- from: CodeMirror.Position;
7
- to: CodeMirror.Position;
8
- };
@@ -1,87 +0,0 @@
1
- import CodeMirror from "codemirror";
2
- import * as TokenUtils from "./tokenUtils";
3
- const PREFIX_KEYWORD = "PREFIX ";
4
- export function findFirstPrefixLine(yasqe) {
5
- var lastLine = yasqe.getDoc().lastLine();
6
- for (var i = 0; i <= lastLine; ++i) {
7
- const firstPrefix = findFirstPrefix(yasqe, i);
8
- if (firstPrefix != null && firstPrefix >= 0) {
9
- return i;
10
- }
11
- }
12
- }
13
- export function findFirstPrefix(yasqe, line, startFromCharIndex = 0, lineText) {
14
- if (!lineText)
15
- lineText = yasqe.getDoc().getLine(line);
16
- if (!lineText)
17
- return undefined;
18
- lineText = lineText.toUpperCase();
19
- const charIndex = lineText.indexOf(PREFIX_KEYWORD, startFromCharIndex);
20
- if (charIndex >= 0) {
21
- const tokenType = yasqe.getTokenTypeAt(CodeMirror.Pos(line, charIndex + 1));
22
- if (tokenType === "keyword") {
23
- return charIndex;
24
- }
25
- }
26
- }
27
- export default function (yasqe, start) {
28
- var line = start.line, lineText = yasqe.getDoc().getLine(line);
29
- function hasPreviousPrefix() {
30
- var hasPreviousPrefix = false;
31
- for (var i = line - 1; i >= 0; i--) {
32
- if (yasqe.getDoc().getLine(i).toUpperCase().indexOf(PREFIX_KEYWORD) >= 0) {
33
- hasPreviousPrefix = true;
34
- break;
35
- }
36
- }
37
- return hasPreviousPrefix;
38
- }
39
- var getLastPrefixPos = function (line, ch) {
40
- var prefixKeywordToken = yasqe.getTokenAt(CodeMirror.Pos(line, ch + 1));
41
- if (!prefixKeywordToken || prefixKeywordToken.type != "keyword")
42
- return -1;
43
- var prefixShortname = TokenUtils.getNextNonWsToken(yasqe, line, prefixKeywordToken.end + 1);
44
- if (!prefixShortname || prefixShortname.type != "string-2")
45
- return -1;
46
- var prefixUri = TokenUtils.getNextNonWsToken(yasqe, line, prefixShortname.end + 1);
47
- if (!prefixUri || prefixUri.type != "variable-3")
48
- return -1;
49
- return prefixUri.end;
50
- };
51
- if (hasPreviousPrefix())
52
- return;
53
- var prefixStart = findFirstPrefix(yasqe, line, start.ch, lineText);
54
- if (prefixStart == null)
55
- return;
56
- var stopAt = "{";
57
- var stopAtNextLine = false;
58
- var lastLine = yasqe.getDoc().lastLine(), endCh;
59
- var prefixEndChar = getLastPrefixPos(line, prefixStart);
60
- var prefixEndLine = line;
61
- for (var i = line; i <= lastLine; ++i) {
62
- if (stopAtNextLine)
63
- break;
64
- var text = yasqe.getDoc().getLine(i), pos = i == line ? prefixStart + 1 : 0;
65
- for (;;) {
66
- if (!stopAtNextLine && text.indexOf(stopAt) >= 0)
67
- stopAtNextLine = true;
68
- var nextPrefixDeclaration = text.toUpperCase().indexOf(PREFIX_KEYWORD, pos);
69
- if (nextPrefixDeclaration >= 0) {
70
- if ((endCh = getLastPrefixPos(i, nextPrefixDeclaration)) > 0) {
71
- prefixEndChar = endCh;
72
- prefixEndLine = i;
73
- pos = prefixEndChar;
74
- }
75
- pos++;
76
- }
77
- else {
78
- break;
79
- }
80
- }
81
- }
82
- return {
83
- from: CodeMirror.Pos(line, prefixStart + PREFIX_KEYWORD.length),
84
- to: CodeMirror.Pos(prefixEndLine, prefixEndChar),
85
- };
86
- }
87
- //# sourceMappingURL=prefixFold.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prefixFold.js","sourceRoot":"","sources":["../../../../../packages/yasqe/src/prefixFold.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC,MAAM,UAAU,mBAAmB,CAAC,KAAY;IAC9C,IAAI,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9C,IAAI,WAAW,IAAI,IAAI,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;YAC5C,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,IAAY,EAAE,kBAAkB,GAAG,CAAC,EAAE,QAAiB;IACnG,IAAI,CAAC,QAAQ;QAAE,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,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,cAAc,GAAG,IAAI,CAAC;YAExE,IAAI,qBAAqB,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAE5E,IAAI,qBAAqB,IAAI,CAAC,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC7D,aAAa,GAAG,KAAK,CAAC;oBACtB,aAAa,GAAG,CAAC,CAAC;oBAClB,GAAG,GAAG,aAAa,CAAC;gBACtB,CAAC;gBACD,GAAG,EAAE,CAAC;YACR,CAAC;iBAAM,CAAC;gBACN,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC;QAC/D,EAAE,EAAE,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC;KACjD,CAAC;AACJ,CAAC"}
package/src/CodeMirror.ts DELETED
@@ -1,54 +0,0 @@
1
- //Do not want to import this using typescript. Somehow, we get a tangled mess when transpiling to es6 with ts,
2
- //and applying babel.
3
- import {
4
- Editor as CmEditor,
5
- Doc as CmDoc,
6
- Token as CmToken,
7
- Position as CmPosition,
8
- EditorConfiguration as CmEditorConfiguration,
9
- } from "codemirror";
10
-
11
- import _CodeMirror from "codemirror";
12
-
13
- import * as sparql11Mode from "../grammar/tokenizer";
14
- import { default as prefixFold } from "./prefixFold";
15
- import { TokenizerState } from "./index";
16
-
17
- import "codemirror/addon/fold/foldcode.js";
18
- import "codemirror/addon/fold/foldgutter.js";
19
- import "codemirror/addon/fold/xml-fold.js";
20
- import "codemirror/addon/fold/brace-fold.js";
21
- import "codemirror/addon/hint/show-hint.js";
22
- import "codemirror/addon/search/searchcursor.js";
23
- import "codemirror/addon/search/match-highlighter.js";
24
- import "codemirror/addon/edit/matchbrackets.js";
25
- import "codemirror/addon/runmode/runmode.js";
26
- import "codemirror/lib/codemirror.css";
27
- import "codemirror/addon/fold/foldgutter.css";
28
- import "./scss/codemirrorMods.scss";
29
-
30
- _CodeMirror.registerHelper("fold", "prefix", prefixFold);
31
- _CodeMirror.defineMode("sparql11", sparql11Mode.default);
32
-
33
- namespace CodeMirror {
34
- export type Doc = CmDoc;
35
- export type Position = CmPosition;
36
- export type EditorConfiguration = CmEditorConfiguration;
37
- export interface Token extends CmToken {
38
- state: sparql11Mode.State;
39
- }
40
- }
41
- interface CodeMirror extends Omit<CmEditor, "getOption" | "setOption" | "on" | "off"> {
42
- /**
43
- * Added some more specific typings for `getOption`
44
- * For some functions (called from keyboard combinations like ctrl-enter) we cannot use member props of our object
45
- * as these are lost when we are receiving the native CM object as argument
46
- * Only way to persistently store these options is by using getOption and setOption
47
- */
48
- getOption(opt: "queryType"): TokenizerState["queryType"];
49
- setOption(opt: "queryType", val: TokenizerState["queryType"]): void;
50
-
51
- foldCode(firstPrefixLine: number, prefix: string, collapse: "fold" | "unfold"): void;
52
- }
53
- const CodeMirror: any = _CodeMirror;
54
- export default CodeMirror;
package/src/prefixFold.ts DELETED
@@ -1,94 +0,0 @@
1
- import { default as Yasqe, Position } from "./";
2
- import CodeMirror from "codemirror";
3
- import * as TokenUtils from "./tokenUtils";
4
- const PREFIX_KEYWORD = "PREFIX ";
5
-
6
- export function findFirstPrefixLine(yasqe: Yasqe) {
7
- var lastLine = yasqe.getDoc().lastLine();
8
- for (var i = 0; i <= lastLine; ++i) {
9
- const firstPrefix = findFirstPrefix(yasqe, i);
10
- if (firstPrefix != null && firstPrefix >= 0) {
11
- return i;
12
- }
13
- }
14
- }
15
-
16
- export function findFirstPrefix(yasqe: Yasqe, line: number, startFromCharIndex = 0, lineText?: string) {
17
- if (!lineText) lineText = yasqe.getDoc().getLine(line);
18
- if (!lineText) return undefined;
19
- lineText = lineText.toUpperCase();
20
- const charIndex = lineText.indexOf(PREFIX_KEYWORD, startFromCharIndex);
21
- if (charIndex >= 0) {
22
- const tokenType = yasqe.getTokenTypeAt(CodeMirror.Pos(line, charIndex + 1));
23
- if (tokenType === "keyword") {
24
- return charIndex;
25
- }
26
- }
27
- }
28
- export default function (yasqe: Yasqe, start: Position) {
29
- var line = start.line,
30
- lineText = yasqe.getDoc().getLine(line);
31
-
32
- // var startCh, tokenType;
33
-
34
- function hasPreviousPrefix() {
35
- var hasPreviousPrefix = false;
36
- for (var i = line - 1; i >= 0; i--) {
37
- if (yasqe.getDoc().getLine(i).toUpperCase().indexOf(PREFIX_KEYWORD) >= 0) {
38
- hasPreviousPrefix = true;
39
- break;
40
- }
41
- }
42
- return hasPreviousPrefix;
43
- }
44
-
45
- var getLastPrefixPos = function (line: number, ch: number) {
46
- var prefixKeywordToken = yasqe.getTokenAt(CodeMirror.Pos(line, ch + 1));
47
- if (!prefixKeywordToken || prefixKeywordToken.type != "keyword") return -1;
48
- var prefixShortname = TokenUtils.getNextNonWsToken(yasqe, line, prefixKeywordToken.end + 1);
49
- if (!prefixShortname || prefixShortname.type != "string-2") return -1; //missing prefix keyword shortname
50
- var prefixUri = TokenUtils.getNextNonWsToken(yasqe, line, prefixShortname.end + 1);
51
- if (!prefixUri || prefixUri.type != "variable-3") return -1; //missing prefix uri
52
- return prefixUri.end;
53
- };
54
-
55
- //only use opening prefix declaration
56
- if (hasPreviousPrefix()) return;
57
- var prefixStart = findFirstPrefix(yasqe, line, start.ch, lineText);
58
-
59
- if (prefixStart == null) return;
60
- var stopAt = "{"; //if this char is there, we won't have a chance of finding more prefixes
61
- var stopAtNextLine = false;
62
- var lastLine = yasqe.getDoc().lastLine(),
63
- endCh;
64
- var prefixEndChar = getLastPrefixPos(line, prefixStart);
65
- var prefixEndLine = line;
66
-
67
- // outer:
68
- for (var i = line; i <= lastLine; ++i) {
69
- if (stopAtNextLine) break;
70
- var text = yasqe.getDoc().getLine(i),
71
- pos = i == line ? prefixStart + 1 : 0;
72
-
73
- for (;;) {
74
- if (!stopAtNextLine && text.indexOf(stopAt) >= 0) stopAtNextLine = true;
75
-
76
- var nextPrefixDeclaration = text.toUpperCase().indexOf(PREFIX_KEYWORD, pos);
77
-
78
- if (nextPrefixDeclaration >= 0) {
79
- if ((endCh = getLastPrefixPos(i, nextPrefixDeclaration)) > 0) {
80
- prefixEndChar = endCh;
81
- prefixEndLine = i;
82
- pos = prefixEndChar;
83
- }
84
- pos++;
85
- } else {
86
- break;
87
- }
88
- }
89
- }
90
- return {
91
- from: CodeMirror.Pos(line, prefixStart + PREFIX_KEYWORD.length),
92
- to: CodeMirror.Pos(prefixEndLine, prefixEndChar),
93
- };
94
- }