@thebuoyant-tsdev/mui-ts-library 3.6.0 → 3.7.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/README.de.md +56 -12
- package/README.md +56 -12
- package/dist/components/json-editor/JsonEditor.d.ts +1 -1
- package/dist/components/json-editor/JsonEditor.js +38 -34
- package/dist/components/json-editor/JsonEditor.types.d.ts +29 -0
- package/dist/components/json-editor/JsonEditorContent.d.ts +6 -2
- package/dist/components/json-editor/JsonEditorContent.js +206 -104
- package/dist/components/json-editor/util/jsonPathFinder.d.ts +9 -0
- package/dist/components/json-editor/util/jsonPathFinder.js +45 -0
- package/dist/components/json-editor/util/jsonSchemaValidator.d.ts +22 -0
- package/dist/components/json-editor/util/jsonSchemaValidator.js +116 -0
- package/dist/components/sql-editor/SqlEditor.types.d.ts +7 -4
- package/dist/components/sql-editor/SqlEditorFooter.d.ts +1 -1
- package/dist/components/sql-editor/SqlEditorHistoryMenu.d.ts +1 -1
- package/dist/components/sql-editor/SqlEditorToolbar.d.ts +1 -1
- package/dist/components/tag-selection/TagSelection.types.d.ts +5 -3
- package/dist/components/tag-selection/TagSelectionAutocomplete.d.ts +1 -1
- package/dist/components/tag-selection/TagSelectionSelectedTags.d.ts +1 -1
- package/dist/index.cjs +2 -2
- package/package.json +2 -1
|
@@ -1,67 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { computeJsonPath as e } from "./util/jsonPathFinder.js";
|
|
2
|
+
import { findRangeForPath as t, validateAgainstSchema as n } from "./util/jsonSchemaValidator.js";
|
|
3
|
+
import { useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { Box as o, Fade as s, Paper as c, Typography as ee, useTheme as te } from "@mui/material";
|
|
5
|
+
import { EditorView as l, highlightActiveLine as ne, highlightActiveLineGutter as re, keymap as ie, lineNumbers as ae, placeholder as oe } from "@codemirror/view";
|
|
4
6
|
import { Compartment as u, EditorState as d } from "@codemirror/state";
|
|
5
|
-
import { json as
|
|
6
|
-
import { defaultKeymap as
|
|
7
|
-
import { HighlightStyle as
|
|
8
|
-
import { lintGutter as
|
|
9
|
-
import { tags as
|
|
10
|
-
import { showMinimap as
|
|
11
|
-
import { jsx as
|
|
7
|
+
import { json as se, jsonParseLinter as f } from "@codemirror/lang-json";
|
|
8
|
+
import { defaultKeymap as ce, history as le, historyKeymap as ue } from "@codemirror/commands";
|
|
9
|
+
import { HighlightStyle as de, foldGutter as fe, foldKeymap as pe, syntaxHighlighting as me } from "@codemirror/language";
|
|
10
|
+
import { forceLinting as he, lintGutter as ge, linter as p } from "@codemirror/lint";
|
|
11
|
+
import { tags as m } from "@lezer/highlight";
|
|
12
|
+
import { showMinimap as _e } from "@replit/codemirror-minimap";
|
|
13
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
12
14
|
//#region src/components/json-editor/JsonEditorContent.tsx
|
|
13
|
-
function
|
|
14
|
-
let
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
}, [
|
|
18
|
-
|
|
19
|
-
}, [
|
|
20
|
-
|
|
21
|
-
}, [
|
|
22
|
-
|
|
23
|
-
}, [
|
|
24
|
-
|
|
25
|
-
}, [
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
function _({ value: _, onChange: v, placeholder: y, disabled: b = !1, readonly: x = !1, schema: S, showLineNumbers: ve = !0, showMinimap: C = !1, showFolding: w = !0, enablePathFinder: T = !0, highlightColors: E, onViewReady: D, onCursorChange: O, onBlur: k, onFocus: A, onPathCopy: j }) {
|
|
16
|
+
let M = i(null), N = i(null), P = i(null), F = i(v), I = i(O), L = i(k), R = i(A), z = i(D), B = i(j), V = i(T), H = i(S), [U, W] = a(null), G = i(new u()), K = i(new u()), q = te(), J = q.palette.mode === "dark", Y = E?.propertyName ?? q.palette.primary.main, X = E?.string ?? q.palette.success.main, Z = E?.number ?? q.palette.warning.main, Q = E?.boolean ?? q.palette.info.main, $ = E?.null ?? q.palette.text.secondary;
|
|
17
|
+
return r(() => {
|
|
18
|
+
F.current = v;
|
|
19
|
+
}, [v]), r(() => {
|
|
20
|
+
I.current = O;
|
|
21
|
+
}, [O]), r(() => {
|
|
22
|
+
L.current = k;
|
|
23
|
+
}, [k]), r(() => {
|
|
24
|
+
R.current = A;
|
|
25
|
+
}, [A]), r(() => {
|
|
26
|
+
z.current = D;
|
|
27
|
+
}, [D]), r(() => {
|
|
28
|
+
B.current = j;
|
|
29
|
+
}, [j]), r(() => {
|
|
30
|
+
V.current = T;
|
|
31
|
+
}, [T]), r(() => {
|
|
32
|
+
H.current = S, P.current && he(P.current);
|
|
33
|
+
}, [S]), r(() => {
|
|
34
|
+
if (!N.current) return;
|
|
35
|
+
let r = P.current?.state.doc.toString() ?? _ ?? "", i = de.define([
|
|
28
36
|
{
|
|
29
|
-
tag:
|
|
30
|
-
color:
|
|
37
|
+
tag: m.propertyName,
|
|
38
|
+
color: Y,
|
|
31
39
|
fontWeight: "bold"
|
|
32
40
|
},
|
|
33
41
|
{
|
|
34
|
-
tag:
|
|
35
|
-
color:
|
|
42
|
+
tag: m.string,
|
|
43
|
+
color: X
|
|
36
44
|
},
|
|
37
45
|
{
|
|
38
|
-
tag:
|
|
39
|
-
color:
|
|
46
|
+
tag: m.number,
|
|
47
|
+
color: Z
|
|
40
48
|
},
|
|
41
49
|
{
|
|
42
|
-
tag:
|
|
43
|
-
color:
|
|
50
|
+
tag: m.bool,
|
|
51
|
+
color: Q,
|
|
44
52
|
fontWeight: "bold"
|
|
45
53
|
},
|
|
46
54
|
{
|
|
47
|
-
tag:
|
|
48
|
-
color:
|
|
55
|
+
tag: m.null,
|
|
56
|
+
color: $,
|
|
49
57
|
fontStyle: "italic"
|
|
50
58
|
},
|
|
51
59
|
{
|
|
52
|
-
tag:
|
|
53
|
-
color:
|
|
60
|
+
tag: m.bracket,
|
|
61
|
+
color: q.palette.text.secondary
|
|
54
62
|
},
|
|
55
63
|
{
|
|
56
|
-
tag:
|
|
57
|
-
color:
|
|
64
|
+
tag: m.punctuation,
|
|
65
|
+
color: q.palette.text.disabled
|
|
58
66
|
},
|
|
59
67
|
{
|
|
60
|
-
tag:
|
|
61
|
-
color:
|
|
68
|
+
tag: m.invalid,
|
|
69
|
+
color: q.palette.error.main,
|
|
62
70
|
textDecoration: "underline wavy"
|
|
63
71
|
}
|
|
64
|
-
]),
|
|
72
|
+
]), a = l.theme({
|
|
65
73
|
"&": {
|
|
66
74
|
height: "100%",
|
|
67
75
|
fontFamily: "'Fira Code', 'JetBrains Mono', 'Consolas', monospace",
|
|
@@ -70,116 +78,210 @@ function w({ value: w, onChange: T, placeholder: E, disabled: D = !1, readonly:
|
|
|
70
78
|
".cm-scroller": { overflow: "auto" },
|
|
71
79
|
".cm-content": {
|
|
72
80
|
padding: "8px 4px",
|
|
73
|
-
caretColor:
|
|
81
|
+
caretColor: q.palette.text.primary
|
|
74
82
|
},
|
|
75
83
|
".cm-gutters": {
|
|
76
|
-
backgroundColor:
|
|
77
|
-
color:
|
|
84
|
+
backgroundColor: J ? q.palette.grey[900] : q.palette.grey[50],
|
|
85
|
+
color: q.palette.text.disabled,
|
|
78
86
|
border: "none",
|
|
79
|
-
borderRight: `1px solid ${
|
|
87
|
+
borderRight: `1px solid ${q.palette.divider}`
|
|
80
88
|
},
|
|
81
89
|
".cm-lineNumbers .cm-gutterElement": {
|
|
82
90
|
paddingLeft: "4px",
|
|
83
91
|
paddingRight: "8px"
|
|
84
92
|
},
|
|
85
|
-
".cm-activeLineGutter": { backgroundColor:
|
|
86
|
-
".cm-activeLine": { backgroundColor:
|
|
87
|
-
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor:
|
|
88
|
-
".cm-cursor, .cm-dropCursor": { borderLeftColor:
|
|
93
|
+
".cm-activeLineGutter": { backgroundColor: q.palette.action.selected },
|
|
94
|
+
".cm-activeLine": { backgroundColor: q.palette.action.hover },
|
|
95
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor: q.palette.primary.main + "40" },
|
|
96
|
+
".cm-cursor, .cm-dropCursor": { borderLeftColor: q.palette.text.primary },
|
|
89
97
|
"&.cm-focused": { outline: "none" },
|
|
90
98
|
".cm-placeholder": {
|
|
91
|
-
color:
|
|
99
|
+
color: q.palette.text.disabled,
|
|
92
100
|
fontStyle: "italic"
|
|
93
101
|
},
|
|
94
102
|
".cm-gutter-lint": { width: "16px" },
|
|
95
|
-
".cm-lint-marker-error": { color:
|
|
96
|
-
".cm-lint-marker-warning": { color:
|
|
103
|
+
".cm-lint-marker-error": { color: q.palette.error.main },
|
|
104
|
+
".cm-lint-marker-warning": { color: q.palette.warning.main },
|
|
105
|
+
".cm-foldGutter .cm-gutterElement": {
|
|
106
|
+
cursor: "pointer",
|
|
107
|
+
color: q.palette.text.disabled
|
|
108
|
+
},
|
|
109
|
+
".cm-foldPlaceholder": {
|
|
110
|
+
backgroundColor: q.palette.action.selected,
|
|
111
|
+
border: `1px solid ${q.palette.divider}`,
|
|
112
|
+
borderRadius: "3px",
|
|
113
|
+
color: q.palette.text.secondary,
|
|
114
|
+
padding: "0 4px"
|
|
115
|
+
},
|
|
97
116
|
".cm-tooltip.cm-tooltip-lint": {
|
|
98
|
-
backgroundColor:
|
|
99
|
-
border: `1px solid ${
|
|
117
|
+
backgroundColor: q.palette.background.paper,
|
|
118
|
+
border: `1px solid ${q.palette.divider}`,
|
|
100
119
|
borderRadius: "4px"
|
|
101
120
|
},
|
|
102
|
-
".cm-diagnostic-error": { borderLeft: `3px solid ${
|
|
103
|
-
".cm-diagnostic-warning": { borderLeft: `3px solid ${
|
|
104
|
-
}, { dark:
|
|
121
|
+
".cm-diagnostic-error": { borderLeft: `3px solid ${q.palette.error.main}` },
|
|
122
|
+
".cm-diagnostic-warning": { borderLeft: `3px solid ${q.palette.warning.main}` }
|
|
123
|
+
}, { dark: J }), o = C ? [_e.of({
|
|
105
124
|
create: () => {
|
|
106
125
|
let e = document.createElement("div");
|
|
107
|
-
return e.style.width = "80px", e.style.overflow = "hidden", e.style.borderLeft = `1px solid ${
|
|
126
|
+
return e.style.width = "80px", e.style.overflow = "hidden", e.style.borderLeft = `1px solid ${q.palette.divider}`, e.style.backgroundColor = J ? q.palette.grey[900] : q.palette.grey[50], { dom: e };
|
|
108
127
|
},
|
|
109
128
|
displayText: "blocks",
|
|
110
129
|
showOverlay: "always"
|
|
111
|
-
})] : [],
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
})] : [], s = [
|
|
131
|
+
a,
|
|
132
|
+
me(i),
|
|
133
|
+
se(),
|
|
134
|
+
ge(),
|
|
135
|
+
p(f()),
|
|
136
|
+
p((e) => {
|
|
137
|
+
let r = H.current;
|
|
138
|
+
if (!r) return [];
|
|
139
|
+
let i;
|
|
140
|
+
try {
|
|
141
|
+
i = JSON.parse(e.state.doc.toString());
|
|
142
|
+
} catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
let a = [];
|
|
146
|
+
for (let o of n(i, r)) {
|
|
147
|
+
let n = t(e.state, o.path);
|
|
148
|
+
n && a.push({
|
|
149
|
+
from: n.from,
|
|
150
|
+
to: n.to,
|
|
151
|
+
severity: "error",
|
|
152
|
+
message: o.message
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return a;
|
|
156
|
+
}),
|
|
157
|
+
le(),
|
|
158
|
+
ie.of([
|
|
159
|
+
...ce,
|
|
160
|
+
...ue,
|
|
161
|
+
...pe
|
|
162
|
+
]),
|
|
163
|
+
G.current.of(l.editable.of(!b && !x)),
|
|
164
|
+
K.current.of(d.readOnly.of(x)),
|
|
165
|
+
ne(),
|
|
166
|
+
...ve ? [ae(), re()] : [],
|
|
167
|
+
...w ? [fe()] : [],
|
|
168
|
+
...y ? [oe(y)] : [],
|
|
169
|
+
...o,
|
|
170
|
+
l.updateListener.of((e) => {
|
|
171
|
+
e.docChanged && F.current?.(e.state.doc.toString());
|
|
127
172
|
let t = e.state.selection.main.head, n = e.state.doc.lineAt(t);
|
|
128
|
-
|
|
173
|
+
I.current(n.number, t - n.from + 1);
|
|
129
174
|
}),
|
|
130
|
-
|
|
175
|
+
l.domEventHandlers({
|
|
131
176
|
blur: () => {
|
|
132
|
-
|
|
177
|
+
L.current?.();
|
|
133
178
|
},
|
|
134
179
|
focus: () => {
|
|
135
|
-
|
|
180
|
+
R.current?.();
|
|
181
|
+
},
|
|
182
|
+
click: (t, n) => {
|
|
183
|
+
if (!V.current || !(t.ctrlKey || t.metaKey)) return !1;
|
|
184
|
+
let r;
|
|
185
|
+
try {
|
|
186
|
+
r = n.posAtCoords({
|
|
187
|
+
x: t.clientX,
|
|
188
|
+
y: t.clientY
|
|
189
|
+
});
|
|
190
|
+
} catch {
|
|
191
|
+
return !1;
|
|
192
|
+
}
|
|
193
|
+
if (r === null) return !1;
|
|
194
|
+
let i = e(n.state, r);
|
|
195
|
+
return i ? (navigator.clipboard.writeText(i).then(() => {
|
|
196
|
+
let e = M.current?.getBoundingClientRect();
|
|
197
|
+
W({
|
|
198
|
+
x: t.clientX - (e?.left ?? 0),
|
|
199
|
+
y: t.clientY - (e?.top ?? 0),
|
|
200
|
+
path: i
|
|
201
|
+
}), B.current?.(i);
|
|
202
|
+
}), !0) : !1;
|
|
136
203
|
}
|
|
137
204
|
})
|
|
138
|
-
],
|
|
205
|
+
], c = new l({
|
|
139
206
|
state: d.create({
|
|
140
|
-
doc:
|
|
141
|
-
extensions:
|
|
207
|
+
doc: r,
|
|
208
|
+
extensions: s
|
|
142
209
|
}),
|
|
143
|
-
parent:
|
|
210
|
+
parent: N.current
|
|
144
211
|
});
|
|
145
|
-
return
|
|
146
|
-
|
|
212
|
+
return P.current = c, z.current(c), () => {
|
|
213
|
+
z.current(null), c.destroy(), P.current = null;
|
|
147
214
|
};
|
|
148
215
|
}, [
|
|
149
|
-
K,
|
|
150
|
-
q,
|
|
151
216
|
J,
|
|
152
217
|
Y,
|
|
153
218
|
X,
|
|
154
219
|
Z,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
220
|
+
Q,
|
|
221
|
+
$,
|
|
222
|
+
C
|
|
223
|
+
]), r(() => {
|
|
224
|
+
let e = P.current;
|
|
158
225
|
if (!e) return;
|
|
159
226
|
let t = e.state.doc.toString();
|
|
160
|
-
t !== (
|
|
227
|
+
t !== (_ ?? "") && e.dispatch({ changes: {
|
|
161
228
|
from: 0,
|
|
162
229
|
to: t.length,
|
|
163
|
-
insert:
|
|
230
|
+
insert: _ ?? ""
|
|
164
231
|
} });
|
|
165
|
-
}, [
|
|
166
|
-
|
|
167
|
-
}, [
|
|
168
|
-
|
|
232
|
+
}, [_]), r(() => {
|
|
233
|
+
P.current?.dispatch({ effects: [G.current.reconfigure(l.editable.of(!b && !x)), K.current.reconfigure(d.readOnly.of(x))] });
|
|
234
|
+
}, [b, x]), r(() => {
|
|
235
|
+
if (!U) return;
|
|
236
|
+
let e = setTimeout(() => W(null), 1500);
|
|
237
|
+
return () => clearTimeout(e);
|
|
238
|
+
}, [U]), /* @__PURE__ */ g(o, {
|
|
239
|
+
ref: M,
|
|
169
240
|
sx: {
|
|
241
|
+
position: "relative",
|
|
170
242
|
flex: 1,
|
|
171
243
|
overflow: "hidden",
|
|
172
|
-
display: "flex"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
244
|
+
display: "flex"
|
|
245
|
+
},
|
|
246
|
+
children: [/* @__PURE__ */ h(o, {
|
|
247
|
+
ref: N,
|
|
248
|
+
sx: {
|
|
177
249
|
flex: 1,
|
|
250
|
+
overflow: "hidden",
|
|
178
251
|
display: "flex",
|
|
179
|
-
flexDirection: "column"
|
|
252
|
+
flexDirection: "column",
|
|
253
|
+
opacity: b ? .5 : 1,
|
|
254
|
+
backgroundColor: q.palette.background.paper,
|
|
255
|
+
"& .cm-editor": {
|
|
256
|
+
flex: 1,
|
|
257
|
+
display: "flex",
|
|
258
|
+
flexDirection: "column"
|
|
259
|
+
}
|
|
180
260
|
}
|
|
181
|
-
}
|
|
261
|
+
}), U && /* @__PURE__ */ h(s, {
|
|
262
|
+
in: !0,
|
|
263
|
+
children: /* @__PURE__ */ h(c, {
|
|
264
|
+
elevation: 3,
|
|
265
|
+
sx: {
|
|
266
|
+
position: "absolute",
|
|
267
|
+
left: U.x,
|
|
268
|
+
top: U.y,
|
|
269
|
+
transform: "translate(-50%, -130%)",
|
|
270
|
+
px: 1,
|
|
271
|
+
py: .5,
|
|
272
|
+
pointerEvents: "none",
|
|
273
|
+
zIndex: 10,
|
|
274
|
+
bgcolor: "grey.900",
|
|
275
|
+
color: "common.white"
|
|
276
|
+
},
|
|
277
|
+
children: /* @__PURE__ */ g(ee, {
|
|
278
|
+
variant: "caption",
|
|
279
|
+
sx: { fontFamily: "monospace" },
|
|
280
|
+
children: ["Copied: ", U.path]
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})]
|
|
182
284
|
});
|
|
183
285
|
}
|
|
184
286
|
//#endregion
|
|
185
|
-
export {
|
|
287
|
+
export { _ as JsonEditorContent };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EditorState } from "@codemirror/state";
|
|
2
|
+
/**
|
|
3
|
+
* Walks up the Lezer JSON syntax tree from `pos` to compute the JSON path
|
|
4
|
+
* (e.g. "$.users[0].name") of the value or property key under the cursor.
|
|
5
|
+
*
|
|
6
|
+
* Returns "$" for the document root, or null if `pos` doesn't resolve to any
|
|
7
|
+
* node (e.g. an empty document).
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeJsonPath(state: EditorState, pos: number): string | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { syntaxTree as e } from "@codemirror/language";
|
|
2
|
+
//#region src/components/json-editor/util/jsonPathFinder.ts
|
|
3
|
+
var t = /^[A-Za-z_$][A-Za-z0-9_$]*$/, n = new Set([
|
|
4
|
+
"Object",
|
|
5
|
+
"Array",
|
|
6
|
+
"String",
|
|
7
|
+
"Number",
|
|
8
|
+
"True",
|
|
9
|
+
"False",
|
|
10
|
+
"Null"
|
|
11
|
+
]);
|
|
12
|
+
function r(e) {
|
|
13
|
+
return t.test(e) ? `.${e}` : `[${JSON.stringify(e)}]`;
|
|
14
|
+
}
|
|
15
|
+
function i(t, i) {
|
|
16
|
+
if (t.doc.length === 0) return null;
|
|
17
|
+
let a = e(t).resolveInner(i, 1);
|
|
18
|
+
if (!a) return null;
|
|
19
|
+
let o = [];
|
|
20
|
+
for (; a;) {
|
|
21
|
+
let e = a.parent;
|
|
22
|
+
if (!e) break;
|
|
23
|
+
if (e.name === "Property") {
|
|
24
|
+
let n = e.getChild("PropertyName");
|
|
25
|
+
if (n) {
|
|
26
|
+
let e = t.sliceDoc(n.from, n.to);
|
|
27
|
+
try {
|
|
28
|
+
o.unshift(r(JSON.parse(e)));
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
a = e.parent ?? e;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (e.name === "Array") {
|
|
35
|
+
let t = 0, r = e.firstChild;
|
|
36
|
+
for (; r && r.from < a.from;) n.has(r.name) && t++, r = r.nextSibling;
|
|
37
|
+
o.unshift(`[${t}]`), a = e;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
a = e;
|
|
41
|
+
}
|
|
42
|
+
return o.length > 0 ? `$${o.join("")}` : "$";
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { i as computeJsonPath };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EditorState } from "@codemirror/state";
|
|
2
|
+
import type { JsonEditorSchema } from "../JsonEditor.types";
|
|
3
|
+
export type JsonSchemaValidationError = {
|
|
4
|
+
/** JSON path of the offending value, e.g. "$.users[0].age" */
|
|
5
|
+
path: string;
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Validates a parsed JSON value against a focused JSON Schema subset (type,
|
|
10
|
+
* required, enum, nested properties/items). Returns one error per violation,
|
|
11
|
+
* each tagged with the JSON path of the offending value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateAgainstSchema(value: unknown, schema: JsonEditorSchema, path?: string): JsonSchemaValidationError[];
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a JSON path (as produced by `validateAgainstSchema`) to its
|
|
16
|
+
* source range in the document, by walking the syntax tree down from the
|
|
17
|
+
* root. Returns null if the path can't be resolved (e.g. document changed).
|
|
18
|
+
*/
|
|
19
|
+
export declare function findRangeForPath(state: EditorState, path: string): {
|
|
20
|
+
from: number;
|
|
21
|
+
to: number;
|
|
22
|
+
} | null;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { syntaxTree as e } from "@codemirror/language";
|
|
2
|
+
//#region src/components/json-editor/util/jsonSchemaValidator.ts
|
|
3
|
+
var t = new Set([
|
|
4
|
+
"Object",
|
|
5
|
+
"Array",
|
|
6
|
+
"String",
|
|
7
|
+
"Number",
|
|
8
|
+
"True",
|
|
9
|
+
"False",
|
|
10
|
+
"Null"
|
|
11
|
+
]), n = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
12
|
+
function r(e) {
|
|
13
|
+
return n.test(e) ? `.${e}` : `[${JSON.stringify(e)}]`;
|
|
14
|
+
}
|
|
15
|
+
function i(e) {
|
|
16
|
+
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e == "number" ? Number.isInteger(e) ? "integer" : "number" : typeof e == "string" ? "string" : typeof e == "boolean" ? "boolean" : "object";
|
|
17
|
+
}
|
|
18
|
+
function a(e, t) {
|
|
19
|
+
let n = i(e);
|
|
20
|
+
return n === t || t === "number" && n === "integer";
|
|
21
|
+
}
|
|
22
|
+
function o(e, t) {
|
|
23
|
+
if (e === t) return !0;
|
|
24
|
+
if (Array.isArray(e) && Array.isArray(t)) return e.length === t.length && e.every((e, n) => o(e, t[n]));
|
|
25
|
+
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
26
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
27
|
+
return n.length === r.length ? n.every((n) => o(e[n], t[n])) : !1;
|
|
28
|
+
}
|
|
29
|
+
return !1;
|
|
30
|
+
}
|
|
31
|
+
function s(e, t, n = "$") {
|
|
32
|
+
let c = [];
|
|
33
|
+
if (t.type) {
|
|
34
|
+
let r = Array.isArray(t.type) ? t.type : [t.type];
|
|
35
|
+
if (!r.some((t) => a(e, t))) return c.push({
|
|
36
|
+
path: n,
|
|
37
|
+
message: `Expected type ${r.join(" | ")}, got ${i(e)}.`
|
|
38
|
+
}), c;
|
|
39
|
+
}
|
|
40
|
+
if (t.enum && !t.enum.some((t) => o(t, e)) && c.push({
|
|
41
|
+
path: n,
|
|
42
|
+
message: `Value must be one of: ${t.enum.map((e) => JSON.stringify(e)).join(", ")}.`
|
|
43
|
+
}), i(e) === "object" && e !== null) {
|
|
44
|
+
let i = e;
|
|
45
|
+
for (let e of t.required ?? []) e in i || c.push({
|
|
46
|
+
path: n,
|
|
47
|
+
message: `Missing required property "${e}".`
|
|
48
|
+
});
|
|
49
|
+
if (t.properties) for (let [e, a] of Object.entries(t.properties)) e in i && c.push(...s(i[e], a, `${n}${r(e)}`));
|
|
50
|
+
}
|
|
51
|
+
return t.items && Array.isArray(e) && e.forEach((e, r) => {
|
|
52
|
+
c.push(...s(e, t.items, `${n}[${r}]`));
|
|
53
|
+
}), c;
|
|
54
|
+
}
|
|
55
|
+
var c = /\.([A-Za-z_$][A-Za-z0-9_$]*)|\[(\d+)\]|\["((?:[^"\\]|\\.)*)"\]/g;
|
|
56
|
+
function l(e) {
|
|
57
|
+
let t = [];
|
|
58
|
+
for (let n of e.matchAll(c)) n[1] === void 0 ? n[2] === void 0 ? n[3] !== void 0 && t.push({
|
|
59
|
+
type: "key",
|
|
60
|
+
value: JSON.parse(`"${n[3]}"`)
|
|
61
|
+
}) : t.push({
|
|
62
|
+
type: "index",
|
|
63
|
+
value: Number(n[2])
|
|
64
|
+
}) : t.push({
|
|
65
|
+
type: "key",
|
|
66
|
+
value: n[1]
|
|
67
|
+
});
|
|
68
|
+
return t;
|
|
69
|
+
}
|
|
70
|
+
function u(e) {
|
|
71
|
+
let n = e.topNode;
|
|
72
|
+
for (; n && !t.has(n.name);) {
|
|
73
|
+
let e = n.firstChild;
|
|
74
|
+
if (!e) return null;
|
|
75
|
+
n = e;
|
|
76
|
+
}
|
|
77
|
+
return n;
|
|
78
|
+
}
|
|
79
|
+
function d(n, r) {
|
|
80
|
+
let i = u(e(n));
|
|
81
|
+
if (!i) return null;
|
|
82
|
+
for (let e of l(r)) if (e.type === "key") {
|
|
83
|
+
if (i.name !== "Object") return null;
|
|
84
|
+
let t = null;
|
|
85
|
+
for (let r = i.firstChild; r; r = r.nextSibling) {
|
|
86
|
+
if (r.name !== "Property") continue;
|
|
87
|
+
let i = r.getChild("PropertyName");
|
|
88
|
+
if (i) try {
|
|
89
|
+
if (JSON.parse(n.sliceDoc(i.from, i.to)) === e.value) {
|
|
90
|
+
t = r.lastChild;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
} catch {}
|
|
94
|
+
}
|
|
95
|
+
if (!t) return null;
|
|
96
|
+
i = t;
|
|
97
|
+
} else {
|
|
98
|
+
if (i.name !== "Array") return null;
|
|
99
|
+
let n = 0, r = null;
|
|
100
|
+
for (let a = i.firstChild; a; a = a.nextSibling) if (t.has(a.name)) {
|
|
101
|
+
if (n === e.value) {
|
|
102
|
+
r = a;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
n++;
|
|
106
|
+
}
|
|
107
|
+
if (!r) return null;
|
|
108
|
+
i = r;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
from: i.from,
|
|
112
|
+
to: i.to
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { d as findRangeForPath, s as validateAgainstSchema };
|
|
@@ -24,11 +24,14 @@ export type SqlEditorTranslation = {
|
|
|
24
24
|
redo: string;
|
|
25
25
|
lineColumn: string;
|
|
26
26
|
errorCount: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/** @since 3.5.0 — optional for backward compatibility with full-literal objects typed before this field existed. */
|
|
28
|
+
history?: string;
|
|
29
|
+
/** @since 3.5.0 — optional for backward compatibility with full-literal objects typed before this field existed. */
|
|
30
|
+
historyEmpty?: string;
|
|
31
|
+
/** @since 3.5.0 — optional for backward compatibility with full-literal objects typed before this field existed. */
|
|
32
|
+
clearHistory?: string;
|
|
30
33
|
};
|
|
31
|
-
export declare const DEFAULT_SQL_EDITOR_TRANSLATION: SqlEditorTranslation
|
|
34
|
+
export declare const DEFAULT_SQL_EDITOR_TRANSLATION: Required<SqlEditorTranslation>;
|
|
32
35
|
export type SqlEditorDialect = "standard" | "mysql" | "postgresql" | "sqlite" | "mssql";
|
|
33
36
|
export type SqlColumn = {
|
|
34
37
|
name: string;
|
|
@@ -7,7 +7,7 @@ type SqlEditorFooterProps = {
|
|
|
7
7
|
diagnosticsCount: number;
|
|
8
8
|
cursorLine: number;
|
|
9
9
|
cursorCol: number;
|
|
10
|
-
translation: SqlEditorTranslation
|
|
10
|
+
translation: Required<SqlEditorTranslation>;
|
|
11
11
|
};
|
|
12
12
|
export declare function SqlEditorFooter({ helperText, error, showLineColumn, showErrorCount, diagnosticsCount, cursorLine, cursorCol, translation: t, }: SqlEditorFooterProps): import("react/jsx-runtime").JSX.Element;
|
|
13
13
|
export {};
|
|
@@ -4,7 +4,7 @@ type SqlEditorHistoryMenuProps = {
|
|
|
4
4
|
history: SqlQueryHistoryEntry[];
|
|
5
5
|
onSelect: (sql: string) => void;
|
|
6
6
|
onClear: () => void;
|
|
7
|
-
translation: SqlEditorTranslation
|
|
7
|
+
translation: Required<SqlEditorTranslation>;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
export declare function SqlEditorHistoryMenu({ history, onSelect, onClear, translation: t, disabled, }: SqlEditorHistoryMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import type { SqlQueryHistoryEntry } from "./util/sqlQueryHistory.util";
|
|
|
4
4
|
type SqlEditorToolbarProps = {
|
|
5
5
|
editorView: EditorView | null;
|
|
6
6
|
toolbarConfig: Required<SqlEditorToolbarConfig>;
|
|
7
|
-
translation: SqlEditorTranslation
|
|
7
|
+
translation: Required<SqlEditorTranslation>;
|
|
8
8
|
dialect: SqlEditorDialect;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
onExecute?: (sql: string) => void;
|
|
@@ -20,10 +20,12 @@ export type TagSelectionTranslation = {
|
|
|
20
20
|
backgroundColorLabel: string;
|
|
21
21
|
textColorLabel: string;
|
|
22
22
|
autoTextColorLabel: string;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** @since 3.4.0 — optional for backward compatibility with full-literal objects typed before this field existed. */
|
|
24
|
+
confirmCreateLabel?: string;
|
|
25
|
+
/** @since 3.4.0 — optional for backward compatibility with full-literal objects typed before this field existed. */
|
|
26
|
+
cancelCreateLabel?: string;
|
|
25
27
|
};
|
|
26
|
-
export declare const DEFAULT_TAG_SELECTION_TRANSLATION: TagSelectionTranslation
|
|
28
|
+
export declare const DEFAULT_TAG_SELECTION_TRANSLATION: Required<TagSelectionTranslation>;
|
|
27
29
|
export type TagSelectionProps = {
|
|
28
30
|
allowCreate?: boolean;
|
|
29
31
|
chipSize?: "small" | "medium";
|
|
@@ -4,7 +4,7 @@ type TagSelectionAutocompleteProps = {
|
|
|
4
4
|
chipSize: "medium" | "small";
|
|
5
5
|
availableTags: TagSelectionItem[];
|
|
6
6
|
searchValue: string;
|
|
7
|
-
translation: TagSelectionTranslation
|
|
7
|
+
translation: Required<TagSelectionTranslation>;
|
|
8
8
|
onSearchChange: (value: string) => void;
|
|
9
9
|
onTagSelect: (tag: TagSelectionItem) => void;
|
|
10
10
|
onTagCreate?: (tag: TagSelectionItem) => void;
|