@tellaro/tql 0.1.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.
- package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +37 -0
- package/dist/src/completionProvider.d.ts +22 -0
- package/dist/src/completionProvider.js +619 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/parser.d.ts +81 -0
- package/dist/src/parser.js +511 -0
- package/dist/src/tokenizer.d.ts +113 -0
- package/dist/src/tokenizer.js +430 -0
- package/dist/src/types.d.ts +221 -0
- package/dist/src/validator.d.ts +46 -0
- package/dist/src/validator.js +315 -0
- package/dist/style.css +1 -0
- package/dist/vue/TqlAutocomplete.vue.d.ts +2 -0
- package/dist/vue/TqlAutocomplete.vue.js +7 -0
- package/dist/vue/TqlAutocomplete.vue2.js +136 -0
- package/dist/vue/TqlInput.vue.d.ts +2 -0
- package/dist/vue/TqlInput.vue.js +7 -0
- package/dist/vue/TqlInput.vue2.js +326 -0
- package/dist/vue/index.d.ts +10 -0
- package/dist/vue/index.js +8 -0
- package/dist/vue/useTqlInput.js +166 -0
- package/package.json +79 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { defineComponent as C, ref as y, watch as $, nextTick as D, computed as L, onMounted as T, onUnmounted as S, openBlock as l, createBlock as B, Teleport as z, createElementBlock as s, normalizeStyle as A, createElementVNode as d, Fragment as H, renderList as I, normalizeClass as k, toDisplayString as p, createCommentVNode as u } from "vue";
|
|
2
|
+
const K = { class: "tql-completion-list" }, M = ["aria-selected", "onClick", "onMouseenter"], U = { class: "tql-completion-content" }, V = { class: "tql-completion-label" }, N = {
|
|
3
|
+
key: 0,
|
|
4
|
+
class: "tql-completion-detail"
|
|
5
|
+
}, O = {
|
|
6
|
+
key: 0,
|
|
7
|
+
class: "tql-completion-kind-badge"
|
|
8
|
+
}, R = {
|
|
9
|
+
key: 0,
|
|
10
|
+
class: "tql-completion-docs"
|
|
11
|
+
}, Q = /* @__PURE__ */ C({
|
|
12
|
+
__name: "TqlAutocomplete",
|
|
13
|
+
props: {
|
|
14
|
+
items: {},
|
|
15
|
+
visible: { type: Boolean },
|
|
16
|
+
position: {},
|
|
17
|
+
maxHeight: {}
|
|
18
|
+
},
|
|
19
|
+
emits: ["select", "close"],
|
|
20
|
+
setup(i, { expose: w, emit: b }) {
|
|
21
|
+
const t = i, a = b, e = y(0), c = y(null);
|
|
22
|
+
$(
|
|
23
|
+
() => t.items,
|
|
24
|
+
() => {
|
|
25
|
+
e.value = 0, r();
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
function r() {
|
|
29
|
+
D(() => {
|
|
30
|
+
if (!c.value) return;
|
|
31
|
+
const o = c.value.querySelector(".tql-completion-item.selected");
|
|
32
|
+
o && o.scrollIntoView({ block: "nearest" });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function f(o) {
|
|
36
|
+
if (!(!t.visible || t.items.length === 0))
|
|
37
|
+
switch (o.key) {
|
|
38
|
+
case "ArrowDown":
|
|
39
|
+
o.preventDefault(), e.value = (e.value + 1) % t.items.length, r();
|
|
40
|
+
break;
|
|
41
|
+
case "ArrowUp":
|
|
42
|
+
o.preventDefault(), e.value = (e.value - 1 + t.items.length) % t.items.length, r();
|
|
43
|
+
break;
|
|
44
|
+
case "Enter":
|
|
45
|
+
case "Tab":
|
|
46
|
+
o.preventDefault(), t.items[e.value] && a("select", t.items[e.value]);
|
|
47
|
+
break;
|
|
48
|
+
case "Escape":
|
|
49
|
+
o.preventDefault(), a("close");
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function q(o) {
|
|
54
|
+
return {
|
|
55
|
+
field: "pi pi-tag",
|
|
56
|
+
operator: "pi pi-code",
|
|
57
|
+
value: "pi pi-hashtag",
|
|
58
|
+
keyword: "pi pi-key",
|
|
59
|
+
snippet: "pi pi-file-edit",
|
|
60
|
+
mutator: "pi pi-wrench",
|
|
61
|
+
aggregation: "pi pi-chart-bar",
|
|
62
|
+
logicalOp: "pi pi-sitemap",
|
|
63
|
+
typeHint: "pi pi-info-circle",
|
|
64
|
+
visualization: "pi pi-chart-line"
|
|
65
|
+
}[o] || "pi pi-circle";
|
|
66
|
+
}
|
|
67
|
+
function _(o) {
|
|
68
|
+
return `tql-completion-kind-${o}`;
|
|
69
|
+
}
|
|
70
|
+
const x = L(() => ({
|
|
71
|
+
"--dropdown-top": `${t.position.top}px`,
|
|
72
|
+
"--dropdown-left": `${t.position.left}px`,
|
|
73
|
+
"--dropdown-max-height": `${t.maxHeight || 300}px`
|
|
74
|
+
}));
|
|
75
|
+
function h(o) {
|
|
76
|
+
const m = o.target;
|
|
77
|
+
c.value && !c.value.contains(m) && a("close");
|
|
78
|
+
}
|
|
79
|
+
return T(() => {
|
|
80
|
+
document.addEventListener("keydown", f), document.addEventListener("mousedown", h);
|
|
81
|
+
}), S(() => {
|
|
82
|
+
document.removeEventListener("keydown", f), document.removeEventListener("mousedown", h);
|
|
83
|
+
}), w({
|
|
84
|
+
selectCurrent: () => {
|
|
85
|
+
t.items[e.value] && a("select", t.items[e.value]);
|
|
86
|
+
},
|
|
87
|
+
moveUp: () => {
|
|
88
|
+
e.value = (e.value - 1 + t.items.length) % t.items.length, r();
|
|
89
|
+
},
|
|
90
|
+
moveDown: () => {
|
|
91
|
+
e.value = (e.value + 1) % t.items.length, r();
|
|
92
|
+
}
|
|
93
|
+
}), (o, m) => {
|
|
94
|
+
var g;
|
|
95
|
+
return l(), B(z, { to: "body" }, [
|
|
96
|
+
i.visible && i.items.length > 0 ? (l(), s("div", {
|
|
97
|
+
key: 0,
|
|
98
|
+
ref_key: "listRef",
|
|
99
|
+
ref: c,
|
|
100
|
+
class: "tql-autocomplete-dropdown",
|
|
101
|
+
style: A(x.value),
|
|
102
|
+
role: "listbox",
|
|
103
|
+
"aria-label": "TQL completions"
|
|
104
|
+
}, [
|
|
105
|
+
d("div", K, [
|
|
106
|
+
(l(!0), s(H, null, I(i.items, (n, v) => (l(), s("div", {
|
|
107
|
+
key: `${n.kind}-${n.label}`,
|
|
108
|
+
class: k(["tql-completion-item", { selected: v === e.value }]),
|
|
109
|
+
role: "option",
|
|
110
|
+
"aria-selected": v === e.value,
|
|
111
|
+
onClick: (E) => a("select", n),
|
|
112
|
+
onMouseenter: (E) => e.value = v
|
|
113
|
+
}, [
|
|
114
|
+
d("span", {
|
|
115
|
+
class: k(["tql-completion-icon", _(n.kind)])
|
|
116
|
+
}, [
|
|
117
|
+
d("i", {
|
|
118
|
+
class: k(q(n.kind))
|
|
119
|
+
}, null, 2)
|
|
120
|
+
], 2),
|
|
121
|
+
d("span", U, [
|
|
122
|
+
d("span", V, p(n.label), 1),
|
|
123
|
+
n.detail ? (l(), s("span", N, p(n.detail), 1)) : u("", !0)
|
|
124
|
+
]),
|
|
125
|
+
n.kind ? (l(), s("span", O, p(n.kind), 1)) : u("", !0)
|
|
126
|
+
], 42, M))), 128))
|
|
127
|
+
]),
|
|
128
|
+
(g = i.items[e.value]) != null && g.documentation ? (l(), s("div", R, p(i.items[e.value].documentation), 1)) : u("", !0)
|
|
129
|
+
], 4)) : u("", !0)
|
|
130
|
+
]);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
export {
|
|
135
|
+
Q as default
|
|
136
|
+
};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { defineComponent as he, ref as f, toRef as D, watch as ge, computed as ye, onMounted as ke, openBlock as u, createElementBlock as s, normalizeClass as q, unref as p, Fragment as z, renderList as F, toDisplayString as P, createCommentVNode as b, withDirectives as L, vModelText as j, withKeys as be, withModifiers as we, createElementVNode as E, createVNode as qe, nextTick as C } from "vue";
|
|
2
|
+
import Ce from "./TqlAutocomplete.vue.js";
|
|
3
|
+
import { useTqlInput as Ve } from "./useTqlInput.js";
|
|
4
|
+
const Se = {
|
|
5
|
+
key: 0,
|
|
6
|
+
class: "tql-highlight-layer",
|
|
7
|
+
"aria-hidden": "true"
|
|
8
|
+
}, Re = ["placeholder", "disabled", "readonly", "rows"], xe = ["placeholder", "disabled", "readonly"], Te = {
|
|
9
|
+
key: 3,
|
|
10
|
+
class: "tql-validation-icon"
|
|
11
|
+
}, Be = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "pi pi-check-circle tql-icon-valid"
|
|
14
|
+
}, De = {
|
|
15
|
+
key: 5,
|
|
16
|
+
class: "tql-validation-messages"
|
|
17
|
+
}, Pe = {
|
|
18
|
+
key: 0,
|
|
19
|
+
class: "tql-error-suggestion"
|
|
20
|
+
}, Ke = /* @__PURE__ */ he({
|
|
21
|
+
__name: "TqlInput",
|
|
22
|
+
props: {
|
|
23
|
+
modelValue: {},
|
|
24
|
+
placeholder: { default: "Enter TQL query..." },
|
|
25
|
+
disabled: { type: Boolean, default: !1 },
|
|
26
|
+
readonly: { type: Boolean, default: !1 },
|
|
27
|
+
rows: { default: 3 },
|
|
28
|
+
multiline: { type: Boolean, default: !1 },
|
|
29
|
+
showValidation: { type: Boolean, default: !0 },
|
|
30
|
+
validateOnInput: { type: Boolean, default: !0 },
|
|
31
|
+
debounceMs: { default: 300 },
|
|
32
|
+
fieldSchema: {},
|
|
33
|
+
modelName: {},
|
|
34
|
+
snippets: {},
|
|
35
|
+
showSnippetButton: { type: Boolean, default: !1 },
|
|
36
|
+
autocomplete: { type: Boolean, default: !0 },
|
|
37
|
+
syntaxHighlighting: { type: Boolean, default: !0 }
|
|
38
|
+
},
|
|
39
|
+
emits: ["update:modelValue", "validation", "parse", "submit"],
|
|
40
|
+
setup(a, { expose: Q, emit: G }) {
|
|
41
|
+
const r = a, d = G, n = f(null), V = f(null), g = f(null), i = f(r.modelValue), y = f(!1), v = f(!1), k = f([]), m = f(-1), J = D(r, "modelValue"), W = D(r, "fieldSchema"), X = D(r, "snippets"), {
|
|
42
|
+
tokens: Y,
|
|
43
|
+
cursorPosition: S,
|
|
44
|
+
completionItems: I,
|
|
45
|
+
showAutocomplete: R,
|
|
46
|
+
isValid: Z,
|
|
47
|
+
errors: A,
|
|
48
|
+
hasErrors: K,
|
|
49
|
+
validate: _,
|
|
50
|
+
handleInput: ee,
|
|
51
|
+
handleCursorChange: h,
|
|
52
|
+
insertCompletion: te,
|
|
53
|
+
insertSnippet: le,
|
|
54
|
+
triggerAutocomplete: ne,
|
|
55
|
+
hideAutocomplete: x,
|
|
56
|
+
getTokenAtCursor: ae
|
|
57
|
+
} = Ve({
|
|
58
|
+
modelValue: J,
|
|
59
|
+
fieldSchema: W,
|
|
60
|
+
snippets: X,
|
|
61
|
+
validateOnInput: r.validateOnInput,
|
|
62
|
+
debounceMs: r.debounceMs,
|
|
63
|
+
autocomplete: r.autocomplete,
|
|
64
|
+
onValidation: (e) => d("validation", e),
|
|
65
|
+
onParse: (e) => d("parse", e)
|
|
66
|
+
});
|
|
67
|
+
ge(
|
|
68
|
+
() => r.modelValue,
|
|
69
|
+
(e) => {
|
|
70
|
+
e !== i.value && (i.value = e);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const oe = ye(() => {
|
|
74
|
+
if (!n.value || !V.value)
|
|
75
|
+
return { top: 0, left: 0 };
|
|
76
|
+
const e = V.value.getBoundingClientRect();
|
|
77
|
+
return {
|
|
78
|
+
top: e.bottom + 4,
|
|
79
|
+
left: e.left
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
function ie(e) {
|
|
83
|
+
const t = `tql-token tql-token-${e.type}`;
|
|
84
|
+
return A.value.some((o) => e.start >= o.start && e.end <= o.end) ? `${t} tql-token-error-range` : t;
|
|
85
|
+
}
|
|
86
|
+
function M(e) {
|
|
87
|
+
const t = e.target;
|
|
88
|
+
i.value = t.value, d("update:modelValue", t.value), ee(t.value), C(() => {
|
|
89
|
+
n.value && h(n.value.selectionStart || 0);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function T() {
|
|
93
|
+
if (n.value) {
|
|
94
|
+
const e = n.value.selectionStart || 0;
|
|
95
|
+
e !== S.value && h(e);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function N(e) {
|
|
99
|
+
var t, l, o, c;
|
|
100
|
+
if (e.key === "Tab" && !e.shiftKey) {
|
|
101
|
+
if (k.value.length > 0 && m.value >= 0) {
|
|
102
|
+
e.preventDefault(), ue();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (se()) {
|
|
106
|
+
e.preventDefault(), re();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (R.value && I.value.length > 0)
|
|
111
|
+
switch (e.key) {
|
|
112
|
+
case "ArrowDown":
|
|
113
|
+
e.preventDefault(), (t = g.value) == null || t.moveDown();
|
|
114
|
+
return;
|
|
115
|
+
case "ArrowUp":
|
|
116
|
+
e.preventDefault(), (l = g.value) == null || l.moveUp();
|
|
117
|
+
return;
|
|
118
|
+
case "Tab":
|
|
119
|
+
case "Enter":
|
|
120
|
+
if (e.key === "Enter" && !r.multiline) {
|
|
121
|
+
if (e.key === "Tab") {
|
|
122
|
+
e.preventDefault(), (o = g.value) == null || o.selectCurrent();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
e.preventDefault(), (c = g.value) == null || c.selectCurrent();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "Escape":
|
|
131
|
+
e.preventDefault(), x(), B();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (e.key === " " && e.ctrlKey) {
|
|
135
|
+
e.preventDefault(), ne();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
e.key === "Enter" && (r.multiline && e.ctrlKey || !r.multiline && !R.value) && (e.preventDefault(), d("submit", i.value));
|
|
139
|
+
}
|
|
140
|
+
function ue() {
|
|
141
|
+
if (m.value++, m.value >= k.value.length) {
|
|
142
|
+
B();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const e = k.value[m.value];
|
|
146
|
+
n.value && (n.value.setSelectionRange(e.start, e.end), n.value.focus(), h(e.start));
|
|
147
|
+
}
|
|
148
|
+
function B() {
|
|
149
|
+
k.value = [], m.value = -1;
|
|
150
|
+
}
|
|
151
|
+
function se() {
|
|
152
|
+
const e = S.value, t = i.value;
|
|
153
|
+
let l = !1, o = null;
|
|
154
|
+
for (let c = 0; c < e; c++) {
|
|
155
|
+
const w = t[c], me = c > 0 ? t[c - 1] : "";
|
|
156
|
+
(w === '"' || w === "'") && me !== "\\" && (l ? w === o && (l = !1, o = null) : (l = !0, o = w));
|
|
157
|
+
}
|
|
158
|
+
return l;
|
|
159
|
+
}
|
|
160
|
+
function re() {
|
|
161
|
+
const e = S.value, t = i.value;
|
|
162
|
+
for (let l = e; l < t.length; l++)
|
|
163
|
+
if (t[l] === '"' || t[l] === "'") {
|
|
164
|
+
const o = l + 1;
|
|
165
|
+
n.value && (n.value.setSelectionRange(o, o), h(o));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function O() {
|
|
170
|
+
y.value = !0;
|
|
171
|
+
}
|
|
172
|
+
function H() {
|
|
173
|
+
y.value = !1, setTimeout(() => {
|
|
174
|
+
y.value || (x(), v.value = !1);
|
|
175
|
+
}, 200);
|
|
176
|
+
}
|
|
177
|
+
function ce(e) {
|
|
178
|
+
const t = te(e);
|
|
179
|
+
i.value = t.query, d("update:modelValue", t.query), t.placeholders.length > 0 ? (k.value = t.placeholders, m.value = 0) : B(), C(() => {
|
|
180
|
+
n.value && (n.value.focus(), n.value.setSelectionRange(t.newCursorPosition, t.newCursorPosition), h(t.newCursorPosition));
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function de(e) {
|
|
184
|
+
const t = le(e);
|
|
185
|
+
i.value = t, d("update:modelValue", t), C(() => {
|
|
186
|
+
n.value && n.value.focus();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function fe() {
|
|
190
|
+
var e;
|
|
191
|
+
(e = n.value) == null || e.focus();
|
|
192
|
+
}
|
|
193
|
+
function pe() {
|
|
194
|
+
var e;
|
|
195
|
+
(e = n.value) == null || e.blur();
|
|
196
|
+
}
|
|
197
|
+
function U() {
|
|
198
|
+
var e;
|
|
199
|
+
return ((e = n.value) == null ? void 0 : e.selectionStart) || 0;
|
|
200
|
+
}
|
|
201
|
+
function $(e) {
|
|
202
|
+
n.value && (n.value.setSelectionRange(e, e), h(e));
|
|
203
|
+
}
|
|
204
|
+
function ve(e) {
|
|
205
|
+
const t = U(), l = i.value.substring(0, t), o = i.value.substring(t), c = l + e + o;
|
|
206
|
+
i.value = c, d("update:modelValue", c), C(() => {
|
|
207
|
+
$(t + e.length);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return Q({
|
|
211
|
+
focus: fe,
|
|
212
|
+
blur: pe,
|
|
213
|
+
validate: _,
|
|
214
|
+
insertText: ve,
|
|
215
|
+
insertSnippet: de,
|
|
216
|
+
getTokenAtPosition: ae,
|
|
217
|
+
getCursorPosition: U,
|
|
218
|
+
setCursorPosition: $
|
|
219
|
+
}), ke(() => {
|
|
220
|
+
document.addEventListener("selectionchange", T);
|
|
221
|
+
}), (e, t) => (u(), s("div", {
|
|
222
|
+
ref_key: "wrapperRef",
|
|
223
|
+
ref: V,
|
|
224
|
+
class: q([
|
|
225
|
+
"tql-input-wrapper",
|
|
226
|
+
{
|
|
227
|
+
"tql-input-focused": y.value,
|
|
228
|
+
"tql-input-invalid": p(K) && a.showValidation,
|
|
229
|
+
"tql-input-disabled": a.disabled,
|
|
230
|
+
"tql-input-multiline": a.multiline
|
|
231
|
+
}
|
|
232
|
+
])
|
|
233
|
+
}, [
|
|
234
|
+
a.syntaxHighlighting ? (u(), s("div", Se, [
|
|
235
|
+
(u(!0), s(z, null, F(p(Y), (l, o) => (u(), s("span", {
|
|
236
|
+
key: o,
|
|
237
|
+
class: q(ie(l))
|
|
238
|
+
}, P(l.raw || l.value), 3))), 128))
|
|
239
|
+
])) : b("", !0),
|
|
240
|
+
a.multiline ? L((u(), s("textarea", {
|
|
241
|
+
key: 1,
|
|
242
|
+
ref_key: "inputRef",
|
|
243
|
+
ref: n,
|
|
244
|
+
"onUpdate:modelValue": t[0] || (t[0] = (l) => i.value = l),
|
|
245
|
+
class: q(["tql-input", { "tql-input-highlighted": a.syntaxHighlighting }]),
|
|
246
|
+
placeholder: a.placeholder,
|
|
247
|
+
disabled: a.disabled,
|
|
248
|
+
readonly: a.readonly,
|
|
249
|
+
rows: a.rows,
|
|
250
|
+
spellcheck: "false",
|
|
251
|
+
autocomplete: "off",
|
|
252
|
+
autocapitalize: "off",
|
|
253
|
+
onInput: M,
|
|
254
|
+
onKeydown: N,
|
|
255
|
+
onFocus: O,
|
|
256
|
+
onBlur: H,
|
|
257
|
+
onClick: T
|
|
258
|
+
}, null, 42, Re)), [
|
|
259
|
+
[j, i.value]
|
|
260
|
+
]) : L((u(), s("input", {
|
|
261
|
+
key: 2,
|
|
262
|
+
ref_key: "inputRef",
|
|
263
|
+
ref: n,
|
|
264
|
+
"onUpdate:modelValue": t[1] || (t[1] = (l) => i.value = l),
|
|
265
|
+
type: "text",
|
|
266
|
+
class: q(["tql-input", { "tql-input-highlighted": a.syntaxHighlighting }]),
|
|
267
|
+
placeholder: a.placeholder,
|
|
268
|
+
disabled: a.disabled,
|
|
269
|
+
readonly: a.readonly,
|
|
270
|
+
spellcheck: "false",
|
|
271
|
+
autocomplete: "off",
|
|
272
|
+
autocapitalize: "off",
|
|
273
|
+
onInput: M,
|
|
274
|
+
onKeydown: N,
|
|
275
|
+
onFocus: O,
|
|
276
|
+
onBlur: H,
|
|
277
|
+
onClick: T
|
|
278
|
+
}, null, 42, xe)), [
|
|
279
|
+
[j, i.value]
|
|
280
|
+
]),
|
|
281
|
+
a.showValidation && i.value ? (u(), s("div", Te, [
|
|
282
|
+
p(Z) ? (u(), s("i", Be)) : (u(), s("i", {
|
|
283
|
+
key: 1,
|
|
284
|
+
class: "pi pi-exclamation-circle tql-icon-invalid tql-icon-clickable",
|
|
285
|
+
role: "button",
|
|
286
|
+
tabindex: "0",
|
|
287
|
+
title: "Click to show/hide errors",
|
|
288
|
+
onClick: t[2] || (t[2] = (l) => v.value = !v.value),
|
|
289
|
+
onKeydown: t[3] || (t[3] = be((l) => v.value = !v.value, ["enter"]))
|
|
290
|
+
}, null, 32))
|
|
291
|
+
])) : b("", !0),
|
|
292
|
+
a.showSnippetButton && a.snippets && a.snippets.length > 0 ? (u(), s("button", {
|
|
293
|
+
key: 4,
|
|
294
|
+
type: "button",
|
|
295
|
+
class: "tql-snippet-button",
|
|
296
|
+
title: "Insert snippet",
|
|
297
|
+
onClick: t[4] || (t[4] = we(() => {
|
|
298
|
+
}, ["stop"]))
|
|
299
|
+
}, [...t[5] || (t[5] = [
|
|
300
|
+
E("i", { class: "pi pi-code" }, null, -1)
|
|
301
|
+
])])) : b("", !0),
|
|
302
|
+
qe(Ce, {
|
|
303
|
+
ref_key: "autocompleteRef",
|
|
304
|
+
ref: g,
|
|
305
|
+
items: p(I),
|
|
306
|
+
visible: p(R) && y.value,
|
|
307
|
+
position: oe.value,
|
|
308
|
+
onSelect: ce,
|
|
309
|
+
onClose: p(x)
|
|
310
|
+
}, null, 8, ["items", "visible", "position", "onClose"]),
|
|
311
|
+
a.showValidation && p(K) && v.value && i.value ? (u(), s("div", De, [
|
|
312
|
+
(u(!0), s(z, null, F(p(A).slice(0, 3), (l, o) => (u(), s("div", {
|
|
313
|
+
key: o,
|
|
314
|
+
class: "tql-error-message"
|
|
315
|
+
}, [
|
|
316
|
+
t[6] || (t[6] = E("i", { class: "pi pi-exclamation-triangle" }, null, -1)),
|
|
317
|
+
E("span", null, P(l.message), 1),
|
|
318
|
+
l.suggestion ? (u(), s("span", Pe, P(l.suggestion), 1)) : b("", !0)
|
|
319
|
+
]))), 128))
|
|
320
|
+
])) : b("", !0)
|
|
321
|
+
], 2));
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
export {
|
|
325
|
+
Ke as default
|
|
326
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tellaro/tql/vue
|
|
3
|
+
*
|
|
4
|
+
* Vue components and composables for TQL (Tellaro Query Language).
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { default as TqlInput } from './TqlInput.vue';
|
|
9
|
+
export { default as TqlAutocomplete } from './TqlAutocomplete.vue';
|
|
10
|
+
export { useTqlInput, type UseTqlInputOptions } from './useTqlInput';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useDebounceFn as te } from "@vueuse/core";
|
|
2
|
+
import { ref as p, computed as h, watch as ne } from "vue";
|
|
3
|
+
import { shouldTriggerCompletion as se, getCompletions as oe } from "../src/completionProvider.js";
|
|
4
|
+
import { parseTql as re } from "../src/parser.js";
|
|
5
|
+
import { findTokenAtPosition as R, tokenizeTql as ue } from "../src/tokenizer.js";
|
|
6
|
+
import { validateTql as le } from "../src/validator.js";
|
|
7
|
+
function me(V) {
|
|
8
|
+
const {
|
|
9
|
+
modelValue: i,
|
|
10
|
+
fieldSchema: u,
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
snippets: ae,
|
|
13
|
+
// Reserved for future snippet support
|
|
14
|
+
fieldValues: y,
|
|
15
|
+
validateOnInput: j = !0,
|
|
16
|
+
debounceMs: D = 300,
|
|
17
|
+
autocomplete: C = !0,
|
|
18
|
+
onValidation: k,
|
|
19
|
+
onParse: q
|
|
20
|
+
} = V, v = p([]), w = p(null), d = p(null), c = p(0), m = p([]), T = p(!1), A = p(!1), Q = h(() => {
|
|
21
|
+
var e;
|
|
22
|
+
return ((e = d.value) == null ? void 0 : e.valid) ?? !0;
|
|
23
|
+
}), b = h(() => {
|
|
24
|
+
var e;
|
|
25
|
+
return ((e = d.value) == null ? void 0 : e.errors) ?? [];
|
|
26
|
+
}), P = h(() => {
|
|
27
|
+
var e;
|
|
28
|
+
return ((e = d.value) == null ? void 0 : e.warnings) ?? [];
|
|
29
|
+
}), _ = h(() => b.value.length > 0), $ = h(() => P.value.length > 0);
|
|
30
|
+
function E() {
|
|
31
|
+
return v.value = ue(i.value), v.value;
|
|
32
|
+
}
|
|
33
|
+
function B() {
|
|
34
|
+
const e = re(i.value);
|
|
35
|
+
return w.value = e, q == null || q(e), e;
|
|
36
|
+
}
|
|
37
|
+
function M() {
|
|
38
|
+
var s, r;
|
|
39
|
+
A.value = !0;
|
|
40
|
+
const e = (s = u == null ? void 0 : u.value) == null ? void 0 : s.map((l) => l.name), t = (r = u == null ? void 0 : u.value) == null ? void 0 : r.reduce(
|
|
41
|
+
(l, f) => (l[f.name] = f.type, l),
|
|
42
|
+
{}
|
|
43
|
+
), n = le(i.value, {
|
|
44
|
+
availableFields: e,
|
|
45
|
+
fieldTypes: t,
|
|
46
|
+
strictMode: !1
|
|
47
|
+
});
|
|
48
|
+
return d.value = n, A.value = !1, k == null || k(n), n;
|
|
49
|
+
}
|
|
50
|
+
const G = te(M, D);
|
|
51
|
+
function I() {
|
|
52
|
+
if (!C) {
|
|
53
|
+
m.value = [];
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const e = oe(
|
|
57
|
+
{
|
|
58
|
+
query: i.value,
|
|
59
|
+
cursorPosition: c.value
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
fields: u == null ? void 0 : u.value,
|
|
63
|
+
fieldValues: y == null ? void 0 : y.value,
|
|
64
|
+
includeSnippets: !0,
|
|
65
|
+
maxItems: 15
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
m.value = e;
|
|
69
|
+
}
|
|
70
|
+
function H() {
|
|
71
|
+
I(), T.value = m.value.length > 0;
|
|
72
|
+
}
|
|
73
|
+
function W() {
|
|
74
|
+
T.value = !1;
|
|
75
|
+
}
|
|
76
|
+
function z(e) {
|
|
77
|
+
E(), j && G(), C && se(e, c.value) && (I(), T.value = m.value.length > 0);
|
|
78
|
+
}
|
|
79
|
+
function J(e) {
|
|
80
|
+
c.value = e, I();
|
|
81
|
+
}
|
|
82
|
+
function K(e) {
|
|
83
|
+
const t = i.value, n = c.value, s = R(v.value, n);
|
|
84
|
+
let r = n, l = n;
|
|
85
|
+
if (s && s.type !== "whitespace")
|
|
86
|
+
r = s.start, l = s.end;
|
|
87
|
+
else {
|
|
88
|
+
const a = v.value.filter((o) => o.end <= n && o.type !== "whitespace");
|
|
89
|
+
if (a.length > 0) {
|
|
90
|
+
const o = a[a.length - 1];
|
|
91
|
+
o.end === n && (r = o.start, l = o.end);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const f = t.substring(0, r), Y = t.substring(l), x = [];
|
|
95
|
+
let g = e.insertText;
|
|
96
|
+
const Z = [...e.insertText.matchAll(/\$(\d+)/g)].sort(
|
|
97
|
+
(a, o) => parseInt(a[1]) - parseInt(o[1])
|
|
98
|
+
);
|
|
99
|
+
let F = 0;
|
|
100
|
+
for (const a of Z) {
|
|
101
|
+
const o = g.indexOf(a[0]);
|
|
102
|
+
if (o !== -1) {
|
|
103
|
+
const O = r + o - F;
|
|
104
|
+
x.push({
|
|
105
|
+
start: O,
|
|
106
|
+
end: O
|
|
107
|
+
// Zero-width cursor position
|
|
108
|
+
}), g = g.replace(a[0], ""), F += a[0].length;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const S = f + g + Y, ee = x.length > 0 ? x[0].start : r + g.length;
|
|
112
|
+
return W(), { query: S, newCursorPosition: ee, placeholders: x };
|
|
113
|
+
}
|
|
114
|
+
function L(e) {
|
|
115
|
+
const t = i.value, n = c.value, s = t.substring(0, n), r = t.substring(n), f = s.length > 0 && !s.endsWith(" ") && !s.endsWith("(") ? " " : "";
|
|
116
|
+
return s + f + e.insertText + r;
|
|
117
|
+
}
|
|
118
|
+
function N() {
|
|
119
|
+
return R(v.value, c.value);
|
|
120
|
+
}
|
|
121
|
+
function U(e) {
|
|
122
|
+
return b.value.some((t) => e >= t.start && e < t.end);
|
|
123
|
+
}
|
|
124
|
+
function X(e) {
|
|
125
|
+
return b.value.filter((t) => e >= t.start && e < t.end);
|
|
126
|
+
}
|
|
127
|
+
return ne(
|
|
128
|
+
i,
|
|
129
|
+
(e) => {
|
|
130
|
+
e !== void 0 && z(e);
|
|
131
|
+
},
|
|
132
|
+
{ immediate: !0 }
|
|
133
|
+
), {
|
|
134
|
+
// State
|
|
135
|
+
tokens: v,
|
|
136
|
+
parseResult: w,
|
|
137
|
+
validationResult: d,
|
|
138
|
+
cursorPosition: c,
|
|
139
|
+
completionItems: m,
|
|
140
|
+
showAutocomplete: T,
|
|
141
|
+
isValidating: A,
|
|
142
|
+
// Computed
|
|
143
|
+
isValid: Q,
|
|
144
|
+
errors: b,
|
|
145
|
+
warnings: P,
|
|
146
|
+
hasErrors: _,
|
|
147
|
+
hasWarnings: $,
|
|
148
|
+
// Methods
|
|
149
|
+
tokenize: E,
|
|
150
|
+
parse: B,
|
|
151
|
+
validate: M,
|
|
152
|
+
updateCompletions: I,
|
|
153
|
+
triggerAutocomplete: H,
|
|
154
|
+
hideAutocomplete: W,
|
|
155
|
+
handleInput: z,
|
|
156
|
+
handleCursorChange: J,
|
|
157
|
+
insertCompletion: K,
|
|
158
|
+
insertSnippet: L,
|
|
159
|
+
getTokenAtCursor: N,
|
|
160
|
+
isPositionInError: U,
|
|
161
|
+
getErrorsAtPosition: X
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
me as useTqlInput
|
|
166
|
+
};
|