@tellaro/tql 1.4.0 → 1.4.2

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.
@@ -1,14 +1,14 @@
1
- import { defineComponent as st, ref as $, computed as k, onMounted as nt, watch as rt, openBlock as C, createElementBlock as M, normalizeStyle as it, createElementVNode as D, toDisplayString as O, createCommentVNode as ot, nextTick as ct } from "vue";
2
- import { Chart as b, Title as ut, Tooltip as ft, Legend as pt, Filler as dt, BarElement as mt, BarController as ht, LineElement as yt, LineController as gt, PointElement as vt, ArcElement as bt, PieController as xt, DoughnutController as kt, CategoryScale as _t, LinearScale as St, TimeScale as Tt } from "../node_modules/chart.js/dist/chart.js";
1
+ import { defineComponent as at, ref as $, computed as S, onMounted as st, watch as nt, openBlock as M, createElementBlock as w, normalizeStyle as rt, createElementVNode as D, toDisplayString as O, createCommentVNode as it, nextTick as ot } from "vue";
2
+ import { Chart as x, Title as ct, Tooltip as ut, Legend as ft, Filler as pt, BarElement as dt, BarController as mt, LineElement as ht, LineController as yt, PointElement as gt, ArcElement as vt, PieController as bt, DoughnutController as xt, CategoryScale as kt, LinearScale as _t, TimeScale as St } from "../node_modules/chart.js/dist/chart.js";
3
3
  import { formatValue as G } from "../src/chart/formatters.js";
4
- import { extractScalarValue as J, buildChartData as Ct, buildChartOptions as Mt, isTimeSeriesData as wt, isLinkTemplateSafe as Pt, expandLinkTemplate as Lt, chartJsType as K } from "../src/chart/mappers.js";
5
- const At = {
4
+ import { extractScalarValue as J, buildChartData as Tt, buildChartOptions as Ct, isTimeSeriesData as Mt, isLinkTemplateSafe as wt, expandLinkTemplate as Lt, chartJsType as K } from "../src/chart/mappers.js";
5
+ const Pt = {
6
6
  key: 0,
7
7
  class: "tql-chart__metric"
8
8
  }, Ft = { class: "tql-chart__metric-value" }, Nt = {
9
9
  key: 0,
10
10
  class: "tql-chart__metric-title"
11
- }, Rt = /* @__PURE__ */ st({
11
+ }, Ht = /* @__PURE__ */ at({
12
12
  __name: "TqlChart",
13
13
  props: {
14
14
  result: {},
@@ -18,7 +18,8 @@ const At = {
18
18
  },
19
19
  emits: ["drilldown"],
20
20
  setup(E, { emit: U }) {
21
- b.register(
21
+ x.register(
22
+ ct,
22
23
  ut,
23
24
  ft,
24
25
  pt,
@@ -32,19 +33,14 @@ const At = {
32
33
  xt,
33
34
  kt,
34
35
  _t,
35
- St,
36
- Tt
36
+ St
37
37
  );
38
- let w = null, X = null, P = !1, I = !1;
39
- async function Y() {
38
+ let L = null, P = !1, I = !1;
39
+ async function X() {
40
40
  if (!I) {
41
41
  I = !0;
42
42
  try {
43
- w = (await import("../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.esm.js")).default;
44
- } catch {
45
- }
46
- try {
47
- X = (await import("../node_modules/chartjs-plugin-annotation/dist/chartjs-plugin-annotation.esm.js")).default;
43
+ L = (await import("../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.esm.js")).default;
48
44
  } catch {
49
45
  }
50
46
  if (!P)
@@ -54,146 +50,146 @@ const At = {
54
50
  }
55
51
  }
56
52
  }
57
- b.defaults.color = "#888", b.defaults.borderColor = "#ffffff0a", b.defaults.font.family = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
58
- const l = E, j = U, m = $(null), L = $(null);
53
+ x.defaults.color = "#888", x.defaults.borderColor = "#ffffff0a", x.defaults.font.family = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
54
+ const e = E, Y = U, m = $(null), F = $(null);
59
55
  let u = null;
60
- const _ = k(() => {
61
- if (l.chartType && l.chartType !== "auto") return l.chartType;
62
- if (l.result.viz_hint) return l.result.viz_hint;
63
- const a = l.result.stats;
64
- return a && a.type === "stats" && !a.group_by ? "number" : "bar";
65
- }), A = k(() => _.value === "number"), Q = k(() => _.value === "gauge"), Z = k(() => {
66
- if (!A.value) return "";
67
- const a = l.result.stats, t = J(a), e = l.result.viz_params?.format;
68
- return e ? G(t, e) : t >= 1e6 ? (t / 1e6).toFixed(1) + "M" : t >= 1e4 ? (t / 1e3).toFixed(1) + "K" : Number.isInteger(t) ? t.toLocaleString() : t.toFixed(2);
69
- }), B = k(() => l.result.viz_params?.title || "");
70
- function tt(a) {
71
- if (!l.drilldown || !u) return;
72
- const t = u.getElementsAtEventForMode(a, "nearest", { intersect: !0 }, !1);
56
+ const T = S(() => {
57
+ if (e.chartType && e.chartType !== "auto") return e.chartType;
58
+ if (e.result.viz_hint) return e.result.viz_hint;
59
+ const l = e.result.stats;
60
+ return l && l.type === "stats" && !l.group_by ? "number" : "bar";
61
+ }), N = S(() => T.value === "number"), j = S(() => T.value === "gauge"), Q = S(() => {
62
+ if (!N.value) return "";
63
+ const l = e.result.stats, t = J(l), a = e.result.viz_params?.format;
64
+ return a ? G(t, a) : t >= 1e6 ? (t / 1e6).toFixed(1) + "M" : t >= 1e4 ? (t / 1e3).toFixed(1) + "K" : Number.isInteger(t) ? t.toLocaleString() : t.toFixed(2);
65
+ }), B = S(() => e.result.viz_params?.title || "");
66
+ function Z(l) {
67
+ if (!e.drilldown || !u) return;
68
+ const t = u.getElementsAtEventForMode(l, "nearest", { intersect: !0 }, !1);
73
69
  if (t.length === 0) return;
74
- const e = t[0], r = e.datasetIndex, n = e.index, d = String(u.data.labels?.[n] ?? ""), y = Number(u.data.datasets[r]?.data?.[n] ?? 0);
75
- j("drilldown", {
70
+ const a = t[0], o = a.datasetIndex, n = a.index, d = String(u.data.labels?.[n] ?? ""), v = Number(u.data.datasets[o]?.data?.[n] ?? 0);
71
+ Y("drilldown", {
76
72
  label: d,
77
- value: y,
73
+ value: v,
78
74
  index: n,
79
- field: l.result.stats.group_by?.[0],
80
- chartType: _.value
75
+ field: e.result.stats.group_by?.[0],
76
+ chartType: T.value
81
77
  });
82
78
  }
83
- function et() {
84
- const a = m.value;
85
- if (!a) return;
86
- const t = a.getContext("2d");
79
+ function tt() {
80
+ const l = m.value;
81
+ if (!l) return;
82
+ const t = l.getContext("2d");
87
83
  if (!t) return;
88
- const e = l.result.viz_params || {}, r = J(l.result.stats), n = Number(e.y_min ?? 0), d = Number(e.y_max ?? 100), y = Math.max(0, Math.min(1, (r - n) / (d - n))), x = e.ranges, g = [];
89
- if (x)
90
- for (const p of x.split(",")) {
91
- const [T, v] = p.split(":");
92
- if (T && v) {
93
- const [V, W] = T.split("-").map(Number);
94
- !isNaN(V) && !isNaN(W) && g.push({ from: V, to: W, color: v.startsWith("#") ? v : `#${v}` });
84
+ const a = e.result.viz_params || {}, o = J(e.result.stats), n = Number(a.y_min ?? 0), d = Number(a.y_max ?? 100), v = Math.max(0, Math.min(1, (o - n) / (d - n))), k = a.ranges, h = [];
85
+ if (k)
86
+ for (const p of k.split(",")) {
87
+ const [C, b] = p.split(":");
88
+ if (C && b) {
89
+ const [V, W] = C.split("-").map(Number);
90
+ !isNaN(V) && !isNaN(W) && h.push({ from: V, to: W, color: b.startsWith("#") ? b : `#${b}` });
95
91
  }
96
92
  }
97
- const h = a.width = a.parentElement?.clientWidth || 400, o = a.height = 240, s = h / 2, f = o - 40, c = Math.min(h / 2 - 30, o - 60), i = Math.PI, S = 2 * Math.PI;
98
- if (t.clearRect(0, 0, h, o), t.beginPath(), t.arc(s, f, c, i, S), t.lineWidth = 24, t.strokeStyle = "#333", t.lineCap = "round", t.stroke(), g.length > 0)
99
- for (const p of g) {
100
- const T = i + (p.from - n) / (d - n) * Math.PI, v = i + (p.to - n) / (d - n) * Math.PI;
101
- t.beginPath(), t.arc(s, f, c, T, Math.min(v, S)), t.lineWidth = 24, t.strokeStyle = p.color + "66", t.lineCap = "butt", t.stroke();
93
+ const r = l.width = l.parentElement?.clientWidth || 400, y = l.height = 240, i = r / 2, s = y - 40, g = Math.min(r / 2 - 30, y - 60), c = Math.PI, f = 2 * Math.PI;
94
+ if (t.clearRect(0, 0, r, y), t.beginPath(), t.arc(i, s, g, c, f), t.lineWidth = 24, t.strokeStyle = "#333", t.lineCap = "round", t.stroke(), h.length > 0)
95
+ for (const p of h) {
96
+ const C = c + (p.from - n) / (d - n) * Math.PI, b = c + (p.to - n) / (d - n) * Math.PI;
97
+ t.beginPath(), t.arc(i, s, g, C, Math.min(b, f)), t.lineWidth = 24, t.strokeStyle = p.color + "66", t.lineCap = "butt", t.stroke();
102
98
  }
103
- const F = i + y * Math.PI;
104
- let N = "#818cf8";
105
- if (g.length > 0) {
106
- for (const p of g)
107
- if (r >= p.from && r <= p.to) {
108
- N = p.color;
99
+ const A = c + v * Math.PI;
100
+ let _ = "#818cf8";
101
+ if (h.length > 0) {
102
+ for (const p of h)
103
+ if (o >= p.from && o <= p.to) {
104
+ _ = p.color;
109
105
  break;
110
106
  }
111
107
  }
112
- t.beginPath(), t.arc(s, f, c, i, F), t.lineWidth = 24, t.strokeStyle = N, t.lineCap = "round", t.stroke();
113
- const q = e.title || "", z = e.format, at = z ? G(r, z) : Number.isInteger(r) ? r.toLocaleString() : r.toFixed(1);
114
- t.fillStyle = N, t.font = "bold 36px -apple-system, BlinkMacSystemFont, sans-serif", t.textAlign = "center", t.fillText(String(at), s, f - 10), q && (t.fillStyle = "#888", t.font = "13px -apple-system, BlinkMacSystemFont, sans-serif", t.fillText(q, s, f + 18)), t.fillStyle = "#555", t.font = "11px -apple-system, BlinkMacSystemFont, sans-serif", t.textAlign = "left", t.fillText(String(n), s - c - 5, f + 18), t.textAlign = "right", t.fillText(String(d), s + c + 5, f + 18);
108
+ t.beginPath(), t.arc(i, s, g, c, A), t.lineWidth = 24, t.strokeStyle = _, t.lineCap = "round", t.stroke();
109
+ const q = a.title || "", z = a.format, lt = z ? G(o, z) : Number.isInteger(o) ? o.toLocaleString() : o.toFixed(1);
110
+ t.fillStyle = _, t.font = "bold 36px -apple-system, BlinkMacSystemFont, sans-serif", t.textAlign = "center", t.fillText(String(lt), i, s - 10), q && (t.fillStyle = "#888", t.font = "13px -apple-system, BlinkMacSystemFont, sans-serif", t.fillText(q, i, s + 18)), t.fillStyle = "#555", t.font = "11px -apple-system, BlinkMacSystemFont, sans-serif", t.textAlign = "left", t.fillText(String(n), i - g - 5, s + 18), t.textAlign = "right", t.fillText(String(d), i + g + 5, s + 18);
115
111
  }
116
- function lt() {
117
- if (!m.value || A.value) return;
118
- if (Q.value) {
119
- et();
112
+ function et() {
113
+ if (!m.value || N.value) return;
114
+ if (j.value) {
115
+ tt();
120
116
  return;
121
117
  }
122
118
  u && (u.destroy(), u = null);
123
- const a = _.value, t = Ct(l.result, a), e = Mt(l.result, a);
124
- l.drilldown && (e.onClick = tt, m.value && (m.value.style.cursor = "pointer"));
125
- const r = [], n = l.result.viz_params || {}, d = n.labels === !0 || n.labels === "true" || n.labels === "minmax";
126
- w && d && r.push(w);
127
- const y = [...t.labels], x = e.indexAxis === "y";
128
- P && wt(l.result.stats) && e?.scales?.x && !x ? e.scales.x = {
129
- ...e.scales.x,
119
+ const l = T.value, t = Tt(e.result, l), a = Ct(e.result, l);
120
+ e.drilldown && (a.onClick = Z, m.value && (m.value.style.cursor = "pointer"));
121
+ const o = [], n = e.result.viz_params || {}, d = n.labels === !0 || n.labels === "true" || n.labels === "minmax";
122
+ L && d && o.push(L);
123
+ const v = [...t.labels], k = a.indexAxis === "y", h = P && Mt(e.result.stats), r = a;
124
+ h && r?.scales?.x && !k ? r.scales.x = {
125
+ ...r.scales.x,
130
126
  type: "time",
131
127
  time: { tooltipFormat: "HH:mm", displayFormats: { minute: "HH:mm", hour: "HH:mm", day: "MMM d" } },
132
- ticks: { ...e.scales.x.ticks, maxRotation: 0, autoSkip: !0, maxTicksLimit: 10 }
133
- } : x ? e?.scales?.y && !e.scales.y.ticks?.callback && (e.scales.y.ticks = {
134
- ...e.scales.y.ticks,
135
- callback: function(o, s) {
136
- return y[s] ?? s;
128
+ ticks: { ...r.scales.x.ticks, maxRotation: 0, autoSkip: !0, maxTicksLimit: 10 }
129
+ } : k ? r?.scales?.y && !r.scales.y.ticks?.callback && (r.scales.y.ticks = {
130
+ ...r.scales.y.ticks,
131
+ callback: function(i, s) {
132
+ return v[s] ?? s;
137
133
  }
138
- }) : e?.scales?.x && !e.scales.x.ticks?.callback && (e.scales.x.ticks = {
139
- ...e.scales.x.ticks,
140
- callback: function(o, s) {
141
- return y[s] ?? s;
134
+ }) : r?.scales?.x && !r.scales.x.ticks?.callback && (r.scales.x.ticks = {
135
+ ...r.scales.x.ticks,
136
+ callback: function(i, s) {
137
+ return v[s] ?? s;
142
138
  }
143
139
  });
144
- const h = n.link;
145
- if (h && Pt(h) && L.value) {
146
- const o = n.link_target || "_self", s = L.value;
147
- e.plugins = {
148
- ...e.plugins,
140
+ const y = n.link;
141
+ if (y && wt(y) && F.value) {
142
+ const i = n.link_target || "_self", s = F.value;
143
+ a.plugins = {
144
+ ...a.plugins,
149
145
  tooltip: {
150
146
  enabled: !1,
151
- external: (f) => {
152
- const { tooltip: c } = f;
147
+ external: (g) => {
148
+ const { tooltip: c } = g;
153
149
  if (c.opacity === 0) {
154
150
  s.style.opacity = "0";
155
151
  return;
156
152
  }
157
- const i = c.dataPoints?.[0];
158
- if (!i) return;
159
- const S = Lt(h, {
160
- value: i.label,
161
- label: i.label,
162
- field: l.result.stats.group_by?.[0],
163
- count: i.raw
164
- }), F = o === "_blank" ? ' rel="noopener noreferrer"' : "";
165
- s.innerHTML = `<div class="tt-title">${i.label}</div><div class="tt-val">${i.formattedValue}</div><a href="${S}" target="${o}"${F} class="tt-link">Open link &rarr;</a>`, s.style.opacity = "1", s.style.left = c.caretX + "px", s.style.top = c.caretY + "px";
153
+ const f = c.dataPoints?.[0];
154
+ if (!f) return;
155
+ const A = Lt(y, {
156
+ value: f.label,
157
+ label: f.label,
158
+ field: e.result.stats.group_by?.[0],
159
+ count: f.raw
160
+ }), _ = i === "_blank" ? ' rel="noopener noreferrer"' : "";
161
+ s.innerHTML = `<div class="tt-title">${f.label}</div><div class="tt-val">${f.formattedValue}</div><a href="${A}" target="${i}"${_} class="tt-link">Open link &rarr;</a>`, s.style.opacity = "1", s.style.left = c.caretX + "px", s.style.top = c.caretY + "px";
166
162
  }
167
163
  }
168
164
  };
169
165
  }
170
166
  try {
171
- u = new b(m.value, {
172
- type: K(a),
167
+ u = new x(m.value, {
168
+ type: K(l),
173
169
  data: { labels: t.labels, datasets: t.datasets },
174
- options: e,
175
- plugins: r
170
+ options: a,
171
+ plugins: o
176
172
  });
177
- } catch (o) {
178
- console.warn("[TqlChart] Plugin error, rendering without plugins:", o), u = new b(m.value, {
179
- type: K(a),
173
+ } catch (i) {
174
+ console.warn("[TqlChart] Plugin error, rendering without plugins:", i), u = new x(m.value, {
175
+ type: K(l),
180
176
  data: { labels: t.labels, datasets: t.datasets },
181
- options: e
177
+ options: a
182
178
  });
183
179
  }
184
180
  }
185
181
  let H = !1;
186
182
  async function R() {
187
- H || (await Y(), H = !0), ct(lt);
183
+ H || (await X(), H = !0), ot(et);
188
184
  }
189
- return nt(R), rt(() => [l.result, l.chartType], () => R(), { deep: !0 }), (a, t) => (C(), M("div", {
185
+ return st(R), nt(() => [e.result, e.chartType], () => R(), { deep: !0 }), (l, t) => (M(), w("div", {
190
186
  class: "tql-chart",
191
- style: it({ height: E.height })
187
+ style: rt({ height: E.height })
192
188
  }, [
193
- A.value ? (C(), M("div", At, [
194
- D("span", Ft, O(Z.value), 1),
195
- B.value ? (C(), M("span", Nt, O(B.value), 1)) : ot("", !0)
196
- ])) : (C(), M("canvas", {
189
+ N.value ? (M(), w("div", Pt, [
190
+ D("span", Ft, O(Q.value), 1),
191
+ B.value ? (M(), w("span", Nt, O(B.value), 1)) : it("", !0)
192
+ ])) : (M(), w("canvas", {
197
193
  key: 1,
198
194
  ref_key: "canvasRef",
199
195
  ref: m,
@@ -201,12 +197,12 @@ const At = {
201
197
  }, null, 512)),
202
198
  D("div", {
203
199
  ref_key: "tooltipRef",
204
- ref: L,
200
+ ref: F,
205
201
  class: "tql-chart__tooltip"
206
202
  }, null, 512)
207
203
  ], 4));
208
204
  }
209
205
  });
210
206
  export {
211
- Rt as default
207
+ Ht as default
212
208
  };
@@ -2,7 +2,7 @@ import o from "./TqlInput.vue2.js";
2
2
  /* empty css */
3
3
  /* empty css */
4
4
  import t from "../_virtual/_plugin-vue_export-helper.js";
5
- const a = /* @__PURE__ */ t(o, [["__scopeId", "data-v-2eb7c399"]]);
5
+ const _ = /* @__PURE__ */ t(o, [["__scopeId", "data-v-b501ae88"]]);
6
6
  export {
7
- a as default
7
+ _ as default
8
8
  };
@@ -1,9 +1,9 @@
1
- import e from "./TqlPreview.vue2.js";
1
+ import o from "./TqlPreview.vue2.js";
2
2
  import { TqlPreviewNode as i } from "./TqlPreview.vue2.js";
3
3
  /* empty css */
4
- import o from "../../_virtual/_plugin-vue_export-helper.js";
5
- const p = /* @__PURE__ */ o(e, [["__scopeId", "data-v-bae811e6"]]);
4
+ import r from "../../_virtual/_plugin-vue_export-helper.js";
5
+ const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-3521fa37"]]);
6
6
  export {
7
7
  i as TqlPreviewNode,
8
- p as default
8
+ m as default
9
9
  };
@@ -0,0 +1,54 @@
1
+ import { Ref } from 'vue';
2
+ import { TqlCompletionItem, TqlFieldSchema, TqlParseResult, TqlSnippet, TqlToken, TqlValidationResult } from '../src/types';
3
+ export interface UseTqlInputOptions {
4
+ modelValue: Ref<string>;
5
+ fieldSchema?: Ref<TqlFieldSchema[] | undefined>;
6
+ snippets?: Ref<TqlSnippet[] | undefined>;
7
+ fieldValues?: Ref<Record<string, string[]> | undefined>;
8
+ validateOnInput?: boolean;
9
+ /** Debounce time for validation in ms (default: 300) */
10
+ debounceMs?: number;
11
+ /** Debounce time for completions in ms (default: 50, faster than validation) */
12
+ completionDebounceMs?: number;
13
+ autocomplete?: boolean;
14
+ onValidation?: (result: TqlValidationResult) => void;
15
+ onParse?: (result: TqlParseResult) => void;
16
+ }
17
+ /**
18
+ * Placeholder position for tab-stop navigation (used in insertCompletion return value)
19
+ */
20
+ export interface PlaceholderPosition {
21
+ start: number;
22
+ end: number;
23
+ }
24
+ export declare function useTqlInput(options: UseTqlInputOptions): {
25
+ tokens: any;
26
+ parseResult: any;
27
+ validationResult: any;
28
+ cursorPosition: any;
29
+ completionItems: any;
30
+ showAutocomplete: any;
31
+ isValidating: any;
32
+ isValid: any;
33
+ errors: any;
34
+ warnings: any;
35
+ hasErrors: any;
36
+ hasWarnings: any;
37
+ tokenize: () => any;
38
+ parse: () => TqlParseResult;
39
+ validate: () => TqlValidationResult;
40
+ updateCompletions: () => void;
41
+ triggerAutocomplete: () => void;
42
+ hideAutocomplete: () => void;
43
+ handleInput: (value: string) => void;
44
+ handleCursorChange: (position: number) => void;
45
+ insertCompletion: (item: TqlCompletionItem) => {
46
+ query: string;
47
+ newCursorPosition: number;
48
+ placeholders: PlaceholderPosition[];
49
+ };
50
+ insertSnippet: (snippet: TqlSnippet) => string;
51
+ getTokenAtCursor: () => TqlToken | null;
52
+ isPositionInError: (position: number) => boolean;
53
+ getErrorsAtPosition: (position: number) => any;
54
+ };