postgres-query-box 0.0.0-stage → 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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +178 -2
- package/dist/chunk-VMCU5JEN.js +1196 -0
- package/dist/chunk-VMCU5JEN.js.map +1 -0
- package/dist/core.cjs +1235 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +84 -0
- package/dist/core.d.ts +84 -0
- package/dist/core.js +45 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +2555 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +1357 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +313 -0
- package/package.json +83 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1357 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILD_OPS,
|
|
3
|
+
LATENCY,
|
|
4
|
+
LAT_FIELD,
|
|
5
|
+
METHODS,
|
|
6
|
+
OP_INFO,
|
|
7
|
+
STATUS_CODES,
|
|
8
|
+
TYPE_LABEL,
|
|
9
|
+
arity,
|
|
10
|
+
buildSchema,
|
|
11
|
+
context,
|
|
12
|
+
evaluate,
|
|
13
|
+
format,
|
|
14
|
+
fromTree,
|
|
15
|
+
ipToBig,
|
|
16
|
+
isComplete,
|
|
17
|
+
newCond,
|
|
18
|
+
opsFor,
|
|
19
|
+
parse,
|
|
20
|
+
parseRange,
|
|
21
|
+
schemaFromFields,
|
|
22
|
+
toSql,
|
|
23
|
+
toTree,
|
|
24
|
+
tokenize,
|
|
25
|
+
validate
|
|
26
|
+
} from "./chunk-VMCU5JEN.js";
|
|
27
|
+
|
|
28
|
+
// src/react/PostgresQueryBox.jsx
|
|
29
|
+
import { forwardRef, useEffect as useEffect4, useImperativeHandle, useRef as useRef4, useState as useState4 } from "react";
|
|
30
|
+
import { BookmarksSimple, CaretDown as CaretDown2, Play } from "@phosphor-icons/react";
|
|
31
|
+
|
|
32
|
+
// src/react/QueryBox.jsx
|
|
33
|
+
import { useEffect as useEffect2, useLayoutEffect, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
34
|
+
import { Funnel, X as X2, Copy as Copy2, TreeStructure, TextT as TextT2, Hash as Hash2, ToggleLeft as ToggleLeft2, Globe as Globe2, Timer as Timer2, Warning as Warning2 } from "@phosphor-icons/react";
|
|
35
|
+
|
|
36
|
+
// src/react/Builder.jsx
|
|
37
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
38
|
+
import * as P from "@phosphor-icons/react";
|
|
39
|
+
|
|
40
|
+
// src/react/colors.js
|
|
41
|
+
var VERB = { GET: "#147af3", POST: "#2fb880", PUT: "#b07500", PATCH: "#9d57f4", DELETE: "#ea3829", OPTIONS: "#626978", HEAD: "#626978", TRACE: "#626978", CONNECT: "#626978", QUERY: "#626978" };
|
|
42
|
+
var TONE = { 1: ["#147af3", "#e0f2ff"], 2: ["#00653e", "#cef8e0"], 3: ["#4046ca", "#d3d5ff"], 4: ["#b40000", "#ffcdc3"], 5: ["#cb5d00", "#ffeccc"] };
|
|
43
|
+
var valueStyle = (v, field) => {
|
|
44
|
+
const s = String(v);
|
|
45
|
+
if ((!field || field === "data.request.verb") && VERB[s]) return { color: VERB[s], fontWeight: 600 };
|
|
46
|
+
const t = (!field || field === "data.response.statusCode") && /^\d{3}$/.test(s) && TONE[s[0]];
|
|
47
|
+
return t ? { color: t[0], background: t[1], boxShadow: "inset 0 0 0 1px #cdd2dd", borderRadius: 2 } : null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/react/Builder.jsx
|
|
51
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
52
|
+
var TYPE_ICON = { string: P.TextT, numtext: P.TextT, ip: P.Globe, number: P.Hash, boolean: P.ToggleLeft, latency: P.Timer };
|
|
53
|
+
var EXAMPLE = {
|
|
54
|
+
"==": '"GET"',
|
|
55
|
+
"!=": '"200"',
|
|
56
|
+
ANYONE: '["POST", "PUT"]',
|
|
57
|
+
NONEOF: '["GET", "HEAD"]',
|
|
58
|
+
"<": "1024",
|
|
59
|
+
"<=": "5000",
|
|
60
|
+
">": "399",
|
|
61
|
+
">=": "500",
|
|
62
|
+
BETWEEN: "200 AND 299",
|
|
63
|
+
CONTAINS: '"agent-registry"',
|
|
64
|
+
"NOT CONTAINS": '"node"',
|
|
65
|
+
"~": '"^/api/v1/"',
|
|
66
|
+
"!~": '"/health$"',
|
|
67
|
+
PRESENT: "no value",
|
|
68
|
+
ABSENT: "no value",
|
|
69
|
+
"IP IN_RANGE": '"10.0.0.0/8"',
|
|
70
|
+
"IP NOT_IN_RANGE": '["10.0.0.0/8"]'
|
|
71
|
+
};
|
|
72
|
+
var HINT = { "data.request.verb": "Method", "data.response.statusCode": "Status code", "data.request.path": "Path", "data.request.hostname": "Host" };
|
|
73
|
+
var CATALOG = { "data.request.verb": METHODS, "data.response.statusCode": STATUS_CODES };
|
|
74
|
+
var INPUT = "h-7 min-w-0 rounded-md border border-stroke-subsection bg-transparent px-1.5 hover:border-stroke-section font-mono text-code-editor-small text-text-default-regular outline-none placeholder:font-sans placeholder:text-text-default-disabled focus:border-stroke-active";
|
|
75
|
+
var ACT = "grid h-7 w-7 place-items-center rounded text-icon-default hover:bg-surface-hover-l1-hover";
|
|
76
|
+
var typeOf = (field, schema) => {
|
|
77
|
+
var _a;
|
|
78
|
+
return field === "@latency" ? "latency" : ((_a = schema.byPath[field]) == null ? void 0 : _a.type) || "string";
|
|
79
|
+
};
|
|
80
|
+
var update = (g, id, fn) => ({ ...g, items: g.items.map((x) => x.id === id ? fn(x) : x.kind === "group" ? update(x, id, fn) : x) });
|
|
81
|
+
var remove = (g, id) => ({ ...g, items: g.items.filter((x) => x.id !== id).map((x) => x.kind === "group" ? remove(x, id) : x) });
|
|
82
|
+
var tidy = (g, top) => {
|
|
83
|
+
const items = g.items.map((x) => x.kind === "group" ? tidy(x, false) : x).filter((x) => x && (x.kind !== "group" || x.items.length));
|
|
84
|
+
if (!top && items.length === 1 && !g.not) return items[0];
|
|
85
|
+
return { ...g, items };
|
|
86
|
+
};
|
|
87
|
+
var insertAfter = (g, id, item) => {
|
|
88
|
+
const i = g.items.findIndex((x) => x.id === id);
|
|
89
|
+
if (i >= 0) return { ...g, items: [...g.items.slice(0, i + 1), item, ...g.items.slice(i + 1)] };
|
|
90
|
+
return { ...g, items: g.items.map((x) => x.kind === "group" ? insertAfter(x, id, item) : x) };
|
|
91
|
+
};
|
|
92
|
+
var clone = (x) => x.kind === "group" ? { ...x, id: newCond().id, items: x.items.map(clone) } : { ...x, id: newCond().id, values: [...x.values] };
|
|
93
|
+
function Menu({ anchor, width, onClose, children }) {
|
|
94
|
+
const ref = useRef(null);
|
|
95
|
+
const close = useRef(onClose);
|
|
96
|
+
close.current = onClose;
|
|
97
|
+
const [pos, setPos] = useState(null);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const onClose2 = () => close.current();
|
|
100
|
+
const r = anchor.current.getBoundingClientRect();
|
|
101
|
+
const below = r.bottom + 360 < window.innerHeight;
|
|
102
|
+
setPos({ left: Math.min(r.left, window.innerWidth - width - 8), top: below ? r.bottom + 4 : void 0, bottom: below ? void 0 : window.innerHeight - r.top + 4 });
|
|
103
|
+
const out = (e) => {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return !((_a = ref.current) == null ? void 0 : _a.contains(e.target)) && !((_b = anchor.current) == null ? void 0 : _b.contains(e.target)) && onClose2();
|
|
106
|
+
};
|
|
107
|
+
const key = (e) => e.key === "Escape" && onClose2();
|
|
108
|
+
const scroll = (e) => {
|
|
109
|
+
var _a;
|
|
110
|
+
return !((_a = ref.current) == null ? void 0 : _a.contains(e.target)) && onClose2();
|
|
111
|
+
};
|
|
112
|
+
document.addEventListener("mousedown", out, true);
|
|
113
|
+
document.addEventListener("keydown", key);
|
|
114
|
+
document.addEventListener("scroll", scroll, true);
|
|
115
|
+
return () => {
|
|
116
|
+
document.removeEventListener("mousedown", out, true);
|
|
117
|
+
document.removeEventListener("keydown", key);
|
|
118
|
+
document.removeEventListener("scroll", scroll, true);
|
|
119
|
+
};
|
|
120
|
+
}, []);
|
|
121
|
+
if (!pos) return null;
|
|
122
|
+
return /* @__PURE__ */ jsx("div", { ref, style: { position: "fixed", zIndex: 70, width, ...pos }, className: "rounded-md border border-stroke-subsection bg-surface-default-l1 shadow-e300", children });
|
|
123
|
+
}
|
|
124
|
+
function FieldPicker({ value, schema, onPick, autoOpen, placeholder = "Add field" }) {
|
|
125
|
+
const btn = useRef(null);
|
|
126
|
+
const [open, setOpen] = useState(autoOpen);
|
|
127
|
+
const [q, setQ] = useState("");
|
|
128
|
+
const x = q.trim().toLowerCase();
|
|
129
|
+
const common = [...schema.fields.filter((f) => f.group === "Common").map((f) => ({ path: f.path, hint: HINT[f.path] || "" })), { path: "@latency", hint: "Latency in ms" }].filter((c) => !x || (c.path === "@latency" ? LATENCY : c.path).toLowerCase().includes(x) || c.hint.toLowerCase().includes(x));
|
|
130
|
+
const all = schema.fields.filter((f) => f.group !== "Common" && (!x || f.path.toLowerCase().includes(x))).slice(0, 80);
|
|
131
|
+
const pick = (p) => {
|
|
132
|
+
onPick(p);
|
|
133
|
+
setOpen(false);
|
|
134
|
+
setQ("");
|
|
135
|
+
};
|
|
136
|
+
const label = value === "@latency" ? LATENCY : value;
|
|
137
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative min-w-0 shrink", children: [
|
|
138
|
+
/* @__PURE__ */ jsx("button", { ref: btn, onClick: () => setOpen(!open), "aria-expanded": open, "data-pqb-tip": value ? void 0 : "Pick a field", className: `flex h-7 max-w-[440px] items-center rounded-md border text-left ${value ? `px-1 ${open ? "border-stroke-active bg-surface-default-ground" : "border-transparent hover:bg-surface-hover-l1-hover"}` : `border-dashed bg-surface-default-ground px-2 ${open ? "border-stroke-active" : "border-stroke-section hover:border-stroke-active"}`}`, children: /* @__PURE__ */ jsx("span", { className: `min-w-0 truncate text-interface-body-s-normal ${value ? "font-mono text-base-blue-1100" : "text-text-default-disabled"}`, children: value ? label : placeholder }) }),
|
|
139
|
+
open && /* @__PURE__ */ jsxs(Menu, { anchor: btn, width: 420, onClose: () => setOpen(false), children: [
|
|
140
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-9 items-center gap-1.5 border-b border-stroke-subsection px-2.5", children: [
|
|
141
|
+
/* @__PURE__ */ jsx(P.MagnifyingGlass, { size: 14, className: "text-icon-default" }),
|
|
142
|
+
/* @__PURE__ */ jsx(
|
|
143
|
+
"input",
|
|
144
|
+
{
|
|
145
|
+
autoFocus: true,
|
|
146
|
+
value: q,
|
|
147
|
+
onChange: (e) => setQ(e.target.value),
|
|
148
|
+
placeholder: `Search ${schema.fields.length} fields`,
|
|
149
|
+
onKeyDown: (e) => {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
if (e.key === "Enter") {
|
|
152
|
+
const p = ((_a = common[0]) == null ? void 0 : _a.path) ?? ((_b = all[0]) == null ? void 0 : _b.path);
|
|
153
|
+
if (p) pick(p);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
className: "min-w-0 flex-1 bg-transparent text-interface-body-s-normal text-text-default-regular outline-none placeholder:text-text-default-disabled"
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
] }),
|
|
160
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-[280px] overflow-y-auto no-scrollbar pb-1", children: [
|
|
161
|
+
[["Common", common], ...Object.entries(all.reduce((g, f) => ((g[f.group] ||= []).push(f), g), {}))].filter(([, list]) => list.length).map(([g, list]) => /* @__PURE__ */ jsxs("div", { children: [
|
|
162
|
+
/* @__PURE__ */ jsxs("p", { style: { position: "sticky", top: 0, zIndex: 1 }, className: "flex items-center justify-between gap-3 bg-surface-default-l1 px-2.5 pb-0.5 pt-1.5 text-interface-titles-caption text-text-default-subdued", children: [
|
|
163
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: `FIELDS / ${g}`.toUpperCase() }),
|
|
164
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 text-interface-labels-xs-normal text-text-default-subtle", children: list.length })
|
|
165
|
+
] }),
|
|
166
|
+
g === "Common" ? list.map((c) => {
|
|
167
|
+
var _a;
|
|
168
|
+
const Icon = TYPE_ICON[c.path === "@latency" ? "latency" : (_a = schema.byPath[c.path]) == null ? void 0 : _a.type] || P.TextT;
|
|
169
|
+
return /* @__PURE__ */ jsxs("button", { onClick: () => pick(c.path), className: "flex w-full items-center gap-2 px-2.5 py-1 text-left hover:bg-surface-hover-l1-hover", children: [
|
|
170
|
+
/* @__PURE__ */ jsx(Icon, { size: 12, className: "shrink-0 text-icon-subtle" }),
|
|
171
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate font-mono text-code-editor-small text-text-default-regular", children: c.path === "@latency" ? LATENCY : c.path }),
|
|
172
|
+
value === c.path && /* @__PURE__ */ jsx(P.Check, { size: 12, className: "shrink-0 text-icon-default" })
|
|
173
|
+
] }, c.path);
|
|
174
|
+
}) : list.map((f) => {
|
|
175
|
+
const Icon = TYPE_ICON[f.type] || P.TextT;
|
|
176
|
+
return /* @__PURE__ */ jsxs("button", { onClick: () => pick(f.path), className: "flex w-full items-center gap-2 px-2.5 py-1 text-left hover:bg-surface-hover-l1-hover", children: [
|
|
177
|
+
/* @__PURE__ */ jsx(Icon, { size: 12, className: "shrink-0 text-icon-subtle" }),
|
|
178
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate font-mono text-code-editor-small text-text-default-regular", children: f.path }),
|
|
179
|
+
value === f.path && /* @__PURE__ */ jsx(P.Check, { size: 12, className: "shrink-0 text-icon-default" })
|
|
180
|
+
] }, f.path);
|
|
181
|
+
})
|
|
182
|
+
] }, g)),
|
|
183
|
+
!common.length && !all.length && /* @__PURE__ */ jsxs("p", { className: "px-2.5 py-2 text-interface-body-s-light text-text-default-subdued", children: [
|
|
184
|
+
"No field matches \u201C",
|
|
185
|
+
q,
|
|
186
|
+
"\u201D"
|
|
187
|
+
] })
|
|
188
|
+
] })
|
|
189
|
+
] })
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
function OpPicker({ value, type, onPick }) {
|
|
193
|
+
const btn = useRef(null);
|
|
194
|
+
const [open, setOpen] = useState(false);
|
|
195
|
+
const [q, setQ] = useState("");
|
|
196
|
+
const allowed = opsFor({ type });
|
|
197
|
+
const x = q.trim().toLowerCase();
|
|
198
|
+
const groups = BUILD_OPS.map(([name, ops]) => [name, ops.filter((o) => allowed.includes(o) && (!x || `${o} ${OP_INFO[o]}`.toLowerCase().includes(x)))]).filter(([, ops]) => ops.length);
|
|
199
|
+
const pick = (o) => {
|
|
200
|
+
onPick(o);
|
|
201
|
+
setOpen(false);
|
|
202
|
+
setQ("");
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
205
|
+
/* @__PURE__ */ jsx("button", { ref: btn, onClick: () => setOpen(!open), "aria-expanded": open, "data-pqb-tip": OP_INFO[value], className: `mt-[3px] flex h-[22px] min-w-[22px] items-center justify-center rounded px-1.5 bg-surface-color-blue-default-subtle hover:bg-surface-color-blue-hover-subtle ${open ? "ring-1 ring-stroke-active" : ""}`, children: /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap font-mono text-code-editor-small font-semibold text-text-color-blue", children: value }) }),
|
|
206
|
+
open && /* @__PURE__ */ jsxs(Menu, { anchor: btn, width: 320, onClose: () => setOpen(false), children: [
|
|
207
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-9 items-center gap-1.5 border-b border-stroke-subsection px-2.5", children: [
|
|
208
|
+
/* @__PURE__ */ jsx(P.MagnifyingGlass, { size: 14, className: "text-icon-default" }),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
"input",
|
|
211
|
+
{
|
|
212
|
+
autoFocus: true,
|
|
213
|
+
value: q,
|
|
214
|
+
onChange: (e) => setQ(e.target.value),
|
|
215
|
+
placeholder: "Search operators",
|
|
216
|
+
onKeyDown: (e) => e.key === "Enter" && groups[0] && pick(groups[0][1][0]),
|
|
217
|
+
className: "min-w-0 flex-1 bg-transparent text-interface-body-s-normal text-text-default-regular outline-none placeholder:text-text-default-disabled"
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
] }),
|
|
221
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-[320px] overflow-y-auto no-scrollbar py-1", children: [
|
|
222
|
+
groups.map(([name, ops]) => /* @__PURE__ */ jsxs("div", { children: [
|
|
223
|
+
/* @__PURE__ */ jsx("p", { className: "px-2.5 pb-0.5 pt-1.5 text-interface-titles-caption text-text-default-subdued", children: name.toUpperCase() }),
|
|
224
|
+
ops.map((o) => /* @__PURE__ */ jsxs("button", { onClick: () => pick(o), className: `flex w-full items-center gap-2 px-2.5 py-1.5 text-left hover:bg-surface-hover-l1-hover ${o === value ? "bg-surface-color-blue-default-subtle" : ""}`, children: [
|
|
225
|
+
/* @__PURE__ */ jsx("span", { className: "w-[72px] shrink-0 truncate rounded bg-surface-default-underground px-1 py-0.5 text-center font-mono text-code-editor-small text-text-default-subtle", children: o.replace("IP ", "") }),
|
|
226
|
+
/* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
227
|
+
/* @__PURE__ */ jsx("span", { className: "text-interface-body-s-normal text-text-default-regular", children: OP_INFO[o] }),
|
|
228
|
+
/* @__PURE__ */ jsx("span", { className: "truncate font-mono text-interface-labels-xs-light text-text-default-subdued", children: EXAMPLE[o] })
|
|
229
|
+
] }),
|
|
230
|
+
o === value && /* @__PURE__ */ jsx(P.Check, { size: 12, className: "shrink-0 text-icon-default" })
|
|
231
|
+
] }, o))
|
|
232
|
+
] }, name)),
|
|
233
|
+
!groups.length && /* @__PURE__ */ jsxs("p", { className: "px-2.5 py-2 text-interface-body-s-light text-text-default-subdued", children: [
|
|
234
|
+
"No operator matches \u201C",
|
|
235
|
+
q,
|
|
236
|
+
"\u201D"
|
|
237
|
+
] })
|
|
238
|
+
] }),
|
|
239
|
+
/* @__PURE__ */ jsxs("p", { className: "border-t border-stroke-subsection px-2.5 py-1.5 text-interface-labels-xs-light text-text-default-subdued", children: [
|
|
240
|
+
"Showing operators for ",
|
|
241
|
+
TYPE_LABEL[type],
|
|
242
|
+
" fields"
|
|
243
|
+
] })
|
|
244
|
+
] })
|
|
245
|
+
] });
|
|
246
|
+
}
|
|
247
|
+
function Options({ list, value, field, quoted, onPick, children }) {
|
|
248
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex max-h-[280px] flex-col gap-1 overflow-y-auto no-scrollbar p-2", children: [
|
|
249
|
+
Object.entries(list.reduce((g, v) => ((g[/^\d{3}$/.test(v) ? v[0] + "XX" : ""] ||= []).push(v), g), {})).map(([k, vs]) => /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
250
|
+
k && /* @__PURE__ */ jsx("span", { className: "w-8 shrink-0 text-interface-labels-xs-normal text-text-default-subdued", children: k }),
|
|
251
|
+
vs.map((v) => {
|
|
252
|
+
const st = valueStyle(v, field);
|
|
253
|
+
return /* @__PURE__ */ jsx("button", { onMouseDown: (e) => e.preventDefault(), onClick: () => onPick(v), style: { ...st, outline: v === value ? "2px solid var(--color-stroke-active)" : "none", outlineOffset: 1 }, className: `h-6 rounded px-1.5 font-mono text-code-editor-small hover:opacity-80 ${(st == null ? void 0 : st.background) ? "" : "bg-surface-default-underground"} ${st ? "" : "text-text-default-regular"}`, children: quoted && !st ? `"${v}"` : v }, v);
|
|
254
|
+
})
|
|
255
|
+
] }, k)),
|
|
256
|
+
children
|
|
257
|
+
] });
|
|
258
|
+
}
|
|
259
|
+
function ValuePick({ value, options, quoted, onPick, add, field }) {
|
|
260
|
+
const btn = useRef(null);
|
|
261
|
+
const [open, setOpen] = useState(false);
|
|
262
|
+
const [q, setQ] = useState("");
|
|
263
|
+
const x = q.trim().toLowerCase();
|
|
264
|
+
const list = options.filter((o) => !x || o.toLowerCase().includes(x));
|
|
265
|
+
const show = (v) => {
|
|
266
|
+
const st = valueStyle(v, field);
|
|
267
|
+
return /* @__PURE__ */ jsx("span", { style: st ? { ...st, padding: st.background ? "0 4px" : 0 } : void 0, children: quoted && !st ? `"${v}"` : v });
|
|
268
|
+
};
|
|
269
|
+
const pick = (v) => {
|
|
270
|
+
onPick(v);
|
|
271
|
+
setOpen(false);
|
|
272
|
+
setQ("");
|
|
273
|
+
};
|
|
274
|
+
return /* @__PURE__ */ jsxs("span", { className: "relative shrink-0", children: [
|
|
275
|
+
add ? /* @__PURE__ */ jsx("button", { ref: btn, onClick: () => setOpen(!open), "aria-expanded": open, "data-pqb-tip": "Add a value", "aria-label": "Add a value", className: ACT, children: /* @__PURE__ */ jsx(P.Plus, { size: 14 }) }) : /* @__PURE__ */ jsxs("button", { ref: btn, onClick: () => setOpen(!open), className: `flex h-7 min-w-[90px] items-center gap-1.5 rounded-md border px-1.5 text-left ${open ? "border-stroke-active" : "border-stroke-subsection hover:border-stroke-active"}`, children: [
|
|
276
|
+
/* @__PURE__ */ jsx("span", { className: `min-w-0 flex-1 truncate ${value ? "font-mono text-code-editor-small text-text-default-regular" : "text-interface-body-s-normal text-text-default-disabled"}`, children: value ? show(value) : "Pick a value" }),
|
|
277
|
+
/* @__PURE__ */ jsx(P.CaretDown, { size: 12, className: "shrink-0 text-text-default-subtle" })
|
|
278
|
+
] }),
|
|
279
|
+
open && /* @__PURE__ */ jsxs(Menu, { anchor: btn, width: field === "data.response.statusCode" ? 420 : 300, onClose: () => setOpen(false), children: [
|
|
280
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-9 items-center gap-1.5 border-b border-stroke-subsection px-2.5", children: [
|
|
281
|
+
/* @__PURE__ */ jsx(P.MagnifyingGlass, { size: 14, className: "text-icon-default" }),
|
|
282
|
+
/* @__PURE__ */ jsx(
|
|
283
|
+
"input",
|
|
284
|
+
{
|
|
285
|
+
autoFocus: true,
|
|
286
|
+
value: q,
|
|
287
|
+
onChange: (e) => setQ(e.target.value),
|
|
288
|
+
placeholder: "Search values",
|
|
289
|
+
onKeyDown: (e) => {
|
|
290
|
+
if (e.key === "Enter" && (list[0] || q.trim())) pick(list[0] ?? q.trim());
|
|
291
|
+
},
|
|
292
|
+
className: "min-w-0 flex-1 bg-transparent text-interface-body-s-normal text-text-default-regular outline-none placeholder:text-text-default-disabled"
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
] }),
|
|
296
|
+
/* @__PURE__ */ jsx(Options, { list, value, field, quoted, onPick: pick, children: !list.length && /* @__PURE__ */ jsxs("p", { className: "px-0.5 py-1 text-interface-body-s-light text-text-default-subdued", children: [
|
|
297
|
+
"Enter adds \u201C",
|
|
298
|
+
q,
|
|
299
|
+
"\u201D"
|
|
300
|
+
] }) })
|
|
301
|
+
] })
|
|
302
|
+
] });
|
|
303
|
+
}
|
|
304
|
+
function Chips({ values, onValues, placeholder, quoted, field, options }) {
|
|
305
|
+
const [draft, setDraft] = useState("");
|
|
306
|
+
const [open, setOpen] = useState(false);
|
|
307
|
+
const ref = useRef(null);
|
|
308
|
+
const box = useRef(null);
|
|
309
|
+
const x = draft.trim().toLowerCase();
|
|
310
|
+
const list = (options || []).filter((o) => !values.includes(o) && (!x || o.toLowerCase().includes(x)));
|
|
311
|
+
const add = (raw) => {
|
|
312
|
+
const vals = raw.split(/[,\n]/).map((v) => v.trim().replace(/^"(.*)"$/s, "$1")).filter(Boolean);
|
|
313
|
+
if (vals.length) onValues([...values, ...vals.filter((v) => !values.includes(v))]);
|
|
314
|
+
setDraft("");
|
|
315
|
+
setOpen(false);
|
|
316
|
+
};
|
|
317
|
+
return /* @__PURE__ */ jsxs("span", { ref: box, onClick: () => {
|
|
318
|
+
var _a;
|
|
319
|
+
return (_a = ref.current) == null ? void 0 : _a.focus(), setOpen(true);
|
|
320
|
+
}, className: "flex min-h-7 min-w-0 max-w-[420px] flex-1 cursor-text flex-wrap items-center gap-1 rounded-md border border-stroke-subsection bg-surface-default-ground px-1 py-0.5 focus-within:border-stroke-active", children: [
|
|
321
|
+
values.map((v) => /* @__PURE__ */ jsxs("span", { style: valueStyle(v, field) || void 0, className: "flex h-5 items-center gap-1 rounded bg-surface-default-underground pl-1.5 pr-0.5 font-mono text-code-editor-small text-text-default-regular", children: [
|
|
322
|
+
quoted && !valueStyle(v, field) ? `"${v}"` : v,
|
|
323
|
+
/* @__PURE__ */ jsx(
|
|
324
|
+
"button",
|
|
325
|
+
{
|
|
326
|
+
onClick: (e) => {
|
|
327
|
+
e.stopPropagation();
|
|
328
|
+
onValues(values.filter((x2) => x2 !== v));
|
|
329
|
+
},
|
|
330
|
+
"aria-label": `Remove ${v}`,
|
|
331
|
+
className: "grid h-4 w-4 place-items-center rounded text-icon-subtle hover:bg-surface-hover-l1-hover",
|
|
332
|
+
children: /* @__PURE__ */ jsx(P.X, { size: 9 })
|
|
333
|
+
}
|
|
334
|
+
)
|
|
335
|
+
] }, v)),
|
|
336
|
+
/* @__PURE__ */ jsx(
|
|
337
|
+
"input",
|
|
338
|
+
{
|
|
339
|
+
ref,
|
|
340
|
+
value: draft,
|
|
341
|
+
placeholder: values.length ? "" : `${placeholder}, then Enter`,
|
|
342
|
+
onFocus: () => setOpen(true),
|
|
343
|
+
onChange: (e) => (setOpen(true), e.target.value.includes(",") ? add(e.target.value) : setDraft(e.target.value)),
|
|
344
|
+
onKeyDown: (e) => {
|
|
345
|
+
if (e.key === "Enter") {
|
|
346
|
+
e.preventDefault();
|
|
347
|
+
add(x && list[0] ? list[0] : draft);
|
|
348
|
+
}
|
|
349
|
+
if (e.key === "Backspace" && !draft && values.length) onValues(values.slice(0, -1));
|
|
350
|
+
},
|
|
351
|
+
onBlur: () => draft && add(draft),
|
|
352
|
+
className: "h-5 min-w-[90px] flex-1 bg-transparent px-1 font-mono text-code-editor-small text-text-default-regular outline-none placeholder:font-sans placeholder:text-text-default-disabled"
|
|
353
|
+
}
|
|
354
|
+
),
|
|
355
|
+
open && list.length > 0 && /* @__PURE__ */ jsx(Menu, { anchor: box, width: field === "data.response.statusCode" ? 420 : 300, onClose: () => setOpen(false), children: /* @__PURE__ */ jsx(Options, { list, field, quoted, onPick: add }) })
|
|
356
|
+
] });
|
|
357
|
+
}
|
|
358
|
+
function Values({ cond, type, onChange }) {
|
|
359
|
+
const a = arity(cond.op);
|
|
360
|
+
const [one = "", two = ""] = cond.values;
|
|
361
|
+
const set = (values) => onChange({ values });
|
|
362
|
+
const catalog = CATALOG[cond.field] || (type === "boolean" ? ["true", "false"] : null);
|
|
363
|
+
const quoted = type !== "number" && type !== "boolean" && type !== "latency" && !["<", "<=", ">", ">="].includes(cond.op);
|
|
364
|
+
const placeholder = cond.field === "data.response.statusCode" ? "404" : type === "number" || type === "latency" ? "Number" : type === "ip" ? "10.0.4.12" : type === "boolean" ? "true or false" : "Value";
|
|
365
|
+
const hint = (t) => /* @__PURE__ */ jsx("span", { className: "pl-0.5 text-interface-labels-xs-light text-text-default-subdued", children: t });
|
|
366
|
+
const textOp = ["CONTAINS", "NOT CONTAINS", "~", "!~"].includes(cond.op);
|
|
367
|
+
if (a === "none") return /* @__PURE__ */ jsx("span", { className: "flex h-7 items-center px-1 text-interface-labels-xs-light text-text-default-subdued", children: "no value needed" });
|
|
368
|
+
if (a === "two")
|
|
369
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: [
|
|
370
|
+
/* @__PURE__ */ jsx("input", { value: one, onChange: (e) => set([e.target.value, two]), inputMode: "decimal", placeholder: "From", className: `${INPUT} w-24` }),
|
|
371
|
+
/* @__PURE__ */ jsx("span", { className: "text-interface-body-s-normal text-text-default-subtle", children: "and" }),
|
|
372
|
+
/* @__PURE__ */ jsx("input", { value: two, onChange: (e) => set([one, e.target.value]), inputMode: "decimal", placeholder: "To", className: `${INPUT} w-24` }),
|
|
373
|
+
hint(type === "latency" ? "ms \xB7 both ends included" : "both ends included")
|
|
374
|
+
] });
|
|
375
|
+
if (a === "list")
|
|
376
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
377
|
+
/* @__PURE__ */ jsx(Chips, { values: cond.values, onValues: set, placeholder, quoted, field: cond.field, options: catalog }),
|
|
378
|
+
catalog && /* @__PURE__ */ jsx(ValuePick, { add: true, options: catalog.filter((v) => !cond.values.includes(v)), quoted, field: cond.field, onPick: (v) => set([...cond.values, v]) })
|
|
379
|
+
] });
|
|
380
|
+
if (a === "ip")
|
|
381
|
+
return /* @__PURE__ */ jsx("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: /* @__PURE__ */ jsx("input", { value: cond.values.join(", "), onChange: (e) => set(e.target.value.split(",").map((v) => v.trim())), placeholder: "10.0.0.0/24 or 10.0.0.1-10.0.0.50, comma for several", className: `${INPUT} w-full max-w-[340px]` }) });
|
|
382
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: [
|
|
383
|
+
catalog && (cond.op === "==" || cond.op === "!=") ? /* @__PURE__ */ jsx(ValuePick, { value: one, options: catalog, quoted, field: cond.field, onPick: (v) => set([v]) }) : quoted ? /* @__PURE__ */ jsxs("span", { className: "flex h-7 w-[220px] min-w-0 items-center rounded-md border border-stroke-subsection font-mono text-code-editor-small hover:border-stroke-section focus-within:border-stroke-active", children: [
|
|
384
|
+
/* @__PURE__ */ jsx("span", { className: "pl-1.5 text-text-default-subdued", children: cond.op === "~" || cond.op === "!~" ? "/" : '"' }),
|
|
385
|
+
/* @__PURE__ */ jsx("input", { value: one, onChange: (e) => set([e.target.value.replace(/^"(.*)"$/s, "$1")]), placeholder, spellCheck: false, className: "h-full min-w-0 flex-1 bg-transparent px-0.5 text-text-default-regular outline-none placeholder:font-sans placeholder:text-text-default-disabled" }),
|
|
386
|
+
/* @__PURE__ */ jsx("span", { className: "pr-1.5 text-text-default-subdued", children: cond.op === "~" || cond.op === "!~" ? "/" : '"' })
|
|
387
|
+
] }) : /* @__PURE__ */ jsx("input", { value: one, onChange: (e) => set([e.target.value]), inputMode: type === "boolean" ? void 0 : "decimal", placeholder, className: `${INPUT} w-[180px]` }),
|
|
388
|
+
type === "latency" && hint("ms"),
|
|
389
|
+
textOp && /* @__PURE__ */ jsx("button", { onClick: () => onChange({ ci: !cond.ci }), "aria-pressed": cond.ci, "data-pqb-tip": cond.ci ? "Any case (click for exact case)" : "Exact case (click for any case)", className: `h-6 shrink-0 rounded px-1.5 font-mono text-interface-labels-xs-normal font-semibold ${cond.ci ? "bg-surface-color-blue-default-subtle text-text-color-blue" : "text-text-default-subtle hover:bg-surface-hover-l1-hover"}`, children: "Aa" })
|
|
390
|
+
] });
|
|
391
|
+
}
|
|
392
|
+
function RowActions({ item, depth, parentJoin, onRoot }) {
|
|
393
|
+
const btn = useRef(null);
|
|
394
|
+
const [open, setOpen] = useState(false);
|
|
395
|
+
const row = "flex h-8 w-full items-center gap-2 px-2.5 text-left text-interface-body-s-normal text-text-default-regular hover:bg-surface-hover-l1-hover";
|
|
396
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center", children: [
|
|
397
|
+
depth < 2 && item.kind === "cond" && /* @__PURE__ */ jsx("button", { onClick: () => onRoot((r) => update(r, item.id, (c) => ({ kind: "group", id: newCond().id, join: parentJoin === "AND" ? "OR" : "AND", not: false, items: [c, newCond()] }))), "data-pqb-tip": "Branch", "aria-label": "Branch from this condition", className: ACT, children: /* @__PURE__ */ jsx(P.TreeView, { size: 14 }) }),
|
|
398
|
+
/* @__PURE__ */ jsx("button", { onClick: () => onRoot((r) => tidy(remove(r, item.id), true)), "data-pqb-tip": item.kind === "group" ? "Remove group" : "Remove condition", "aria-label": "Remove", className: `${ACT} hover:text-text-color-red`, children: /* @__PURE__ */ jsx(P.Trash, { size: 14 }) }),
|
|
399
|
+
/* @__PURE__ */ jsxs("span", { className: "relative", children: [
|
|
400
|
+
/* @__PURE__ */ jsx("button", { ref: btn, onClick: () => setOpen(!open), "aria-expanded": open, "aria-label": "More", "data-pqb-tip": "More", className: ACT, children: /* @__PURE__ */ jsx(P.DotsThreeVertical, { size: 16, weight: "bold" }) }),
|
|
401
|
+
open && /* @__PURE__ */ jsx(Menu, { anchor: btn, width: 200, onClose: () => setOpen(false), children: /* @__PURE__ */ jsxs("div", { className: "py-1", children: [
|
|
402
|
+
/* @__PURE__ */ jsxs(
|
|
403
|
+
"button",
|
|
404
|
+
{
|
|
405
|
+
onClick: () => {
|
|
406
|
+
onRoot((r) => insertAfter(r, item.id, clone(item)));
|
|
407
|
+
setOpen(false);
|
|
408
|
+
},
|
|
409
|
+
className: row,
|
|
410
|
+
children: [
|
|
411
|
+
/* @__PURE__ */ jsx(P.Copy, { size: 14, className: "text-icon-default" }),
|
|
412
|
+
"Duplicate"
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
/* @__PURE__ */ jsxs(
|
|
417
|
+
"button",
|
|
418
|
+
{
|
|
419
|
+
onClick: () => {
|
|
420
|
+
onRoot((r) => update(r, item.id, (x) => ({ ...x, not: !x.not })));
|
|
421
|
+
setOpen(false);
|
|
422
|
+
},
|
|
423
|
+
className: row,
|
|
424
|
+
children: [
|
|
425
|
+
/* @__PURE__ */ jsx(P.Prohibit, { size: 14, className: "text-icon-default" }),
|
|
426
|
+
item.not ? "Remove NOT" : "Negate with NOT"
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
)
|
|
430
|
+
] }) })
|
|
431
|
+
] })
|
|
432
|
+
] });
|
|
433
|
+
}
|
|
434
|
+
var NotChip = ({ onClick }) => /* @__PURE__ */ jsx("button", { onClick, "data-pqb-tip": "Negated, click to remove NOT", className: "mt-[3px] h-[22px] shrink-0 rounded bg-surface-color-red-default-subtle px-1.5 font-mono text-code-editor-small font-semibold text-text-color-red", children: "NOT" });
|
|
435
|
+
function Row({ cond, depth, parentJoin, schema, errors, onRoot }) {
|
|
436
|
+
const type = cond.field ? typeOf(cond.field, schema) : "string";
|
|
437
|
+
const set = (patch) => onRoot((r) => update(r, cond.id, (c) => ({ ...c, ...patch })));
|
|
438
|
+
const err = errors.get(cond.id);
|
|
439
|
+
return /* @__PURE__ */ jsxs("div", { className: "group/row", children: [
|
|
440
|
+
/* @__PURE__ */ jsxs("div", { className: "inline-flex max-w-full items-start gap-1.5", children: [
|
|
441
|
+
cond.not && /* @__PURE__ */ jsx(NotChip, { onClick: () => set({ not: false }) }),
|
|
442
|
+
/* @__PURE__ */ jsx(
|
|
443
|
+
FieldPicker,
|
|
444
|
+
{
|
|
445
|
+
value: cond.field,
|
|
446
|
+
schema,
|
|
447
|
+
autoOpen: !cond.field,
|
|
448
|
+
onPick: (f) => {
|
|
449
|
+
const t = typeOf(f, schema);
|
|
450
|
+
const ops = opsFor({ type: t });
|
|
451
|
+
const keep = ops.includes(cond.op) && t === type;
|
|
452
|
+
set({ field: f, op: keep ? cond.op : t === "latency" ? ">" : "==", values: keep ? cond.values : [] });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
cond.field && /* @__PURE__ */ jsx(
|
|
457
|
+
OpPicker,
|
|
458
|
+
{
|
|
459
|
+
value: cond.op,
|
|
460
|
+
type,
|
|
461
|
+
onPick: (o) => {
|
|
462
|
+
const from = arity(cond.op);
|
|
463
|
+
const to = arity(o);
|
|
464
|
+
set({ op: o, values: from === to ? cond.values : to === "none" ? [] : to === "two" ? [cond.values[0] ?? "", ""] : cond.values.slice(0, to === "list" || to === "ip" ? 99 : 1) });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
),
|
|
468
|
+
cond.field && /* @__PURE__ */ jsx(Values, { cond, type, onChange: set }),
|
|
469
|
+
/* @__PURE__ */ jsx(RowActions, { item: cond, depth, parentJoin, onRoot })
|
|
470
|
+
] }),
|
|
471
|
+
err && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 pt-0.5 text-interface-labels-xs-normal text-text-color-red", children: [
|
|
472
|
+
/* @__PURE__ */ jsx(P.Warning, { size: 12, weight: "fill", className: "shrink-0" }),
|
|
473
|
+
err
|
|
474
|
+
] })
|
|
475
|
+
] });
|
|
476
|
+
}
|
|
477
|
+
function Group({ group, depth, schema, errors, onRoot, parentJoin }) {
|
|
478
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative pl-6", children: [
|
|
479
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: `absolute left-2 ${depth > 0 ? "top-[14px]" : "top-0"} bottom-[9px] w-px bg-stroke-section` }),
|
|
480
|
+
depth > 0 && /* @__PURE__ */ jsxs("div", { className: "group/row -ml-6 mb-1 flex items-center gap-1.5 pl-6", children: [
|
|
481
|
+
group.not && /* @__PURE__ */ jsx(NotChip, { onClick: () => onRoot((r) => update(r, group.id, (g) => ({ ...g, not: false }))) }),
|
|
482
|
+
/* @__PURE__ */ jsx("span", { className: "text-interface-labels-xs-light text-text-default-subdued", children: "Group" }),
|
|
483
|
+
/* @__PURE__ */ jsx(RowActions, { item: group, depth, parentJoin, onRoot })
|
|
484
|
+
] }),
|
|
485
|
+
/* @__PURE__ */ jsx("ul", { className: "flex flex-col", children: group.items.map((item, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
486
|
+
i > 0 && /* @__PURE__ */ jsx("button", { onClick: () => onRoot((r) => update(r, item.id, (x) => ({ ...x, j: (item.j || group.join) === "AND" ? "OR" : "AND" }))), "data-pqb-tip": `Switch to ${(item.j || group.join) === "AND" ? "OR" : "AND"}`, className: "relative -ml-6 my-1 block h-5 rounded bg-surface-color-blue-default-subtle px-1.5 text-interface-labels-xs-normal font-semibold text-text-color-blue hover:bg-surface-color-blue-hover-subtle", children: item.j || group.join }),
|
|
487
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
488
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "absolute -left-4 top-[14px] h-px w-4 bg-stroke-section" }),
|
|
489
|
+
item.kind === "cond" ? /* @__PURE__ */ jsx(Row, { cond: item, depth, parentJoin: item.j || group.join, schema, errors, onRoot }) : /* @__PURE__ */ jsx("div", { className: "-ml-2", children: /* @__PURE__ */ jsx(Group, { group: item, depth: depth + 1, schema, errors, onRoot, parentJoin: item.j || group.join }) })
|
|
490
|
+
] })
|
|
491
|
+
] }, item.id)) }),
|
|
492
|
+
/* @__PURE__ */ jsx("span", { className: "relative -ml-6 mt-1 block h-[18px]", children: /* @__PURE__ */ jsx("button", { onClick: () => onRoot((r) => {
|
|
493
|
+
var _a;
|
|
494
|
+
return r.id === group.id ? { ...r, items: [...r.items, { ...newCond(), j: (_a = group.items[group.items.length - 1]) == null ? void 0 : _a.j }] } : update(r, group.id, (g) => {
|
|
495
|
+
var _a2;
|
|
496
|
+
return { ...g, items: [...g.items, { ...newCond(), j: (_a2 = group.items[group.items.length - 1]) == null ? void 0 : _a2.j }] };
|
|
497
|
+
});
|
|
498
|
+
}), "aria-label": "Add a condition", "data-pqb-tip": "Add a condition", className: "ml-[1px] grid h-[15px] w-[15px] place-items-center rounded-full border border-stroke-section bg-surface-default-l1 text-icon-subtle hover:border-stroke-active hover:text-text-color-blue", children: /* @__PURE__ */ jsx(P.Plus, { size: 9, weight: "bold" }) }) })
|
|
499
|
+
] });
|
|
500
|
+
}
|
|
501
|
+
function CountRow({ count, schema, onChange, onRemove }) {
|
|
502
|
+
const set = (patch) => onChange({ ...count, ...patch });
|
|
503
|
+
return /* @__PURE__ */ jsxs("div", { className: "group/row mt-2 flex flex-wrap items-start gap-1.5 border-t border-stroke-subsection pl-6 pt-2", children: [
|
|
504
|
+
/* @__PURE__ */ jsx("span", { className: "mt-[3px] flex h-[22px] items-center rounded bg-surface-color-blue-default-subtle px-1.5 font-mono text-code-editor-small font-semibold text-text-color-purple", children: "COUNT()" }),
|
|
505
|
+
/* @__PURE__ */ jsx("select", { value: count.op, onChange: (e) => set({ op: e.target.value }), className: `${INPUT} w-16`, children: [">", ">=", "<", "<=", "=="].map((o) => /* @__PURE__ */ jsx("option", { value: o, children: o }, o)) }),
|
|
506
|
+
/* @__PURE__ */ jsx("input", { value: count.n, onChange: (e) => set({ n: e.target.value }), inputMode: "numeric", placeholder: "Number", className: `${INPUT} w-24` }),
|
|
507
|
+
/* @__PURE__ */ jsx("span", { className: "flex h-7 items-center text-interface-body-s-normal text-text-default-subtle", children: "within" }),
|
|
508
|
+
/* @__PURE__ */ jsx("input", { value: count.within, onChange: (e) => set({ within: e.target.value }), placeholder: "time range", className: `${INPUT} w-24` }),
|
|
509
|
+
/* @__PURE__ */ jsx("span", { className: "flex h-7 items-center text-interface-body-s-normal text-text-default-subtle", children: "group by" }),
|
|
510
|
+
/* @__PURE__ */ jsx(FieldPicker, { value: count.by, schema, placeholder: "Whole result", onPick: (f) => set({ by: f === "@latency" ? "" : f }) }),
|
|
511
|
+
count.by && /* @__PURE__ */ jsx("button", { onClick: () => set({ by: "" }), "data-pqb-tip": "Count the whole result", "aria-label": "Remove group by", className: ACT, children: /* @__PURE__ */ jsx(P.X, { size: 12 }) }),
|
|
512
|
+
/* @__PURE__ */ jsx("button", { onClick: onRemove, "data-pqb-tip": "Remove COUNT()", "aria-label": "Remove COUNT()", className: `${ACT} hover:text-text-color-red`, children: /* @__PURE__ */ jsx(P.Trash, { size: 14 }) })
|
|
513
|
+
] });
|
|
514
|
+
}
|
|
515
|
+
function Builder({ text, schema, onApply, onCancel }) {
|
|
516
|
+
var _a;
|
|
517
|
+
const start = useMemo(() => {
|
|
518
|
+
const p = parse(text, schema);
|
|
519
|
+
const ok = text.trim() && !p.errors.length;
|
|
520
|
+
const tree = toTree(ok ? p.ast : null);
|
|
521
|
+
if (!tree.items.length && !tree.count) tree.items = [newCond()];
|
|
522
|
+
return { tree, replaced: !!text.trim() && !ok };
|
|
523
|
+
}, []);
|
|
524
|
+
const [root, setRoot] = useState(start.tree);
|
|
525
|
+
const [show, setShow] = useState(false);
|
|
526
|
+
const onRoot = (fn) => setRoot((r) => fn(r));
|
|
527
|
+
const out = useMemo(() => fromTree(root, schema), [root, schema]);
|
|
528
|
+
const parsed = useMemo(() => out ? parse(out, schema) : null, [out, schema]);
|
|
529
|
+
const clean = parsed && !parsed.errors.length ? format(parsed.ast) : out;
|
|
530
|
+
const incomplete = useMemo(() => {
|
|
531
|
+
let n = 0;
|
|
532
|
+
const walk = (g) => g.items.forEach((x) => x.kind === "group" ? walk(x) : x.field && !isComplete(x) && n++);
|
|
533
|
+
walk(root);
|
|
534
|
+
if (root.count && !String(root.count.n).trim()) n++;
|
|
535
|
+
return n;
|
|
536
|
+
}, [root]);
|
|
537
|
+
const error = (_a = parsed == null ? void 0 : parsed.errors[0]) == null ? void 0 : _a.msg;
|
|
538
|
+
const blocked = incomplete > 0 || !!error;
|
|
539
|
+
return /* @__PURE__ */ jsxs("div", { className: "border-t border-stroke-subsection", onMouseDown: (e) => e.stopPropagation(), children: [
|
|
540
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-[380px] min-h-[96px] overflow-auto scroll-thin bg-surface-default-l1 px-3 pb-2 pt-3", children: [
|
|
541
|
+
start.replaced && /* @__PURE__ */ jsx("p", { className: "mb-2 text-interface-labels-xs-light text-text-default-subdued", children: "The query in the bar has an error, so the builder starts empty. Apply replaces it." }),
|
|
542
|
+
/* @__PURE__ */ jsx(Group, { group: root, depth: 0, schema, errors: /* @__PURE__ */ new Map(), onRoot }),
|
|
543
|
+
root.count ? /* @__PURE__ */ jsx(CountRow, { count: root.count, schema, onChange: (c) => setRoot({ ...root, count: c }), onRemove: () => setRoot({ ...root, count: null }) }) : /* @__PURE__ */ jsx("button", { onClick: () => setRoot({ ...root, count: { op: ">", n: "", within: "", by: "" } }), className: "mt-1 h-6 rounded px-1.5 text-interface-labels-xs-normal text-text-color-blue hover:bg-surface-hover-l1-hover", children: "Add COUNT() threshold" })
|
|
544
|
+
] }),
|
|
545
|
+
show && /* @__PURE__ */ jsx("div", { className: "border-t border-stroke-subsection px-3 py-2", children: /* @__PURE__ */ jsx("pre", { style: { maxHeight: 200 }, className: "overflow-auto scroll-thin whitespace-pre-wrap break-all font-mono text-code-editor-small leading-5 text-text-default-subdued", children: clean ? paint(parsed && !parsed.errors.length ? format(parsed.ast, null, true) : clean, schema) : "No filter" }) }),
|
|
546
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-t border-stroke-subsection px-3 py-2", children: [
|
|
547
|
+
incomplete > 0 ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-1.5 text-interface-labels-xs-normal text-text-color-red", children: [
|
|
548
|
+
/* @__PURE__ */ jsx(P.Warning, { size: 12, weight: "fill", className: "shrink-0" }),
|
|
549
|
+
incomplete === 1 ? "Finish 1 condition to run" : `Finish ${incomplete} conditions to run`
|
|
550
|
+
] }) : error ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-1.5 truncate text-interface-labels-xs-normal text-text-color-red", children: [
|
|
551
|
+
/* @__PURE__ */ jsx(P.Warning, { size: 12, weight: "fill", className: "shrink-0" }),
|
|
552
|
+
error
|
|
553
|
+
] }) : null,
|
|
554
|
+
/* @__PURE__ */ jsx("span", { className: "ml-auto" }),
|
|
555
|
+
/* @__PURE__ */ jsx("button", { onClick: () => setShow(!show), "aria-pressed": show, className: "h-6 shrink-0 rounded-[5px] border border-stroke-subsection bg-surface-default-ground px-2.5 text-interface-labels-xs-normal font-semibold text-text-default-regular hover:bg-surface-hover-l1-hover", children: show ? "Hide query" : "Show query" }),
|
|
556
|
+
/* @__PURE__ */ jsx("button", { onClick: onCancel, className: "h-6 shrink-0 rounded-[5px] border border-stroke-subsection bg-surface-default-ground px-2.5 text-interface-labels-xs-normal font-semibold text-text-default-regular hover:bg-surface-hover-l1-hover", children: "Cancel" }),
|
|
557
|
+
/* @__PURE__ */ jsx("button", { disabled: blocked, onClick: () => onApply(clean || ""), className: "h-6 shrink-0 rounded-[5px] border border-stroke-active bg-surface-default-action px-2.5 text-interface-labels-xs-normal font-semibold text-text-default-static hover:bg-surface-default-action-hover disabled:cursor-not-allowed disabled:opacity-50", children: "Apply & run" })
|
|
558
|
+
] })
|
|
559
|
+
] });
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/react/QueryBox.jsx
|
|
563
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
564
|
+
var ROLE = { field: "text-base-blue-1100", op: "text-text-color-purple", kw: "font-semibold text-text-color-purple", str: "text-text-color-success", num: "text-text-color-cyan", bool: "text-text-color-orange", fn: "font-semibold text-text-color-purple", punct: "text-text-default-subtle" };
|
|
565
|
+
var DEFAULT = { kw: ROLE.kw, str: ROLE.str, num: ROLE.num, dur: ROLE.num, bool: ROLE.bool, op: ROLE.op, word: ROLE.field };
|
|
566
|
+
var cls = (t) => t.role === "op" && t.t === "op" ? "text-text-default-subdued" : ROLE[t.role] || DEFAULT[t.t] || "";
|
|
567
|
+
var TYPE_ICON2 = { string: TextT2, numtext: TextT2, number: Hash2, boolean: ToggleLeft2, ip: Globe2, latency: Timer2 };
|
|
568
|
+
var PAIRS = { '"': '"', "]": "]", ")": ")" };
|
|
569
|
+
var MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
570
|
+
function paint(text, schema, tipFor) {
|
|
571
|
+
const { toks } = parse(text, schema);
|
|
572
|
+
const out = [];
|
|
573
|
+
let at = 0;
|
|
574
|
+
for (const t of toks) {
|
|
575
|
+
if (t.s > at) out.push(text.slice(at, t.s));
|
|
576
|
+
const tip = tipFor && t.role === "field" ? tipFor(t.raw) : null;
|
|
577
|
+
out.push(
|
|
578
|
+
tip ? /* @__PURE__ */ jsx2("span", { "data-pqb-tip": tip, "data-mono": "", className: `${cls(t)} underline decoration-dotted`, children: t.raw }, t.s) : /* @__PURE__ */ jsx2("span", { className: cls(t), children: t.raw }, t.s)
|
|
579
|
+
);
|
|
580
|
+
at = t.e;
|
|
581
|
+
}
|
|
582
|
+
out.push(text.slice(at));
|
|
583
|
+
return out;
|
|
584
|
+
}
|
|
585
|
+
function Tips({ root }) {
|
|
586
|
+
const [tip, setTip] = useState2(null);
|
|
587
|
+
useEffect2(() => {
|
|
588
|
+
let timer;
|
|
589
|
+
const over = (e) => {
|
|
590
|
+
var _a, _b, _c;
|
|
591
|
+
const el = (_b = (_a = e.target).closest) == null ? void 0 : _b.call(_a, "[data-pqb-tip]");
|
|
592
|
+
clearTimeout(timer);
|
|
593
|
+
if (!el || !el.dataset.pqbTip || !((_c = root.current) == null ? void 0 : _c.contains(el)) || el.getAttribute("aria-expanded") === "true") return setTip(null);
|
|
594
|
+
if (el.dataset.trunc !== void 0 && el.scrollWidth <= el.clientWidth) return setTip(null);
|
|
595
|
+
const r = el.getBoundingClientRect();
|
|
596
|
+
timer = setTimeout(() => setTip({ text: el.dataset.pqbTip, mono: el.dataset.mono !== void 0, side: el.dataset.side, r }), 200);
|
|
597
|
+
};
|
|
598
|
+
const hide = () => {
|
|
599
|
+
clearTimeout(timer);
|
|
600
|
+
setTip(null);
|
|
601
|
+
};
|
|
602
|
+
document.addEventListener("mouseover", over);
|
|
603
|
+
document.addEventListener("mousedown", hide, true);
|
|
604
|
+
document.addEventListener("scroll", hide, true);
|
|
605
|
+
return () => {
|
|
606
|
+
clearTimeout(timer);
|
|
607
|
+
document.removeEventListener("mouseover", over);
|
|
608
|
+
document.removeEventListener("mousedown", hide, true);
|
|
609
|
+
document.removeEventListener("scroll", hide, true);
|
|
610
|
+
};
|
|
611
|
+
}, []);
|
|
612
|
+
if (!tip) return null;
|
|
613
|
+
const place = (el) => {
|
|
614
|
+
if (!el) return;
|
|
615
|
+
const { r } = tip;
|
|
616
|
+
const w = el.offsetWidth;
|
|
617
|
+
const h = el.offsetHeight;
|
|
618
|
+
const a = el.firstChild.style;
|
|
619
|
+
if (tip.side === "right") {
|
|
620
|
+
const top = Math.max(8, r.top + r.height / 2 - h / 2);
|
|
621
|
+
el.style.left = r.right + 8 + "px";
|
|
622
|
+
el.style.top = top + "px";
|
|
623
|
+
Object.assign(a, { left: "-4px", top: Math.min(h - 12, Math.max(4, r.top + r.height / 2 - top - 4)) + "px" });
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
const left = Math.max(8, Math.min(window.innerWidth - w - 8, r.left + r.width / 2 - w / 2));
|
|
627
|
+
const below = r.bottom + 8 + h < window.innerHeight;
|
|
628
|
+
el.style.left = left + "px";
|
|
629
|
+
el.style.top = (below ? r.bottom + 8 : r.top - h - 8) + "px";
|
|
630
|
+
Object.assign(a, { left: Math.min(w - 12, Math.max(4, r.left + r.width / 2 - left - 4)) + "px", top: below ? "-4px" : h - 4 + "px" });
|
|
631
|
+
};
|
|
632
|
+
return /* @__PURE__ */ jsxs2("div", { ref: place, role: "tooltip", style: { position: "fixed", zIndex: 100, left: -9999, top: -9999, background: "#000", fontSize: tip.mono ? 11 : 13, lineHeight: tip.mono ? "16px" : "18px" }, className: `pointer-events-none w-max max-w-[520px] whitespace-pre-wrap break-words rounded-md px-2.5 py-1.5 font-medium text-text-default-static shadow-e300 ${tip.mono ? "font-mono" : ""}`, children: [
|
|
633
|
+
/* @__PURE__ */ jsx2("span", { "aria-hidden": "true", style: { position: "absolute", width: 8, height: 8, background: "#000", transform: "rotate(45deg)" } }),
|
|
634
|
+
tip.text
|
|
635
|
+
] });
|
|
636
|
+
}
|
|
637
|
+
var closes = (text, pos) => {
|
|
638
|
+
let n = 0;
|
|
639
|
+
for (let i = 0; i < pos; i++) {
|
|
640
|
+
if (text[i] === "\\") i++;
|
|
641
|
+
else if (text[i] === '"') n++;
|
|
642
|
+
}
|
|
643
|
+
return n % 2 === 1;
|
|
644
|
+
};
|
|
645
|
+
function QueryBox({ text, setText, schema, onRun, tools, actions, runErrors, setRunErrors, runRef, adv, setAdv, placeholder }) {
|
|
646
|
+
var _a, _b, _c, _d;
|
|
647
|
+
const ta = useRef2(null);
|
|
648
|
+
const pre = useRef2(null);
|
|
649
|
+
const list = useRef2(null);
|
|
650
|
+
const nextCaret = useRef2(null);
|
|
651
|
+
const stepped = useRef2(null);
|
|
652
|
+
const last = useRef2(text);
|
|
653
|
+
last.current = text;
|
|
654
|
+
const [caret, setCaret] = useState2(0);
|
|
655
|
+
const [focus, setFocus] = useState2(false);
|
|
656
|
+
const [open, setOpen] = useState2(false);
|
|
657
|
+
const [hl, setHl] = useState2(0);
|
|
658
|
+
const sugg = useMemo2(() => focus && open ? context(text, caret, schema) : null, [focus, open, text, caret, schema]);
|
|
659
|
+
const items = (sugg == null ? void 0 : sugg.items) || [];
|
|
660
|
+
const parsed = useMemo2(() => parse(text, schema), [text, schema]);
|
|
661
|
+
const [ranged, setRanged] = useState2(false);
|
|
662
|
+
const startHl = (sugg == null ? void 0 : sugg.title) === "Combine" || (sugg == null ? void 0 : sugg.title) === "Add another value" || ((_a = sugg == null ? void 0 : sugg.title) == null ? void 0 : _a.startsWith("Regex syntax")) ? -1 : 0;
|
|
663
|
+
useLayoutEffect(() => {
|
|
664
|
+
setHl(startHl);
|
|
665
|
+
if (list.current) list.current.scrollTop = 0;
|
|
666
|
+
}, [sugg == null ? void 0 : sugg.kind, sugg == null ? void 0 : sugg.title, sugg == null ? void 0 : sugg.from, startHl]);
|
|
667
|
+
useLayoutEffect(() => {
|
|
668
|
+
if (nextCaret.current !== null && ta.current) {
|
|
669
|
+
ta.current.setSelectionRange(nextCaret.current, nextCaret.current);
|
|
670
|
+
setCaret(nextCaret.current);
|
|
671
|
+
nextCaret.current = null;
|
|
672
|
+
}
|
|
673
|
+
}, [text]);
|
|
674
|
+
useEffect2(() => {
|
|
675
|
+
var _a2, _b2;
|
|
676
|
+
(_b2 = (_a2 = list.current) == null ? void 0 : _a2.querySelector("[data-hl]")) == null ? void 0 : _b2.scrollIntoView({ block: "nearest" });
|
|
677
|
+
}, [hl]);
|
|
678
|
+
const visible = useMemo2(() => parsed.errors.filter((e) => runErrors || !e.eof && (e.e < caret || caret < e.s || !focus)), [parsed, runErrors, caret, focus]);
|
|
679
|
+
const highlighted = useMemo2(() => {
|
|
680
|
+
const out = [];
|
|
681
|
+
let at = 0;
|
|
682
|
+
const marked = visible.find((e) => e.at !== void 0);
|
|
683
|
+
const mark = marked == null ? void 0 : marked.at;
|
|
684
|
+
const lo = marked && Math.min(marked.s, mark);
|
|
685
|
+
const hi = marked && Math.max(marked.e, mark);
|
|
686
|
+
const tint = (a, b) => marked && a >= lo && b <= hi ? " bg-base-red-100" : "";
|
|
687
|
+
const pin = (k) => /* @__PURE__ */ jsx2("span", { className: "relative", children: /* @__PURE__ */ jsx2("span", { style: { position: "absolute", left: 0, top: -1, height: 20, width: 2, borderRadius: 1, background: "var(--color-text-color-red)" } }) }, "at" + k);
|
|
688
|
+
for (const t of parsed.toks) {
|
|
689
|
+
if (t.s > at) out.push(/* @__PURE__ */ jsx2("span", { className: tint(at, t.s), children: text.slice(at, t.s) }, "g" + at));
|
|
690
|
+
const bad = visible.some((e) => t.s < e.e && t.e > e.s);
|
|
691
|
+
out.push(/* @__PURE__ */ jsx2("span", { className: (bad ? "text-text-color-red underline decoration-dotted" : cls(t)) + tint(t.s, t.e), children: text.slice(t.s, t.e) }, t.s));
|
|
692
|
+
at = t.e;
|
|
693
|
+
if (mark === t.e) out.push(pin(t.e));
|
|
694
|
+
}
|
|
695
|
+
out.push(text.slice(at));
|
|
696
|
+
return out;
|
|
697
|
+
}, [parsed, text, visible]);
|
|
698
|
+
const edit = (value, pos, keep) => {
|
|
699
|
+
nextCaret.current = pos;
|
|
700
|
+
setText(value);
|
|
701
|
+
setRunErrors(false);
|
|
702
|
+
setOpen(keep);
|
|
703
|
+
};
|
|
704
|
+
const accept = (item) => {
|
|
705
|
+
let from = item.from ?? sugg.from;
|
|
706
|
+
if (item.trim) while (from > 0 && /\s/.test(text[from - 1])) from--;
|
|
707
|
+
const ins = item.insert;
|
|
708
|
+
edit(text.slice(0, from) + ins + text.slice(item.to ?? sugg.to), from + (item.caretAt ?? ins.length), !!item.reopen);
|
|
709
|
+
};
|
|
710
|
+
const run = (src = text) => {
|
|
711
|
+
setOpen(false);
|
|
712
|
+
const p = parse(src, schema);
|
|
713
|
+
if (p.errors.length) {
|
|
714
|
+
setRunErrors(true);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
const clean = format(p.ast);
|
|
718
|
+
const shown = focus ? format(p.ast, null, true) : clean;
|
|
719
|
+
if (shown !== text) edit(shown, shown.length, false);
|
|
720
|
+
onRun == null ? void 0 : onRun(clean, p.ast);
|
|
721
|
+
};
|
|
722
|
+
if (runRef) runRef.current = run;
|
|
723
|
+
const skip = (pos) => {
|
|
724
|
+
nextCaret.current = pos;
|
|
725
|
+
ta.current.setSelectionRange(pos, pos);
|
|
726
|
+
setCaret(pos);
|
|
727
|
+
setOpen(true);
|
|
728
|
+
};
|
|
729
|
+
const onKeyDown = (e) => {
|
|
730
|
+
const el = ta.current;
|
|
731
|
+
stepped.current = null;
|
|
732
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
733
|
+
e.preventDefault();
|
|
734
|
+
run();
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (e.ctrlKey && e.key === " ") {
|
|
738
|
+
e.preventDefault();
|
|
739
|
+
setOpen(true);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (open && items.length) {
|
|
743
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
744
|
+
e.preventDefault();
|
|
745
|
+
const d = e.key === "ArrowDown" ? 1 : -1;
|
|
746
|
+
setHl((h) => h < 0 ? d > 0 ? 0 : items.length - 1 : (h + d + items.length) % items.length);
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (e.key === "Enter" && !e.shiftKey && hl >= 0) {
|
|
750
|
+
e.preventDefault();
|
|
751
|
+
accept(items[hl]);
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if (e.key === "Escape") {
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
if (open && items.length) setOpen(false);
|
|
758
|
+
else el.blur();
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
762
|
+
e.preventDefault();
|
|
763
|
+
run();
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const at = el.selectionStart;
|
|
767
|
+
const live = el.value;
|
|
768
|
+
last.current = live;
|
|
769
|
+
if (e.key === " " && at === el.selectionEnd && live[at - 1] === " " && !((live.slice(0, at).match(/(?<!\\)"/g) || []).length % 2)) {
|
|
770
|
+
e.preventDefault();
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (PAIRS[e.key] && at === el.selectionEnd && live[at] === e.key && (e.key !== '"' || closes(live, at))) {
|
|
774
|
+
e.preventDefault();
|
|
775
|
+
stepped.current = { pos: at + 1, c: e.key };
|
|
776
|
+
skip(at + 1);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const onChange = (e) => {
|
|
780
|
+
const value = e.target.value;
|
|
781
|
+
const pos = e.target.selectionStart;
|
|
782
|
+
const prev = last.current;
|
|
783
|
+
const st = stepped.current;
|
|
784
|
+
stepped.current = null;
|
|
785
|
+
if (st && value === prev.slice(0, st.pos) + st.c + prev.slice(st.pos)) {
|
|
786
|
+
e.target.value = prev;
|
|
787
|
+
setText(prev);
|
|
788
|
+
skip(st.pos);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (value.length === prev.length + 1 && value.slice(pos - 2, pos) === ". " && value.slice(0, pos - 2) + " " + value.slice(pos) === prev) {
|
|
792
|
+
e.target.value = prev;
|
|
793
|
+
setText(prev);
|
|
794
|
+
skip(pos - 1);
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const n = value.length - prev.length;
|
|
798
|
+
const c = value[pos - 1];
|
|
799
|
+
if (n >= 1 && PAIRS[c] && value.slice(0, pos - n) + value.slice(pos) === prev && prev[pos - n] === c && (c !== '"' || closes(value, pos - 1))) {
|
|
800
|
+
const v = value.slice(0, pos - 1) + value.slice(pos);
|
|
801
|
+
e.target.value = v;
|
|
802
|
+
last.current = v;
|
|
803
|
+
setText(v);
|
|
804
|
+
setRunErrors(false);
|
|
805
|
+
skip(pos);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
last.current = value;
|
|
809
|
+
setText(value);
|
|
810
|
+
setCaret(pos);
|
|
811
|
+
setRunErrors(false);
|
|
812
|
+
setOpen(true);
|
|
813
|
+
};
|
|
814
|
+
const sync = () => setCaret(ta.current.selectionStart);
|
|
815
|
+
const showCard = !adv && focus && open && !ranged && items.length > 0;
|
|
816
|
+
const err = visible[0];
|
|
817
|
+
const showNotice = !adv && !showCard && err && (focus || runErrors);
|
|
818
|
+
const fix = (s, e, t) => {
|
|
819
|
+
edit(text.slice(0, s) + t + text.slice(e), s + t.length, true);
|
|
820
|
+
ta.current.focus();
|
|
821
|
+
};
|
|
822
|
+
const lifted = focus || showNotice || adv;
|
|
823
|
+
const kfmt = (n) => n >= 1e3 ? (n / 1e3).toFixed(2).replace(/\.?0+$/, "") + "k" : n;
|
|
824
|
+
let lastGroup = sugg == null ? void 0 : sugg.title;
|
|
825
|
+
const row = "relative flex h-7 cursor-pointer items-center gap-2 rounded px-2";
|
|
826
|
+
const chips = showCard && items.some((it) => !it.pin) && items.every((it) => it.pin || it.kind === "value");
|
|
827
|
+
const rowsOf = [];
|
|
828
|
+
if (chips)
|
|
829
|
+
items.forEach((it, i) => {
|
|
830
|
+
if (it.pin) return;
|
|
831
|
+
const raw = it.label.replace(/^"(.*)"$/, "$1");
|
|
832
|
+
const cls2 = /^\d{3}$/.test(raw) ? raw[0] + "XX" : "";
|
|
833
|
+
const last2 = rowsOf[rowsOf.length - 1];
|
|
834
|
+
if (last2 && last2.group === it.group && last2.cls === cls2) last2.items.push([it, i]);
|
|
835
|
+
else rowsOf.push({ group: it.group, cls: cls2, head: (!last2 || last2.group !== it.group) && it.group, items: [[it, i]] });
|
|
836
|
+
});
|
|
837
|
+
const grouped = showCard && !chips && items.some((it) => !it.pin && it.group);
|
|
838
|
+
const groupsOf = [];
|
|
839
|
+
if (grouped)
|
|
840
|
+
items.forEach((it, i) => {
|
|
841
|
+
if (it.pin) return;
|
|
842
|
+
const last2 = groupsOf[groupsOf.length - 1];
|
|
843
|
+
if (last2 && last2.group === (it.group || "")) last2.items.push([it, i]);
|
|
844
|
+
else groupsOf.push({ group: it.group || "", items: [[it, i]] });
|
|
845
|
+
});
|
|
846
|
+
const renderRow = (it, i, bare) => {
|
|
847
|
+
var _a2;
|
|
848
|
+
const head = !bare && it.group && it.group !== lastGroup ? it.group : null;
|
|
849
|
+
lastGroup = it.group;
|
|
850
|
+
const segs = (_a2 = schema.byPath[it.label]) == null ? void 0 : _a2.segs;
|
|
851
|
+
const dot = segs ? it.label.length - segs[segs.length - 1].length : it.label.search(/[^.]*$/);
|
|
852
|
+
const Icon = TYPE_ICON2[it.type];
|
|
853
|
+
const raw = it.label.replace(/^"(.*)"$/, "$1");
|
|
854
|
+
const vs = it.kind === "value" && valueStyle(raw);
|
|
855
|
+
return /* @__PURE__ */ jsxs2("li", { children: [
|
|
856
|
+
head && /* @__PURE__ */ jsx2("p", { className: `px-2 pb-1 text-interface-titles-caption text-text-default-subdued ${i > 0 ? "pt-2" : ""}`, children: head.toUpperCase() }),
|
|
857
|
+
/* @__PURE__ */ jsxs2("div", { "data-hl": i === hl || void 0, style: { scrollMarginTop: 28 }, onMouseMove: () => i !== hl && setHl(i), onClick: () => accept(it), className: `${row} ${i === hl ? "bg-surface-color-blue-default-subtle" : ""}`, children: [
|
|
858
|
+
it.kind === "field" && /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
859
|
+
Icon && /* @__PURE__ */ jsx2(Icon, { size: 13, className: "shrink-0 text-icon-subtle" }),
|
|
860
|
+
/* @__PURE__ */ jsx2("span", { className: "min-w-0 truncate font-mono text-code-editor-small", children: it.sub ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
861
|
+
/* @__PURE__ */ jsx2("span", { className: "font-semibold text-base-blue-1100", children: it.label }),
|
|
862
|
+
/* @__PURE__ */ jsxs2("span", { className: "text-text-default-subtle", children: [
|
|
863
|
+
" ",
|
|
864
|
+
it.sub
|
|
865
|
+
] })
|
|
866
|
+
] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
867
|
+
/* @__PURE__ */ jsx2("span", { className: "text-text-default-subtle", children: it.label.slice(0, dot) }),
|
|
868
|
+
/* @__PURE__ */ jsx2("span", { className: "font-semibold text-base-blue-1100", children: it.label.slice(dot) })
|
|
869
|
+
] }) }),
|
|
870
|
+
/* @__PURE__ */ jsx2("span", { className: "flex-1" }),
|
|
871
|
+
it.count !== void 0 && /* @__PURE__ */ jsx2("span", { className: "w-9 shrink-0 text-right text-interface-labels-xs-normal text-text-default-subtle", children: kfmt(it.count) })
|
|
872
|
+
] }),
|
|
873
|
+
(it.kind === "op" || it.kind === "kw" || it.kind === "fn") && /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
874
|
+
/* @__PURE__ */ jsx2("span", { className: `shrink-0 font-mono text-code-editor-small font-semibold ${it.num ? ROLE.num : it.str ? ROLE.str : "text-text-color-purple"}`, children: it.label }),
|
|
875
|
+
it.sub && /* @__PURE__ */ jsx2("span", { className: "ml-auto min-w-0 truncate text-interface-body-s-normal text-text-default-subdued", children: it.sub })
|
|
876
|
+
] }),
|
|
877
|
+
it.kind === "value" && /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
878
|
+
vs ? /* @__PURE__ */ jsx2("span", { style: { ...vs, padding: vs.background ? "0 4px" : 0 }, className: "min-w-0 truncate font-mono text-code-editor-small", children: raw }) : /* @__PURE__ */ jsx2("span", { className: `min-w-0 truncate font-mono text-code-editor-small ${it.label.startsWith('"') ? ROLE.str : it.label === "true" || it.label === "false" ? ROLE.bool : ROLE.num}`, children: it.label }),
|
|
879
|
+
it.total ? /* @__PURE__ */ jsx2("span", { className: "ml-auto h-1 w-14 shrink-0 overflow-hidden rounded-full bg-surface-hover-l1-hover", children: /* @__PURE__ */ jsx2("span", { className: "block h-full rounded-full bg-base-blue-500", style: { width: Math.max(4, it.count / it.total * 100) + "%" } }) }) : null,
|
|
880
|
+
it.count !== void 0 && /* @__PURE__ */ jsx2("span", { className: "w-9 shrink-0 text-right text-interface-labels-xs-normal text-text-default-subtle", children: kfmt(it.count) })
|
|
881
|
+
] }),
|
|
882
|
+
i === hl && (it.kind === "field" || it.kind === "value") && /* @__PURE__ */ jsx2("kbd", { className: `${it.kind === "field" || it.total ? "" : "ml-auto"} shrink-0 rounded border border-stroke-subsection bg-surface-default-ground px-1 font-sans text-[10px] leading-4 text-text-default-subtle`, children: "Enter" })
|
|
883
|
+
] })
|
|
884
|
+
] }, i);
|
|
885
|
+
};
|
|
886
|
+
return /* @__PURE__ */ jsx2("div", { "data-qbox": "", className: "relative h-8 min-w-0 flex-1", children: /* @__PURE__ */ jsxs2("div", { className: `absolute inset-x-0 top-0 rounded-md border ${lifted ? `z-40 bg-surface-default-l1 shadow-e300 ${showNotice && runErrors ? "border-stroke-red-regular" : "border-stroke-active"}` : `${runErrors && parsed.errors.length ? "border-stroke-red-regular" : "border-stroke-subsection"} bg-surface-default-underground`}`, children: [
|
|
887
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-start", children: [
|
|
888
|
+
/* @__PURE__ */ jsx2("span", { className: `flex h-[30px] shrink-0 items-center pl-2 ${adv ? "invisible" : ""}`, children: /* @__PURE__ */ jsx2(Funnel, { size: 14, className: "text-icon-default" }) }),
|
|
889
|
+
/* @__PURE__ */ jsxs2("div", { className: `group/filter relative min-w-0 flex-1 ${adv ? "invisible" : ""}`, children: [
|
|
890
|
+
/* @__PURE__ */ jsxs2("div", { ref: pre, "aria-hidden": "true", style: focus ? { maxHeight: 210 } : void 0, className: `pointer-events-none px-2 py-[5px] font-mono text-code-editor-small leading-5 ${focus ? "overflow-hidden whitespace-pre-wrap break-words" : "h-[30px] overflow-hidden whitespace-pre"}`, children: [
|
|
891
|
+
highlighted,
|
|
892
|
+
"\u200B"
|
|
893
|
+
] }),
|
|
894
|
+
/* @__PURE__ */ jsx2(
|
|
895
|
+
"textarea",
|
|
896
|
+
{
|
|
897
|
+
ref: ta,
|
|
898
|
+
rows: 1,
|
|
899
|
+
wrap: focus ? "soft" : "off",
|
|
900
|
+
value: text,
|
|
901
|
+
spellCheck: false,
|
|
902
|
+
"aria-label": "Filter",
|
|
903
|
+
placeholder,
|
|
904
|
+
onSelect: (e) => setRanged(e.target.selectionStart !== e.target.selectionEnd),
|
|
905
|
+
onChange,
|
|
906
|
+
onKeyDown,
|
|
907
|
+
onKeyUp: (e) => {
|
|
908
|
+
if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key) || !open && ["ArrowUp", "ArrowDown"].includes(e.key)) sync();
|
|
909
|
+
},
|
|
910
|
+
onClick: () => {
|
|
911
|
+
sync();
|
|
912
|
+
setOpen(true);
|
|
913
|
+
},
|
|
914
|
+
onFocus: () => {
|
|
915
|
+
setFocus(true);
|
|
916
|
+
setOpen(true);
|
|
917
|
+
const pretty = parsed.ast && !parsed.errors.length ? format(parsed.ast, null, true) : text;
|
|
918
|
+
if (pretty === text) return sync();
|
|
919
|
+
const n = text.slice(0, ta.current.selectionStart).replace(/\s/g, "").length;
|
|
920
|
+
let i = 0;
|
|
921
|
+
for (let k = 0; i < pretty.length && k < n; i++) if (!/\s/.test(pretty[i])) k++;
|
|
922
|
+
nextCaret.current = i;
|
|
923
|
+
setText(pretty);
|
|
924
|
+
},
|
|
925
|
+
onBlur: () => {
|
|
926
|
+
setFocus(false);
|
|
927
|
+
setOpen(false);
|
|
928
|
+
if (text.includes("\n")) setText(parsed.ast && !parsed.errors.length ? format(parsed.ast) : text.replace(/\s*\n\s*/g, " "));
|
|
929
|
+
ta.current.scrollTop = 0;
|
|
930
|
+
if (pre.current) pre.current.scrollTop = 0;
|
|
931
|
+
},
|
|
932
|
+
onScroll: (e) => {
|
|
933
|
+
if (pre.current) pre.current.scrollTop = e.target.scrollTop;
|
|
934
|
+
},
|
|
935
|
+
className: `absolute inset-0 h-full w-full resize-none ${focus ? "no-scrollbar overflow-y-auto" : "overflow-hidden"} bg-transparent px-2 py-[5px] font-mono text-code-editor-small leading-5 text-transparent caret-[var(--color-text-default-regular)] outline-none placeholder:text-text-default-disabled`
|
|
936
|
+
}
|
|
937
|
+
)
|
|
938
|
+
] }),
|
|
939
|
+
text && !adv && /* @__PURE__ */ jsxs2("span", { className: "flex h-[30px] shrink-0 items-center", children: [
|
|
940
|
+
/* @__PURE__ */ jsx2("button", { onMouseDown: (e) => e.preventDefault(), onClick: () => edit("", 0, true), "data-pqb-tip": "Clear filter", "aria-label": "Clear filter", className: "grid h-6 w-6 place-items-center rounded text-icon-default hover:bg-surface-hover-l1-hover", children: /* @__PURE__ */ jsx2(X2, { size: 13 }) }),
|
|
941
|
+
focus && /* @__PURE__ */ jsx2("button", { onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
942
|
+
var _a2;
|
|
943
|
+
return (_a2 = navigator.clipboard) == null ? void 0 : _a2.writeText(text);
|
|
944
|
+
}, "data-pqb-tip": "Copy query", "aria-label": "Copy query", className: "grid h-6 w-6 place-items-center rounded text-icon-default hover:bg-surface-hover-l1-hover", children: /* @__PURE__ */ jsx2(Copy2, { size: 13 }) }),
|
|
945
|
+
/* @__PURE__ */ jsx2("span", { className: "w-1" })
|
|
946
|
+
] }),
|
|
947
|
+
/* @__PURE__ */ jsx2("span", { className: "flex h-[30px] shrink-0 items-center gap-0.5 px-1", children: /* @__PURE__ */ jsxs2("button", { onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
948
|
+
if (!adv) ta.current.blur();
|
|
949
|
+
setAdv(!adv);
|
|
950
|
+
}, "aria-pressed": adv, "data-pqb-tip": "Build the filter with AND / OR groups", className: `flex h-6 items-center gap-1 rounded px-1.5 ${adv ? "bg-surface-color-blue-default-subtle text-text-color-blue" : "text-text-default-regular hover:bg-surface-hover-l1-hover"}`, children: [
|
|
951
|
+
/* @__PURE__ */ jsx2(TreeStructure, { size: 14, className: adv ? "" : "text-icon-default" }),
|
|
952
|
+
/* @__PURE__ */ jsx2("span", { className: "whitespace-nowrap text-interface-body-s-heavy", children: "Advanced filter" })
|
|
953
|
+
] }) }),
|
|
954
|
+
(tools || actions) && /* @__PURE__ */ jsx2("div", { className: "flex shrink-0 self-stretch border-l border-stroke-subsection pl-1 pr-1", children: /* @__PURE__ */ jsxs2("span", { className: "flex min-h-[30px] flex-col items-stretch", children: [
|
|
955
|
+
/* @__PURE__ */ jsx2("span", { className: "flex min-h-[30px] items-center", children: tools }),
|
|
956
|
+
focus && !adv && actions
|
|
957
|
+
] }) })
|
|
958
|
+
] }),
|
|
959
|
+
adv && /* @__PURE__ */ jsx2(
|
|
960
|
+
Builder,
|
|
961
|
+
{
|
|
962
|
+
text,
|
|
963
|
+
schema,
|
|
964
|
+
onCancel: () => setAdv(false),
|
|
965
|
+
onApply: (t) => {
|
|
966
|
+
setAdv(false);
|
|
967
|
+
edit(t, t.length, false);
|
|
968
|
+
run(t);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
),
|
|
972
|
+
showCard && /* @__PURE__ */ jsxs2("div", { className: "border-t border-stroke-subsection", onMouseDown: (e) => e.preventDefault(), children: [
|
|
973
|
+
/* @__PURE__ */ jsx2("div", { className: `${grouped || chips && ((_b = rowsOf[0]) == null ? void 0 : _b.head) ? "hidden" : "flex"} items-center justify-between gap-3 px-3 pb-1 pt-2`, children: /* @__PURE__ */ jsx2("span", { className: "min-w-0 truncate text-interface-titles-caption text-text-default-subdued", children: sugg.title.toUpperCase() }) }),
|
|
974
|
+
/* @__PURE__ */ jsx2("ul", { ref: list, style: { maxHeight: 180 }, className: "no-scrollbar overflow-y-auto px-1 pb-1", children: chips ? rowsOf.map((r) => /* @__PURE__ */ jsxs2("li", { children: [
|
|
975
|
+
r.head && /* @__PURE__ */ jsx2("p", { className: "px-2 pb-1 pt-2 text-interface-titles-caption text-text-default-subdued", children: (r === rowsOf[0] && r.head !== sugg.title ? `${sugg.title} / ${r.head}` : r.head).toUpperCase() }),
|
|
976
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap items-center gap-1 px-2 py-1", children: [
|
|
977
|
+
r.cls && /* @__PURE__ */ jsx2("span", { className: "w-8 shrink-0 text-interface-labels-xs-normal text-text-default-subdued", children: r.cls }),
|
|
978
|
+
r.items.map(([it, i]) => {
|
|
979
|
+
const raw = it.label.replace(/^"(.*)"$/, "$1");
|
|
980
|
+
const vs = valueStyle(raw);
|
|
981
|
+
return /* @__PURE__ */ jsx2("button", { "data-hl": i === hl || void 0, onMouseMove: () => i !== hl && setHl(i), onClick: () => accept(it), style: { ...vs, outline: i === hl ? "2px solid var(--color-stroke-active)" : "none", outlineOffset: 1 }, className: `h-6 rounded px-1.5 font-mono text-code-editor-small ${(vs == null ? void 0 : vs.background) ? "" : "bg-surface-default-underground"} ${vs ? "" : raw === "true" || raw === "false" ? ROLE.bool : ROLE.str}`, children: vs ? raw : it.label }, i);
|
|
982
|
+
})
|
|
983
|
+
] })
|
|
984
|
+
] }, r.items[0][1])) : grouped ? groupsOf.map((g) => /* @__PURE__ */ jsxs2("li", { children: [
|
|
985
|
+
/* @__PURE__ */ jsx2("p", { style: { position: "sticky", top: 0, zIndex: 1 }, className: "flex items-center justify-between gap-3 bg-surface-default-l1 px-2 pb-1 pt-2 text-interface-titles-caption text-text-default-subdued", children: /* @__PURE__ */ jsx2("span", { className: "min-w-0 truncate", children: (g.group ? `${sugg.title} / ${g.group}` : sugg.title).toUpperCase() }) }),
|
|
986
|
+
/* @__PURE__ */ jsx2("ul", { children: g.items.map(([it, i]) => renderRow(it, i, true)) })
|
|
987
|
+
] }, g.items[0][1])) : items.map((it, i) => !it.pin && renderRow(it, i)) }),
|
|
988
|
+
items.some((it) => it.pin) && /* @__PURE__ */ jsx2("ul", { className: "border-t border-stroke-subsection px-1 pb-1", children: items.map((it, i) => it.pin && renderRow(it, i)) }),
|
|
989
|
+
/* @__PURE__ */ jsx2("div", { className: "flex items-center gap-3 border-t border-stroke-subsection px-3 py-1.5 text-interface-labels-xs-light text-text-default-subdued", children: [
|
|
990
|
+
["\u2191\u2193", "move"],
|
|
991
|
+
["Enter", hl < 0 ? "run" : "add"],
|
|
992
|
+
["Esc", "close"],
|
|
993
|
+
[MAC ? "\u2318 Enter" : "Ctrl Enter", "run"],
|
|
994
|
+
[MAC ? "\u21E7 Enter" : "Shift Enter", "new line"]
|
|
995
|
+
].map(([k, l]) => /* @__PURE__ */ jsxs2("span", { className: "flex items-center gap-1", children: [
|
|
996
|
+
/* @__PURE__ */ jsx2("kbd", { className: "rounded border border-stroke-subsection bg-surface-default-ground px-1 font-sans text-[10px] leading-4 text-text-default-subtle", children: k }),
|
|
997
|
+
l
|
|
998
|
+
] }, k)) })
|
|
999
|
+
] }),
|
|
1000
|
+
showNotice && /* @__PURE__ */ jsxs2("div", { className: "flex items-start gap-1.5 border-t border-stroke-subsection px-2.5 py-1.5", onMouseDown: (e) => e.preventDefault(), children: [
|
|
1001
|
+
/* @__PURE__ */ jsx2(Warning2, { size: 14, weight: "fill", className: "mt-[3px] shrink-0 text-text-color-red" }),
|
|
1002
|
+
/* @__PURE__ */ jsxs2("div", { className: "min-w-0 flex-1", children: [
|
|
1003
|
+
/* @__PURE__ */ jsx2("p", { className: "text-interface-labels-xs-normal leading-5 text-text-color-red", children: err.msg }),
|
|
1004
|
+
(err.fix || ((_c = err.near) == null ? void 0 : _c.length) > 0) && /* @__PURE__ */ jsxs2("div", { className: "mt-1 flex flex-wrap items-center gap-1", children: [
|
|
1005
|
+
/* @__PURE__ */ jsx2("span", { className: "mr-1 text-interface-labels-xs-light text-text-default-subdued", children: "Suggestions" }),
|
|
1006
|
+
[].concat(err.fix || []).map((f) => /* @__PURE__ */ jsxs2("button", { onClick: () => fix(f.s, f.e, f.text), style: { minHeight: 24 }, className: "max-w-full break-words rounded border border-stroke-subsection px-2 py-0.5 text-left font-mono text-interface-labels-xs-normal text-base-blue-1100 hover:bg-surface-hover-l1-hover", children: [
|
|
1007
|
+
f.verb || "Use",
|
|
1008
|
+
" ",
|
|
1009
|
+
f.label
|
|
1010
|
+
] }, f.verb + f.label)),
|
|
1011
|
+
(_d = err.near) == null ? void 0 : _d.map((n) => /* @__PURE__ */ jsx2("button", { onClick: () => fix(err.s, err.e, n), style: { minHeight: 24 }, className: "max-w-full break-words rounded border border-stroke-subsection px-2 py-0.5 text-left font-mono text-interface-labels-xs-normal text-base-blue-1100 hover:bg-surface-hover-l1-hover", children: n }, n))
|
|
1012
|
+
] }),
|
|
1013
|
+
visible.length > 1 && /* @__PURE__ */ jsxs2("p", { className: "mt-1 text-interface-labels-xs-light text-text-default-subdued", children: [
|
|
1014
|
+
"and ",
|
|
1015
|
+
visible.length - 1,
|
|
1016
|
+
" more ",
|
|
1017
|
+
visible.length === 2 ? "problem" : "problems"
|
|
1018
|
+
] })
|
|
1019
|
+
] })
|
|
1020
|
+
] })
|
|
1021
|
+
] }) });
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// src/react/Saved.jsx
|
|
1025
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
1026
|
+
import { MagnifyingGlass as MagnifyingGlass2 } from "@phosphor-icons/react";
|
|
1027
|
+
import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1028
|
+
var ICON = { width: 13, height: 13, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true };
|
|
1029
|
+
var PIN = "M9 3h6l-1 6 4 4H6l4-4zM12 13v8";
|
|
1030
|
+
var FUNNEL = "M3 5h18l-7 8v6l-4 2v-8z";
|
|
1031
|
+
var BELL = "M6 16v-5a6 6 0 0 1 12 0v5l2 2H4zM10 21h4";
|
|
1032
|
+
var BOOKMARK = "M6 3h12v18l-6-4-6 4z";
|
|
1033
|
+
function QueryChip({ query, schema }) {
|
|
1034
|
+
return /* @__PURE__ */ jsxs3("code", { style: { fontSize: 11, lineHeight: "16px", paddingTop: 1, paddingBottom: 1 }, className: "flex w-fit max-w-full items-center gap-1 rounded border border-stroke-subsection bg-surface-default-underground px-1.5 font-mono text-text-default-regular", children: [
|
|
1035
|
+
/* @__PURE__ */ jsx3("svg", { ...ICON, width: 12, height: 12, className: "shrink-0 text-icon-default", children: /* @__PURE__ */ jsx3("path", { d: FUNNEL }) }),
|
|
1036
|
+
/* @__PURE__ */ jsx3("span", { "data-pqb-tip": query, "data-mono": "", "data-trunc": "", className: "min-w-0 truncate", children: paint(query.replace(/\s+/g, " ").trim(), schema) })
|
|
1037
|
+
] });
|
|
1038
|
+
}
|
|
1039
|
+
function Saved({ saved, loading, schema, onPick, onPin, onDelete, onUpdate, onAlert, onSearch, onClose }) {
|
|
1040
|
+
const [q, setQ] = useState3("");
|
|
1041
|
+
const [editing, setEditing] = useState3(null);
|
|
1042
|
+
const [removing, setRemoving] = useState3(null);
|
|
1043
|
+
const ref = useRef3(null);
|
|
1044
|
+
const close = useRef3(onClose);
|
|
1045
|
+
close.current = onClose;
|
|
1046
|
+
useEffect3(() => {
|
|
1047
|
+
const out = (e) => {
|
|
1048
|
+
var _a;
|
|
1049
|
+
return !((_a = ref.current) == null ? void 0 : _a.contains(e.target)) && !e.target.closest("[data-pqb-saved]") && close.current();
|
|
1050
|
+
};
|
|
1051
|
+
document.addEventListener("mousedown", out, true);
|
|
1052
|
+
return () => document.removeEventListener("mousedown", out, true);
|
|
1053
|
+
}, []);
|
|
1054
|
+
const x = q.trim().toLowerCase();
|
|
1055
|
+
const hit = saved.filter((s) => !x || s.name.toLowerCase().includes(x) || s.query.toLowerCase().includes(x));
|
|
1056
|
+
const err = editing && editing.query.trim() ? parse(editing.query, schema).errors[0] : null;
|
|
1057
|
+
const nameTaken = editing && saved.some((s) => s.id !== editing.id && s.name === editing.name.trim());
|
|
1058
|
+
const submit = () => {
|
|
1059
|
+
if (!editing.name.trim() || !editing.query.trim() || err || nameTaken) return;
|
|
1060
|
+
onUpdate(saved.find((s) => s.id === editing.id), { name: editing.name.trim(), query: format(parse(editing.query, schema).ast) });
|
|
1061
|
+
setEditing(null);
|
|
1062
|
+
};
|
|
1063
|
+
const act = "grid h-6 w-6 place-items-center rounded text-text-default-subtle hover:bg-surface-default-l1 hover:text-text-default-regular";
|
|
1064
|
+
const item = (s) => removing === s.id ? /* @__PURE__ */ jsxs3("div", { onKeyDown: (e) => e.key === "Escape" && (e.stopPropagation(), setRemoving(null)), className: "flex items-center gap-1 bg-surface-hover-l1-hover px-2.5 py-1.5", children: [
|
|
1065
|
+
/* @__PURE__ */ jsxs3("span", { className: "min-w-0 flex-1 truncate text-interface-body-s-heavy text-text-default-regular", children: [
|
|
1066
|
+
"Delete \u201C",
|
|
1067
|
+
s.name,
|
|
1068
|
+
"\u201D?"
|
|
1069
|
+
] }),
|
|
1070
|
+
/* @__PURE__ */ jsx3("button", { onClick: () => (onDelete(s), setRemoving(null)), className: "h-6 rounded px-2 text-interface-labels-xs-normal font-semibold text-text-color-red hover:bg-surface-default-l1", children: "Delete" }),
|
|
1071
|
+
/* @__PURE__ */ jsx3("button", { autoFocus: true, onClick: () => setRemoving(null), className: "h-6 rounded border border-stroke-subsection bg-surface-default-l1 px-2 text-interface-labels-xs-normal font-semibold text-text-default-regular", children: "Cancel" })
|
|
1072
|
+
] }, s.id) : (editing == null ? void 0 : editing.id) === s.id ? /* @__PURE__ */ jsxs3(
|
|
1073
|
+
"div",
|
|
1074
|
+
{
|
|
1075
|
+
onKeyDown: (e) => {
|
|
1076
|
+
if (e.key === "Escape") e.stopPropagation(), setEditing(null);
|
|
1077
|
+
else if (e.key === "Enter" && !e.shiftKey && e.target.tagName !== "BUTTON") e.preventDefault(), submit();
|
|
1078
|
+
},
|
|
1079
|
+
className: "flex flex-col gap-1.5 bg-surface-hover-l1-hover px-2.5 py-1.5",
|
|
1080
|
+
children: [
|
|
1081
|
+
/* @__PURE__ */ jsx3("input", { autoFocus: true, "aria-label": "Name", value: editing.name, onFocus: (e) => e.target.select(), onChange: (e) => setEditing({ ...editing, name: e.target.value }), className: "rounded border border-stroke-subsection bg-surface-default-l1 px-1.5 py-1 text-interface-body-s-heavy text-text-default-regular outline-none focus:border-stroke-active" }),
|
|
1082
|
+
/* @__PURE__ */ jsx3("textarea", { "aria-label": "Query", rows: 3, spellCheck: false, value: editing.query, onChange: (e) => setEditing({ ...editing, query: e.target.value }), style: { fontSize: 11, lineHeight: "16px" }, className: "resize-none rounded border border-stroke-subsection bg-surface-default-l1 px-1.5 py-1 font-mono text-text-default-regular outline-none focus:border-stroke-active" }),
|
|
1083
|
+
err && (() => {
|
|
1084
|
+
const t = editing.query.replace(/\n/g, " ");
|
|
1085
|
+
const from = Math.min(err.s, err.at ?? err.s);
|
|
1086
|
+
const to = Math.max(err.e, err.at ?? err.e);
|
|
1087
|
+
const lo = Math.max(0, from - 30);
|
|
1088
|
+
const hi = Math.min(t.length, to + 30);
|
|
1089
|
+
const fixes = [...[].concat(err.fix || []), ...(err.near || []).map((n) => ({ s: err.s, e: err.e, text: n, label: n, plain: true }))];
|
|
1090
|
+
return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-1", children: [
|
|
1091
|
+
/* @__PURE__ */ jsx3("p", { className: "text-interface-labels-xs-normal text-text-color-red", children: err.msg }),
|
|
1092
|
+
/* @__PURE__ */ jsxs3("code", { style: { fontSize: 11, lineHeight: "16px" }, className: "whitespace-pre-wrap break-all rounded border border-stroke-subsection bg-surface-default-l1 px-1.5 py-0.5 font-mono text-text-default-subdued", children: [
|
|
1093
|
+
lo > 0 && "\u2026",
|
|
1094
|
+
t.slice(lo, from),
|
|
1095
|
+
/* @__PURE__ */ jsxs3("span", { className: "rounded-sm bg-base-red-100 text-text-color-red", children: [
|
|
1096
|
+
t.slice(from, err.s),
|
|
1097
|
+
/* @__PURE__ */ jsx3("b", { className: "font-semibold", children: t.slice(err.s, err.e) }),
|
|
1098
|
+
t.slice(err.e, to) || (from === to ? " " : "")
|
|
1099
|
+
] }),
|
|
1100
|
+
t.slice(to, hi),
|
|
1101
|
+
hi < t.length && "\u2026"
|
|
1102
|
+
] }),
|
|
1103
|
+
fixes.length > 0 && /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
1104
|
+
/* @__PURE__ */ jsx3("span", { className: "mr-1 text-interface-labels-xs-light text-text-default-subdued", children: "Suggestions" }),
|
|
1105
|
+
fixes.map((f) => /* @__PURE__ */ jsx3("button", { onClick: () => setEditing({ ...editing, query: editing.query.slice(0, f.s) + f.text + editing.query.slice(f.e) }), style: { minHeight: 24 }, className: "max-w-full break-words rounded border border-stroke-subsection bg-surface-default-l1 px-2 py-0.5 text-left font-mono text-interface-labels-xs-normal text-base-blue-1100 hover:bg-surface-default-underground", children: f.plain ? f.label : `${f.verb || "Use"} ${f.label}` }, (f.verb || "") + f.label))
|
|
1106
|
+
] })
|
|
1107
|
+
] });
|
|
1108
|
+
})(),
|
|
1109
|
+
!err && nameTaken && /* @__PURE__ */ jsxs3("p", { className: "text-interface-labels-xs-normal text-text-color-red", children: [
|
|
1110
|
+
"A saved query is already called ",
|
|
1111
|
+
editing.name.trim()
|
|
1112
|
+
] }),
|
|
1113
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex justify-end gap-2", children: [
|
|
1114
|
+
/* @__PURE__ */ jsx3("button", { onClick: () => setEditing(null), className: "h-6 rounded bg-surface-default-l1 px-2 text-interface-labels-xs-normal font-semibold text-text-default-regular hover:bg-surface-default-underground", children: "Cancel" }),
|
|
1115
|
+
/* @__PURE__ */ jsx3("button", { disabled: !editing.name.trim() || !editing.query.trim() || !!err || nameTaken, onClick: submit, className: "h-6 rounded-md border border-stroke-active bg-surface-default-action px-2.5 text-interface-labels-xs-normal font-semibold text-text-default-static hover:bg-surface-default-action-hover disabled:cursor-not-allowed disabled:opacity-50", children: "Save" })
|
|
1116
|
+
] })
|
|
1117
|
+
]
|
|
1118
|
+
},
|
|
1119
|
+
s.id
|
|
1120
|
+
) : /* @__PURE__ */ jsxs3("div", { className: "group flex items-start gap-2 px-2.5 py-1.5 hover:bg-surface-hover-l1-hover", children: [
|
|
1121
|
+
/* @__PURE__ */ jsxs3("button", { onClick: () => onPick(s), style: { gap: 3 }, className: "flex min-w-0 flex-1 flex-col text-left", children: [
|
|
1122
|
+
/* @__PURE__ */ jsx3("span", { "data-pqb-tip": s.name, "data-trunc": "", className: "max-w-full truncate text-interface-body-s-heavy text-text-default-regular", children: s.name }),
|
|
1123
|
+
/* @__PURE__ */ jsx3(QueryChip, { query: s.query, schema })
|
|
1124
|
+
] }),
|
|
1125
|
+
/* @__PURE__ */ jsxs3("span", { className: "grid shrink-0 self-center", children: [
|
|
1126
|
+
s.pinned && /* @__PURE__ */ jsx3("svg", { ...ICON, width: 14, height: 14, role: "img", "aria-label": "Pinned", style: { gridArea: "1 / 1", justifySelf: "end", marginRight: 5 }, className: "text-text-color-blue group-hover:hidden", children: /* @__PURE__ */ jsx3("path", { d: PIN, fill: "currentColor" }) }),
|
|
1127
|
+
/* @__PURE__ */ jsxs3("span", { style: { gridArea: "1 / 1" }, className: "hidden gap-0.5 group-hover:flex", children: [
|
|
1128
|
+
onPin && /* @__PURE__ */ jsx3("button", { "aria-label": s.pinned ? `Unpin ${s.name}` : `Pin ${s.name}`, "data-pqb-tip": s.pinned ? "Unpin" : "Pin", onClick: () => onPin(s, !s.pinned), className: act, children: /* @__PURE__ */ jsx3("svg", { ...ICON, children: /* @__PURE__ */ jsx3("path", { d: s.pinned ? PIN + "M4 4l16 16" : PIN }) }) }),
|
|
1129
|
+
onAlert && /* @__PURE__ */ jsx3("button", { "aria-label": `Create an alert from ${s.name}`, "data-pqb-tip": "Create alert", onClick: () => onAlert(s.query), className: act, children: /* @__PURE__ */ jsx3("svg", { ...ICON, children: /* @__PURE__ */ jsx3("path", { d: BELL }) }) }),
|
|
1130
|
+
onUpdate && /* @__PURE__ */ jsx3("button", { "aria-label": `Edit ${s.name}`, "data-pqb-tip": "Edit", onClick: () => (setRemoving(null), setEditing({ id: s.id, name: s.name, query: s.query })), className: act, children: /* @__PURE__ */ jsx3("svg", { ...ICON, children: /* @__PURE__ */ jsx3("path", { d: "M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4" }) }) }),
|
|
1131
|
+
onDelete && /* @__PURE__ */ jsx3("button", { "aria-label": `Delete ${s.name}`, "data-pqb-tip": "Delete", onClick: () => (setEditing(null), setRemoving(s.id)), className: `${act} hover:text-text-color-red`, children: /* @__PURE__ */ jsx3("svg", { ...ICON, children: /* @__PURE__ */ jsx3("path", { d: "M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3" }) }) })
|
|
1132
|
+
] })
|
|
1133
|
+
] })
|
|
1134
|
+
] }, s.id);
|
|
1135
|
+
const pinned = hit.filter((s) => s.pinned);
|
|
1136
|
+
const rest = hit.filter((s) => !s.pinned);
|
|
1137
|
+
return /* @__PURE__ */ jsxs3("div", { ref, className: "absolute right-0 top-9 z-50 flex w-[380px] flex-col rounded-md border border-stroke-subsection bg-surface-default-l1 shadow-e300", children: [
|
|
1138
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex h-9 items-center gap-1.5 border-b border-stroke-subsection px-3", children: [
|
|
1139
|
+
/* @__PURE__ */ jsx3(MagnifyingGlass2, { size: 14, className: "shrink-0 text-icon-default" }),
|
|
1140
|
+
/* @__PURE__ */ jsx3(
|
|
1141
|
+
"input",
|
|
1142
|
+
{
|
|
1143
|
+
autoFocus: true,
|
|
1144
|
+
value: q,
|
|
1145
|
+
onChange: (e) => {
|
|
1146
|
+
setQ(e.target.value);
|
|
1147
|
+
onSearch == null ? void 0 : onSearch(e.target.value);
|
|
1148
|
+
},
|
|
1149
|
+
onKeyDown: (e) => {
|
|
1150
|
+
if (e.key === "Escape") onClose();
|
|
1151
|
+
else if (e.key === "Enter" && hit[0]) onPick(hit[0]);
|
|
1152
|
+
},
|
|
1153
|
+
placeholder: "Search saved queries",
|
|
1154
|
+
className: "min-w-0 flex-1 bg-transparent text-interface-body-s-normal text-text-default-regular outline-none placeholder:text-text-default-disabled"
|
|
1155
|
+
}
|
|
1156
|
+
)
|
|
1157
|
+
] }),
|
|
1158
|
+
/* @__PURE__ */ jsxs3("div", { style: { maxHeight: "min(520px, 70vh)" }, className: "overflow-y-auto no-scrollbar py-1", children: [
|
|
1159
|
+
loading && /* @__PURE__ */ jsx3("p", { className: "px-3 py-3 text-interface-body-s-light text-text-default-subdued", children: "Loading saved queries" }),
|
|
1160
|
+
pinned.length > 0 && /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
1161
|
+
/* @__PURE__ */ jsx3("p", { className: "px-2.5 pb-0.5 pt-1 text-interface-titles-caption text-text-default-subdued", children: "PINNED" }),
|
|
1162
|
+
pinned.map(item)
|
|
1163
|
+
] }),
|
|
1164
|
+
rest.length > 0 && /* @__PURE__ */ jsxs3("div", { className: pinned.length ? "mt-1 border-t border-stroke-subsection pt-1" : "", children: [
|
|
1165
|
+
/* @__PURE__ */ jsx3("p", { className: "px-2.5 pb-0.5 pt-1 text-interface-titles-caption text-text-default-subdued", children: "ALL SAVED" }),
|
|
1166
|
+
rest.map(item)
|
|
1167
|
+
] }),
|
|
1168
|
+
!loading && !hit.length && /* @__PURE__ */ jsx3("p", { className: "px-3 py-5 text-center text-interface-body-s-light text-text-default-subdued", children: q ? "No saved queries match." : "No saved queries yet. Type a filter and press Save." })
|
|
1169
|
+
] })
|
|
1170
|
+
] });
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
// src/react/PostgresQueryBox.jsx
|
|
1174
|
+
import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1175
|
+
var PostgresQueryBox = forwardRef(function PostgresQueryBox2({
|
|
1176
|
+
schema,
|
|
1177
|
+
value,
|
|
1178
|
+
defaultValue = "",
|
|
1179
|
+
onChange,
|
|
1180
|
+
onRun,
|
|
1181
|
+
placeholder = 'Filter calls, e.g. data.request.verb == "GET" AND data.response.statusCode >= 500',
|
|
1182
|
+
runLabel = "Run query",
|
|
1183
|
+
tools,
|
|
1184
|
+
saved,
|
|
1185
|
+
savedCount,
|
|
1186
|
+
savedLoading,
|
|
1187
|
+
onSelectSaved,
|
|
1188
|
+
onPinSaved,
|
|
1189
|
+
onSaveQuery,
|
|
1190
|
+
onDeleteSaved,
|
|
1191
|
+
onUpdateSaved,
|
|
1192
|
+
onSavedSearch,
|
|
1193
|
+
onCreateAlert,
|
|
1194
|
+
className = ""
|
|
1195
|
+
}, ref) {
|
|
1196
|
+
const root = useRef4(null);
|
|
1197
|
+
const runRef = useRef4(null);
|
|
1198
|
+
const [own, setOwn] = useState4(defaultValue);
|
|
1199
|
+
const text = value ?? own;
|
|
1200
|
+
const setText = (t) => {
|
|
1201
|
+
if (value === void 0) setOwn(t);
|
|
1202
|
+
onChange == null ? void 0 : onChange(t);
|
|
1203
|
+
};
|
|
1204
|
+
const [runErrors, setRunErrors] = useState4(false);
|
|
1205
|
+
const [adv, setAdvState] = useState4(false);
|
|
1206
|
+
const [panel, setPanelState] = useState4(false);
|
|
1207
|
+
const setAdv = (v) => {
|
|
1208
|
+
setAdvState(v);
|
|
1209
|
+
if (v) setPanelState(false);
|
|
1210
|
+
};
|
|
1211
|
+
const setPanel = (v) => {
|
|
1212
|
+
setPanelState(v);
|
|
1213
|
+
if (v) setAdvState(false);
|
|
1214
|
+
};
|
|
1215
|
+
const parsed = text.trim() ? parse(text, schema) : null;
|
|
1216
|
+
const valid = !!parsed && !parsed.errors.length;
|
|
1217
|
+
const clean = valid ? format(parsed.ast) : "";
|
|
1218
|
+
const match = onUpdateSaved && (saved == null ? void 0 : saved.find((s) => s.query === clean));
|
|
1219
|
+
const [draft, setDraft] = useState4(null);
|
|
1220
|
+
const popRef = useRef4(null);
|
|
1221
|
+
const taken = draft && (saved == null ? void 0 : saved.some((s) => s.id !== (match == null ? void 0 : match.id) && s.name === draft.name.trim()));
|
|
1222
|
+
useEffect4(() => {
|
|
1223
|
+
if (!draft) return;
|
|
1224
|
+
const out = (e) => {
|
|
1225
|
+
var _a;
|
|
1226
|
+
return !((_a = popRef.current) == null ? void 0 : _a.contains(e.target)) && setDraft(null);
|
|
1227
|
+
};
|
|
1228
|
+
document.addEventListener("mousedown", out);
|
|
1229
|
+
return () => document.removeEventListener("mousedown", out);
|
|
1230
|
+
}, [!draft]);
|
|
1231
|
+
const submitDraft = () => {
|
|
1232
|
+
if (!draft.name.trim() || taken) return;
|
|
1233
|
+
if (match) onUpdateSaved(match, { name: draft.name.trim(), pinned: draft.pinned });
|
|
1234
|
+
else onSaveQuery({ name: draft.name.trim(), query: clean, pinned: draft.pinned });
|
|
1235
|
+
setDraft(null);
|
|
1236
|
+
};
|
|
1237
|
+
const openAlert = (q) => {
|
|
1238
|
+
var _a, _b;
|
|
1239
|
+
(_b = (_a = root.current) == null ? void 0 : _a.querySelector("textarea")) == null ? void 0 : _b.blur();
|
|
1240
|
+
setPanel(false);
|
|
1241
|
+
const p = parse(q, schema);
|
|
1242
|
+
onCreateAlert(format(p.ast), p.ast);
|
|
1243
|
+
};
|
|
1244
|
+
useImperativeHandle(ref, () => ({
|
|
1245
|
+
focus: () => {
|
|
1246
|
+
var _a, _b;
|
|
1247
|
+
return (_b = (_a = root.current) == null ? void 0 : _a.querySelector("textarea")) == null ? void 0 : _b.focus();
|
|
1248
|
+
},
|
|
1249
|
+
run: () => {
|
|
1250
|
+
var _a;
|
|
1251
|
+
return (_a = runRef.current) == null ? void 0 : _a.call(runRef);
|
|
1252
|
+
},
|
|
1253
|
+
setText,
|
|
1254
|
+
getText: () => text
|
|
1255
|
+
}));
|
|
1256
|
+
const pick = (s) => {
|
|
1257
|
+
var _a;
|
|
1258
|
+
onSelectSaved == null ? void 0 : onSelectSaved(s);
|
|
1259
|
+
setPanel(false);
|
|
1260
|
+
const p = parse(s.query, schema);
|
|
1261
|
+
const clean2 = p.errors.length ? s.query : format(p.ast);
|
|
1262
|
+
setText(clean2);
|
|
1263
|
+
(_a = runRef.current) == null ? void 0 : _a.call(runRef, clean2);
|
|
1264
|
+
};
|
|
1265
|
+
const extra = tools || saved ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
1266
|
+
tools,
|
|
1267
|
+
saved && /* @__PURE__ */ jsxs4("span", { className: "relative", children: [
|
|
1268
|
+
/* @__PURE__ */ jsxs4("button", { "data-pqb-saved": "", onMouseDown: (e) => e.preventDefault(), onClick: () => setPanel(!panel), "aria-expanded": panel, "data-pqb-tip": "Saved queries", className: `flex h-6 items-center gap-1.5 rounded px-1.5 hover:bg-surface-hover-l1-hover ${panel ? "bg-surface-hover-l1-hover" : ""}`, children: [
|
|
1269
|
+
/* @__PURE__ */ jsx4(BookmarksSimple, { size: 14, className: "shrink-0 text-icon-default" }),
|
|
1270
|
+
/* @__PURE__ */ jsx4("span", { className: "min-w-0 max-w-[200px] truncate text-interface-body-s-heavy text-text-default-regular", children: "Queries" }),
|
|
1271
|
+
/* @__PURE__ */ jsx4("span", { className: "rounded-full bg-surface-hover-l1-hover px-1.5 text-interface-labels-xxs-normal text-text-default-subdued", children: savedCount ?? saved.length }),
|
|
1272
|
+
/* @__PURE__ */ jsx4(CaretDown2, { size: 12, className: "shrink-0 text-text-default-subtle" })
|
|
1273
|
+
] }),
|
|
1274
|
+
panel && /* @__PURE__ */ jsx4(Saved, { saved, loading: savedLoading, schema, onPick: pick, onPin: onPinSaved, onDelete: onDeleteSaved, onUpdate: onUpdateSaved, onAlert: onCreateAlert && openAlert, onSearch: onSavedSearch, onClose: () => setPanel(false) })
|
|
1275
|
+
] })
|
|
1276
|
+
] }) : null;
|
|
1277
|
+
const actions = [
|
|
1278
|
+
onSaveQuery && ["Save", BOOKMARK, (e) => {
|
|
1279
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1280
|
+
setPanel(false);
|
|
1281
|
+
setDraft({ name: (match == null ? void 0 : match.name) ?? text.replace(/\b(?:data|metadata)\.[\w.-]+/g, (x) => x.split(".").pop()).replace(/\s+/g, " ").trim().slice(0, 60), pinned: !!(match == null ? void 0 : match.pinned), top: r.bottom + 6, left: Math.max(8, r.right - 280) });
|
|
1282
|
+
}],
|
|
1283
|
+
onCreateAlert && ["Create alert", BELL, () => openAlert(text)]
|
|
1284
|
+
].filter(Boolean);
|
|
1285
|
+
return /* @__PURE__ */ jsxs4("div", { ref: root, className: `pqb ${className}`, children: [
|
|
1286
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-start gap-2", children: [
|
|
1287
|
+
/* @__PURE__ */ jsx4(QueryBox, { text, setText, schema, onRun, tools: extra, actions: actions.length > 0 && actions.map(([label, d, go]) => /* @__PURE__ */ jsxs4("button", { disabled: !valid, onMouseDown: (e) => e.preventDefault(), onClick: go, className: "flex h-6 items-center gap-1.5 rounded px-1.5 text-left hover:bg-surface-hover-l1-hover disabled:cursor-not-allowed disabled:opacity-50", children: [
|
|
1288
|
+
/* @__PURE__ */ jsx4("svg", { ...ICON, width: 14, height: 14, className: "shrink-0 text-icon-default", children: /* @__PURE__ */ jsx4("path", { d }) }),
|
|
1289
|
+
/* @__PURE__ */ jsx4("span", { className: "whitespace-nowrap text-interface-body-s-normal text-text-default-regular", children: label })
|
|
1290
|
+
] }, label)), runErrors, setRunErrors, runRef, adv, setAdv, placeholder }),
|
|
1291
|
+
/* @__PURE__ */ jsxs4("button", { onClick: () => {
|
|
1292
|
+
var _a;
|
|
1293
|
+
return (_a = runRef.current) == null ? void 0 : _a.call(runRef);
|
|
1294
|
+
}, className: "flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-stroke-active bg-surface-default-action px-3 hover:bg-surface-default-action-hover", children: [
|
|
1295
|
+
/* @__PURE__ */ jsx4(Play, { size: 14, weight: "fill", className: "text-text-default-static" }),
|
|
1296
|
+
/* @__PURE__ */ jsx4("span", { className: "whitespace-nowrap text-interface-labels-xs-normal font-semibold text-text-default-static", children: runLabel })
|
|
1297
|
+
] })
|
|
1298
|
+
] }),
|
|
1299
|
+
/* @__PURE__ */ jsx4(Tips, { root }),
|
|
1300
|
+
draft && /* @__PURE__ */ jsxs4(
|
|
1301
|
+
"div",
|
|
1302
|
+
{
|
|
1303
|
+
ref: popRef,
|
|
1304
|
+
role: "dialog",
|
|
1305
|
+
"aria-label": "Save query as",
|
|
1306
|
+
onKeyDown: (e) => {
|
|
1307
|
+
if (e.key === "Escape") setDraft(null);
|
|
1308
|
+
else if (e.key === "Enter" && e.target.tagName !== "BUTTON") e.preventDefault(), submitDraft();
|
|
1309
|
+
},
|
|
1310
|
+
style: { position: "fixed", top: draft.top, left: draft.left, width: 280, zIndex: 60 },
|
|
1311
|
+
className: "flex flex-col gap-2 rounded-md border border-stroke-subsection bg-surface-default-l1 p-3 shadow-e300",
|
|
1312
|
+
children: [
|
|
1313
|
+
/* @__PURE__ */ jsx4("p", { className: "text-interface-body-s-heavy text-text-default-regular", children: "Save query as" }),
|
|
1314
|
+
/* @__PURE__ */ jsx4("input", { autoFocus: true, "aria-label": "Name", value: draft.name, onFocus: (e) => e.target.select(), onChange: (e) => setDraft({ ...draft, name: e.target.value }), className: "rounded-md border border-stroke-subsection bg-surface-default-underground px-2 py-1.5 text-interface-body-s-normal font-medium text-text-default-regular outline-none focus:border-stroke-active" }),
|
|
1315
|
+
/* @__PURE__ */ jsxs4("label", { className: "flex cursor-pointer items-center gap-1.5 text-interface-labels-xs-normal font-medium text-text-default-subdued", children: [
|
|
1316
|
+
/* @__PURE__ */ jsx4("input", { type: "checkbox", checked: draft.pinned, onChange: (e) => setDraft({ ...draft, pinned: e.target.checked }), style: { width: 14, height: 14, margin: 0, accentColor: "var(--color-stroke-active)" } }),
|
|
1317
|
+
"Pin to the top of Queries"
|
|
1318
|
+
] }),
|
|
1319
|
+
/* @__PURE__ */ jsx4(QueryChip, { query: clean, schema }),
|
|
1320
|
+
taken && /* @__PURE__ */ jsxs4("p", { className: "text-interface-labels-xs-normal text-text-color-red", children: [
|
|
1321
|
+
"A saved query is already called ",
|
|
1322
|
+
draft.name.trim()
|
|
1323
|
+
] }),
|
|
1324
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex justify-end gap-2", children: [
|
|
1325
|
+
/* @__PURE__ */ jsx4("button", { onClick: () => setDraft(null), className: "h-6 rounded px-2 text-interface-labels-xs-normal font-semibold text-text-default-regular hover:bg-surface-hover-l1-hover", children: "Cancel" }),
|
|
1326
|
+
/* @__PURE__ */ jsx4("button", { disabled: !draft.name.trim() || taken, onClick: submitDraft, className: "h-6 rounded-md border border-stroke-active bg-surface-default-action px-2.5 text-interface-labels-xs-normal font-semibold text-text-default-static hover:bg-surface-default-action-hover disabled:cursor-not-allowed disabled:opacity-50", children: match ? "Update" : "Save" })
|
|
1327
|
+
] })
|
|
1328
|
+
]
|
|
1329
|
+
}
|
|
1330
|
+
)
|
|
1331
|
+
] });
|
|
1332
|
+
});
|
|
1333
|
+
var PostgresQueryBox_default = PostgresQueryBox;
|
|
1334
|
+
export {
|
|
1335
|
+
LATENCY,
|
|
1336
|
+
LAT_FIELD,
|
|
1337
|
+
METHODS,
|
|
1338
|
+
OP_INFO,
|
|
1339
|
+
PostgresQueryBox_default as PostgresQueryBox,
|
|
1340
|
+
STATUS_CODES,
|
|
1341
|
+
TYPE_LABEL,
|
|
1342
|
+
buildSchema,
|
|
1343
|
+
context,
|
|
1344
|
+
evaluate,
|
|
1345
|
+
format,
|
|
1346
|
+
fromTree,
|
|
1347
|
+
ipToBig,
|
|
1348
|
+
opsFor,
|
|
1349
|
+
parse,
|
|
1350
|
+
parseRange,
|
|
1351
|
+
schemaFromFields,
|
|
1352
|
+
toSql,
|
|
1353
|
+
toTree,
|
|
1354
|
+
tokenize,
|
|
1355
|
+
validate
|
|
1356
|
+
};
|
|
1357
|
+
//# sourceMappingURL=index.js.map
|