@niscorp/loom 0.5.0 → 0.6.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 +104 -0
- package/DESIGN.md +48 -10
- package/README.md +63 -11
- package/dist/{chunk-HHPSU7IA.js → chunk-3UI7CG24.js} +3 -4
- package/dist/chunk-3UI7CG24.js.map +1 -0
- package/dist/{chunk-LVDY6FUH.js → chunk-BYOKCNIJ.js} +3 -3
- package/dist/{chunk-LVDY6FUH.js.map → chunk-BYOKCNIJ.js.map} +1 -1
- package/dist/chunk-GXA57JFR.js +409 -0
- package/dist/chunk-GXA57JFR.js.map +1 -0
- package/dist/chunk-J5SYOIR2.js +100 -0
- package/dist/chunk-J5SYOIR2.js.map +1 -0
- package/dist/{chunk-VMOYMYMV.js → chunk-LAQIW27Q.js} +3 -3
- package/dist/chunk-LAQIW27Q.js.map +1 -0
- package/dist/{chunk-IQMWPPHW.js → chunk-OVTQEAV3.js} +290 -23
- package/dist/chunk-OVTQEAV3.js.map +1 -0
- package/dist/index.cjs +74 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -4
- package/dist/loom-editor-DlNYrfT9.d.ts +15 -0
- package/dist/loom-editor-DtGAf8eH.d.cts +15 -0
- package/dist/plugins/nova/index.cjs +6 -3
- package/dist/plugins/nova/index.cjs.map +1 -1
- package/dist/plugins/nova/index.d.cts +1 -1
- package/dist/plugins/nova/index.d.ts +1 -1
- package/dist/plugins/nova/index.js +2 -3
- package/dist/plugins/nova/react/index.cjs +21 -7
- package/dist/plugins/nova/react/index.cjs.map +1 -1
- package/dist/plugins/nova/react/index.d.cts +2 -2
- package/dist/plugins/nova/react/index.d.ts +2 -2
- package/dist/plugins/nova/react/index.js +5 -5
- package/dist/plugins/nova/react/index.js.map +1 -1
- package/dist/plugins/prism/index.cjs +2 -0
- package/dist/plugins/prism/index.cjs.map +1 -1
- package/dist/plugins/prism/index.d.cts +1 -1
- package/dist/plugins/prism/index.d.ts +1 -1
- package/dist/plugins/prism/index.js +2 -2
- package/dist/plugins/prism/react/index.cjs +200 -189
- package/dist/plugins/prism/react/index.cjs.map +1 -1
- package/dist/plugins/prism/react/index.d.cts +3 -3
- package/dist/plugins/prism/react/index.d.ts +3 -3
- package/dist/plugins/prism/react/index.js +48 -108
- package/dist/plugins/prism/react/index.js.map +1 -1
- package/dist/plugins/vex/index.cjs +2 -0
- package/dist/plugins/vex/index.cjs.map +1 -1
- package/dist/plugins/vex/index.d.cts +1 -1
- package/dist/plugins/vex/index.d.ts +1 -1
- package/dist/plugins/vex/index.js +2 -2
- package/dist/plugins/vex/react/index.cjs +154 -96
- package/dist/plugins/vex/react/index.cjs.map +1 -1
- package/dist/plugins/vex/react/index.d.cts +3 -3
- package/dist/plugins/vex/react/index.d.ts +3 -3
- package/dist/plugins/vex/react/index.js +42 -29
- package/dist/plugins/vex/react/index.js.map +1 -1
- package/dist/react/index.cjs +153 -92
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +7 -3
- package/dist/react/index.d.ts +7 -3
- package/dist/react/index.js +3 -118
- package/dist/react/index.js.map +1 -1
- package/dist/{types-V5kJWZJn.d.ts → types-BWIIThEy.d.cts} +2 -0
- package/dist/{types-V5kJWZJn.d.cts → types-BWIIThEy.d.ts} +2 -0
- package/package.json +7 -7
- package/dist/chunk-27OMOR7I.js +0 -17
- package/dist/chunk-27OMOR7I.js.map +0 -1
- package/dist/chunk-67D727GH.js +0 -47
- package/dist/chunk-67D727GH.js.map +0 -1
- package/dist/chunk-BU5TULRP.js +0 -132
- package/dist/chunk-BU5TULRP.js.map +0 -1
- package/dist/chunk-DEZGKUTO.js +0 -170
- package/dist/chunk-DEZGKUTO.js.map +0 -1
- package/dist/chunk-HHPSU7IA.js.map +0 -1
- package/dist/chunk-IQMWPPHW.js.map +0 -1
- package/dist/chunk-OFKHIREC.js +0 -212
- package/dist/chunk-OFKHIREC.js.map +0 -1
- package/dist/chunk-VMOYMYMV.js.map +0 -1
- package/dist/loom-editor-BthwIGIZ.d.cts +0 -24
- package/dist/loom-editor-CHtjjiBp.d.ts +0 -24
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var vex$1 = require('@niscorp/vex');
|
|
4
|
+
require('zod');
|
|
5
|
+
var nova = require('@niscorp/nova');
|
|
4
6
|
var react = require('react');
|
|
5
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
var react$1 = require('@niscorp/nova/adapters/react');
|
|
7
|
-
var
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
9
|
|
|
9
10
|
// src/plugins/vex/index.ts
|
|
10
11
|
|
|
12
|
+
// src/compile/parse.ts
|
|
13
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
|
|
11
15
|
// src/editor/view.ts
|
|
12
16
|
var mountView = (editor, action, read) => {
|
|
13
17
|
const { shell } = editor;
|
|
@@ -71,6 +75,111 @@ var vexPlugin = (config) => ({
|
|
|
71
75
|
...config.db !== void 0 ? { widgets: vexWidgets } : {},
|
|
72
76
|
mount: (editor) => mountView(editor, previewAction, (e) => ({ query: e.documents["query"] }))
|
|
73
77
|
});
|
|
78
|
+
var useModelWrite = (model) => {
|
|
79
|
+
const dispatch = react$1.useNovaDispatch();
|
|
80
|
+
return (value) => {
|
|
81
|
+
if (model !== void 0) dispatch({ type: "ui:model", ref: model.ref, payload: value });
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/react/kit/tokens.ts
|
|
86
|
+
var COLORS = {
|
|
87
|
+
border: "var(--loom-border, #d1d5db)",
|
|
88
|
+
borderSubtle: "var(--loom-border-subtle, #e5e7eb)",
|
|
89
|
+
borderFaint: "var(--loom-border-faint, #f1f5f9)",
|
|
90
|
+
surface: "var(--loom-surface, #fff)",
|
|
91
|
+
surfaceMuted: "var(--loom-surface-muted, #f9fafb)",
|
|
92
|
+
fill: "var(--loom-fill, #f3f4f6)",
|
|
93
|
+
muted: "var(--loom-muted, #6b7280)",
|
|
94
|
+
danger: "var(--loom-danger, #dc2626)",
|
|
95
|
+
dangerText: "var(--loom-danger-text, #991b1b)",
|
|
96
|
+
dangerFill: "var(--loom-danger-fill, #fef2f2)",
|
|
97
|
+
dangerBorder: "var(--loom-danger-border, #fecaca)",
|
|
98
|
+
warningText: "var(--loom-warning-text, #92400e)",
|
|
99
|
+
warningFill: "var(--loom-warning-fill, #fffbeb)",
|
|
100
|
+
warningBorder: "var(--loom-warning-border, #fde68a)",
|
|
101
|
+
shadow: "var(--loom-shadow, rgba(0,0,0,0.12))"};
|
|
102
|
+
|
|
103
|
+
// src/react/kit/shared.ts
|
|
104
|
+
var inputStyle = { padding: "6px 10px", border: `1px solid ${COLORS.border}`, borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
|
|
105
|
+
var rawStyle = {
|
|
106
|
+
...inputStyle,
|
|
107
|
+
margin: 0,
|
|
108
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
109
|
+
fontSize: 13,
|
|
110
|
+
minHeight: 64,
|
|
111
|
+
resize: "vertical",
|
|
112
|
+
width: "100%",
|
|
113
|
+
boxSizing: "border-box"
|
|
114
|
+
};
|
|
115
|
+
var showJson = (value) => JSON.stringify(value ?? null, null, 2);
|
|
116
|
+
var JsonEditor = ({ value, onChange }) => {
|
|
117
|
+
const [text, setText] = react.useState(() => showJson(value));
|
|
118
|
+
const [valid, setValid] = react.useState(true);
|
|
119
|
+
const serialized = JSON.stringify(value ?? null);
|
|
120
|
+
react.useEffect(() => {
|
|
121
|
+
let mine;
|
|
122
|
+
try {
|
|
123
|
+
mine = JSON.parse(text);
|
|
124
|
+
} catch {
|
|
125
|
+
setText(showJson(value));
|
|
126
|
+
setValid(true);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (JSON.stringify(mine ?? null) !== serialized) {
|
|
130
|
+
setText(showJson(value));
|
|
131
|
+
setValid(true);
|
|
132
|
+
}
|
|
133
|
+
}, [serialized]);
|
|
134
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
135
|
+
"textarea",
|
|
136
|
+
{
|
|
137
|
+
value: text,
|
|
138
|
+
spellCheck: false,
|
|
139
|
+
onChange: (event) => {
|
|
140
|
+
const next = event.target.value;
|
|
141
|
+
setText(next);
|
|
142
|
+
try {
|
|
143
|
+
const parsed = JSON.parse(next);
|
|
144
|
+
setValid(true);
|
|
145
|
+
onChange(parsed);
|
|
146
|
+
} catch {
|
|
147
|
+
setValid(false);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
style: valid ? rawStyle : { ...rawStyle, borderColor: COLORS.danger, background: COLORS.dangerFill }
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
react.createContext(0);
|
|
155
|
+
react.createContext({ close: () => {
|
|
156
|
+
}, anchor: "right" });
|
|
157
|
+
var clashStyle = { fontSize: 12, color: COLORS.danger };
|
|
158
|
+
var KeyInput = ({ value, isTaken, onRename, placeholder, style }) => {
|
|
159
|
+
const [clash, setClash] = react.useState(void 0);
|
|
160
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 2 }, children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
162
|
+
"input",
|
|
163
|
+
{
|
|
164
|
+
value: clash ?? value,
|
|
165
|
+
placeholder,
|
|
166
|
+
"aria-invalid": clash !== void 0,
|
|
167
|
+
onChange: (event) => {
|
|
168
|
+
const name = event.target.value;
|
|
169
|
+
if (name !== value && isTaken(name)) {
|
|
170
|
+
setClash(name);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
setClash(void 0);
|
|
174
|
+
if (name !== value) onRename(name);
|
|
175
|
+
},
|
|
176
|
+
onBlur: () => setClash(void 0),
|
|
177
|
+
style: clash === void 0 ? style : { ...style, borderColor: COLORS.danger }
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
clash !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { role: "alert", style: clashStyle, children: `"${clash}" is already a key` }) : null
|
|
181
|
+
] });
|
|
182
|
+
};
|
|
74
183
|
var makePreview = (run) => {
|
|
75
184
|
const Preview = ({ query }) => {
|
|
76
185
|
const [state, setState] = react.useState({ status: "empty" });
|
|
@@ -110,17 +219,17 @@ var PreviewView = ({ state }) => {
|
|
|
110
219
|
] });
|
|
111
220
|
};
|
|
112
221
|
var mono = "ui-monospace, SFMono-Regular, Menlo, monospace";
|
|
113
|
-
var Note = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color:
|
|
222
|
+
var Note = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color: COLORS.muted, padding: 12 }, children });
|
|
114
223
|
var TONES = {
|
|
115
|
-
error: { fg:
|
|
116
|
-
warn: { fg:
|
|
224
|
+
error: { fg: COLORS.dangerText, bg: COLORS.dangerFill, border: COLORS.dangerBorder },
|
|
225
|
+
warn: { fg: COLORS.warningText, bg: COLORS.warningFill, border: COLORS.warningBorder }
|
|
117
226
|
};
|
|
118
227
|
var Banner = ({ tone, lines }) => {
|
|
119
228
|
const c = TONES[tone];
|
|
120
229
|
return /* @__PURE__ */ jsxRuntime.jsx("pre", { style: { margin: 0, padding: 12, background: c.bg, color: c.fg, border: `1px solid ${c.border}`, borderRadius: 6, fontSize: 12, fontFamily: mono, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: lines.join("\n") });
|
|
121
230
|
};
|
|
122
|
-
var th = { textAlign: "left", padding: "6px 10px", background:
|
|
123
|
-
var td = { padding: "6px 10px", borderBottom:
|
|
231
|
+
var th = { textAlign: "left", padding: "6px 10px", background: COLORS.surfaceMuted, borderBottom: `1px solid ${COLORS.borderSubtle}`, color: COLORS.muted, fontWeight: 600, whiteSpace: "nowrap" };
|
|
232
|
+
var td = { padding: "6px 10px", borderBottom: `1px solid ${COLORS.borderFaint}`, fontFamily: mono, whiteSpace: "nowrap" };
|
|
124
233
|
var cell = (value) => value === null ? "\u2205" : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
125
234
|
var RowsTable = ({ rows }) => {
|
|
126
235
|
if (rows.length === 0) return /* @__PURE__ */ jsxRuntime.jsx(Note, { children: "No rows." });
|
|
@@ -129,21 +238,13 @@ var RowsTable = ({ rows }) => {
|
|
|
129
238
|
return /* @__PURE__ */ jsxRuntime.jsx(Banner, { tone: "warn", lines: [JSON.stringify(rows, null, 2)] });
|
|
130
239
|
}
|
|
131
240
|
const cols = Object.keys(first);
|
|
132
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflow: "auto", border:
|
|
241
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflow: "auto", border: `1px solid ${COLORS.borderSubtle}`, borderRadius: 6 }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { style: { borderCollapse: "collapse", width: "100%", fontSize: 12 }, children: [
|
|
133
242
|
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: cols.map((c) => /* @__PURE__ */ jsxRuntime.jsx("th", { style: th, children: c }, c)) }) }),
|
|
134
243
|
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.map((row, i) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: cols.map((c) => /* @__PURE__ */ jsxRuntime.jsx("td", { style: td, children: cell(row[c]) }, c)) }, i)) })
|
|
135
244
|
] }) });
|
|
136
245
|
};
|
|
137
|
-
var useModelWrite = (model) => {
|
|
138
|
-
const dispatch = react$1.useNovaDispatch();
|
|
139
|
-
return (value) => {
|
|
140
|
-
if (model !== void 0) dispatch({ type: "ui:model", ref: model.ref, payload: value });
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
246
|
var LoomDocumentContext = react.createContext(void 0);
|
|
144
247
|
var useLoomDocument = () => react.useContext(LoomDocumentContext);
|
|
145
|
-
|
|
146
|
-
// src/plugins/vex/react/columns.ts
|
|
147
248
|
var useScopedColumns = (catalog) => {
|
|
148
249
|
const document = useLoomDocument();
|
|
149
250
|
const from = document === void 0 ? void 0 : nova.getPath(document, "query.from");
|
|
@@ -155,9 +256,9 @@ var useScopedColumns = (catalog) => {
|
|
|
155
256
|
};
|
|
156
257
|
|
|
157
258
|
// src/plugins/vex/react/styles.ts
|
|
158
|
-
var
|
|
159
|
-
var controlBtn = { padding: "6px 10px", border:
|
|
160
|
-
var comboListStyle = { position: "absolute", top: "100%", left: 0, right: 0, zIndex: 20, marginTop: 2, maxHeight: 200, overflowY: "auto", background:
|
|
259
|
+
var fieldStyle2 = { padding: "6px 10px", border: `1px solid ${COLORS.border}`, borderRadius: 6, fontSize: 14, boxSizing: "border-box" };
|
|
260
|
+
var controlBtn = { padding: "6px 10px", border: `1px solid ${COLORS.border}`, borderRadius: 6, background: COLORS.fill, cursor: "pointer", fontSize: 13 };
|
|
261
|
+
var comboListStyle = { position: "absolute", top: "100%", left: 0, right: 0, zIndex: 20, marginTop: 2, maxHeight: 200, overflowY: "auto", background: COLORS.surface, border: `1px solid ${COLORS.border}`, borderRadius: 6, boxShadow: `0 6px 16px ${COLORS.shadow}` };
|
|
161
262
|
var comboItemStyle = { padding: "6px 10px", fontSize: 13, cursor: "pointer", fontFamily: "ui-monospace, Menlo, monospace" };
|
|
162
263
|
var Combo = ({ value, placeholder, options, onPick, style }) => {
|
|
163
264
|
const [open, setOpen] = react.useState(false);
|
|
@@ -172,7 +273,7 @@ var Combo = ({ value, placeholder, options, onPick, style }) => {
|
|
|
172
273
|
onChange: (event) => onPick(event.target.value),
|
|
173
274
|
onFocus: () => setOpen(true),
|
|
174
275
|
onBlur: () => window.setTimeout(() => setOpen(false), 120),
|
|
175
|
-
style: { ...
|
|
276
|
+
style: { ...fieldStyle2, width: "100%" }
|
|
176
277
|
}
|
|
177
278
|
),
|
|
178
279
|
open && matches2.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: comboListStyle, children: matches2.slice(0, 50).map((option) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -196,7 +297,7 @@ var FieldPath = ({ value, catalog, model }) => {
|
|
|
196
297
|
return /* @__PURE__ */ jsxRuntime.jsx(Combo, { value: String(value ?? ""), placeholder: "entity.field", options: columns, onPick: set, style: { width: "100%" } });
|
|
197
298
|
};
|
|
198
299
|
var Operand = ({ type, value, onChange }) => {
|
|
199
|
-
const style = { ...
|
|
300
|
+
const style = { ...fieldStyle2, flex: 1, minWidth: 0 };
|
|
200
301
|
if (type === "number") {
|
|
201
302
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
202
303
|
"input",
|
|
@@ -257,83 +358,33 @@ var Comparison = ({ value, catalog, model }) => {
|
|
|
257
358
|
};
|
|
258
359
|
var fieldPathWidget = (catalog) => ({ value, novaModel }) => /* @__PURE__ */ jsxRuntime.jsx(FieldPath, { value, catalog, model: novaModel });
|
|
259
360
|
var comparisonWidget = (catalog) => ({ value, novaModel }) => /* @__PURE__ */ jsxRuntime.jsx(Comparison, { value, catalog, model: novaModel });
|
|
260
|
-
|
|
261
|
-
// src/compile/parse.ts
|
|
262
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
263
|
-
|
|
264
|
-
// src/react/kit/shared.ts
|
|
265
|
-
var inputStyle = { padding: "6px 10px", border: "1px solid #d1d5db", borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
|
|
266
|
-
var rawStyle = {
|
|
267
|
-
...inputStyle,
|
|
268
|
-
margin: 0,
|
|
269
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
270
|
-
fontSize: 13,
|
|
271
|
-
minHeight: 64,
|
|
272
|
-
resize: "vertical",
|
|
273
|
-
width: "100%",
|
|
274
|
-
boxSizing: "border-box"
|
|
275
|
-
};
|
|
276
|
-
var showJson = (value) => JSON.stringify(value ?? null, null, 2);
|
|
277
|
-
var JsonEditor = ({ value, onChange }) => {
|
|
278
|
-
const [text, setText] = react.useState(() => showJson(value));
|
|
279
|
-
const [valid, setValid] = react.useState(true);
|
|
280
|
-
const serialized = JSON.stringify(value ?? null);
|
|
281
|
-
react.useEffect(() => {
|
|
282
|
-
let mine;
|
|
283
|
-
try {
|
|
284
|
-
mine = JSON.parse(text);
|
|
285
|
-
} catch {
|
|
286
|
-
setText(showJson(value));
|
|
287
|
-
setValid(true);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (JSON.stringify(mine ?? null) !== serialized) {
|
|
291
|
-
setText(showJson(value));
|
|
292
|
-
setValid(true);
|
|
293
|
-
}
|
|
294
|
-
}, [serialized]);
|
|
295
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
296
|
-
"textarea",
|
|
297
|
-
{
|
|
298
|
-
value: text,
|
|
299
|
-
spellCheck: false,
|
|
300
|
-
onChange: (event) => {
|
|
301
|
-
const next = event.target.value;
|
|
302
|
-
setText(next);
|
|
303
|
-
try {
|
|
304
|
-
const parsed = JSON.parse(next);
|
|
305
|
-
setValid(true);
|
|
306
|
-
onChange(parsed);
|
|
307
|
-
} catch {
|
|
308
|
-
setValid(false);
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
style: valid ? rawStyle : { ...rawStyle, borderColor: "#dc2626", background: "#fef2f2" }
|
|
312
|
-
}
|
|
313
|
-
);
|
|
314
|
-
};
|
|
315
|
-
react.createContext(0);
|
|
316
|
-
react.createContext({ close: () => {
|
|
317
|
-
}, anchor: "right" });
|
|
318
361
|
var RecordRows = ({ value, model, newEntry, renderValue }) => {
|
|
319
362
|
const set = useModelWrite(model);
|
|
320
363
|
const entries = isRecord(value) ? Object.entries(value) : [];
|
|
321
364
|
const write = (next) => set(Object.fromEntries(next));
|
|
322
|
-
|
|
365
|
+
const rename = (index, to) => write(entries.map((entry, i) => i === index ? [to, entry[1]] : entry));
|
|
366
|
+
const freeAlias = () => {
|
|
367
|
+
const taken = new Set(entries.map(([key]) => key));
|
|
368
|
+
let n = entries.length + 1;
|
|
369
|
+
while (taken.has(`field_${n}`)) n += 1;
|
|
370
|
+
return `field_${n}`;
|
|
371
|
+
};
|
|
372
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6, padding: 12, border: `1px dashed ${COLORS.border}`, borderRadius: 6 }, children: [
|
|
323
373
|
entries.map(([key, val], index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6, alignItems: "flex-start" }, children: [
|
|
324
374
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
325
|
-
|
|
375
|
+
KeyInput,
|
|
326
376
|
{
|
|
327
377
|
value: key,
|
|
328
378
|
placeholder: "alias",
|
|
329
|
-
|
|
330
|
-
|
|
379
|
+
isTaken: (name) => entries.some(([other]) => other === name),
|
|
380
|
+
onRename: (name) => rename(index, name),
|
|
381
|
+
style: { ...fieldStyle2, width: 110 }
|
|
331
382
|
}
|
|
332
383
|
),
|
|
333
384
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, minWidth: 0 }, children: renderValue(val, (next) => write(entries.map((entry, i) => i === index ? [entry[0], next] : entry))) }),
|
|
334
385
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => write(entries.filter((_, i) => i !== index)), style: controlBtn, children: "\u2715" })
|
|
335
386
|
] }, index)),
|
|
336
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => write([...entries, [
|
|
387
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => write([...entries, [freeAlias(), newEntry]]), style: { ...controlBtn, alignSelf: "flex-start" }, children: "Add" })
|
|
337
388
|
] });
|
|
338
389
|
};
|
|
339
390
|
var coerceLiteral = (text) => {
|
|
@@ -343,16 +394,23 @@ var coerceLiteral = (text) => {
|
|
|
343
394
|
const n = Number(text);
|
|
344
395
|
return text.trim() !== "" && Number.isFinite(n) ? n : text;
|
|
345
396
|
};
|
|
346
|
-
var ValueInput = ({ value, columns, onChange }) =>
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
)
|
|
397
|
+
var ValueInput = ({ value, columns, onChange }) => {
|
|
398
|
+
const [typed, setTyped] = react.useState(void 0);
|
|
399
|
+
const stored = value === null || value === void 0 ? "" : String(value);
|
|
400
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
401
|
+
Combo,
|
|
402
|
+
{
|
|
403
|
+
value: typed !== void 0 && Object.is(coerceLiteral(typed), value) ? typed : stored,
|
|
404
|
+
placeholder: "field or value",
|
|
405
|
+
options: columns,
|
|
406
|
+
onPick: (text) => {
|
|
407
|
+
setTyped(text);
|
|
408
|
+
onChange(coerceLiteral(text));
|
|
409
|
+
},
|
|
410
|
+
style: { flex: 1, minWidth: 120 }
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
};
|
|
356
414
|
var AGG_OPS = ["count", "sum", "avg", "min", "max"];
|
|
357
415
|
var AggregateValue = ({ value, onChange, catalog }) => {
|
|
358
416
|
const columns = useScopedColumns(catalog);
|
|
@@ -367,7 +425,7 @@ var AggregateValue = ({ value, onChange, catalog }) => {
|
|
|
367
425
|
onChange({ [next]: carried });
|
|
368
426
|
};
|
|
369
427
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6, alignItems: "center" }, children: [
|
|
370
|
-
/* @__PURE__ */ jsxRuntime.jsx("select", { value: op, onChange: (event) => switchOp(event.target.value), style: { ...
|
|
428
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { value: op, onChange: (event) => switchOp(event.target.value), style: { ...fieldStyle2, width: 90 }, children: AGG_OPS.map((candidate) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: candidate, children: candidate }, candidate)) }),
|
|
371
429
|
/* @__PURE__ */ jsxRuntime.jsx(Combo, { value: operand, placeholder: "entity.field", options, onPick: (next) => onChange({ [op]: next }), style: { flex: 1, minWidth: 0 } })
|
|
372
430
|
] });
|
|
373
431
|
};
|
|
@@ -389,7 +447,7 @@ var ComputeValue = ({ value, onChange, catalog }) => {
|
|
|
389
447
|
}
|
|
390
448
|
};
|
|
391
449
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6, alignItems: "flex-start", flexWrap: "wrap" }, children: [
|
|
392
|
-
/* @__PURE__ */ jsxRuntime.jsx("select", { value: op, onChange: (event) => switchOp(event.target.value), style: { ...
|
|
450
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { value: op, onChange: (event) => switchOp(event.target.value), style: { ...fieldStyle2, width: 90 }, children: COMPUTE_OPS.map((candidate) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: candidate, children: candidate }, candidate)) }),
|
|
393
451
|
ARITHMETIC.has(op) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
394
452
|
/* @__PURE__ */ jsxRuntime.jsx(ValueInput, { value: operands[0], columns, onChange: (next) => onChange({ [op]: [next, operands[1] ?? ""] }) }),
|
|
395
453
|
/* @__PURE__ */ jsxRuntime.jsx(ValueInput, { value: operands[1], columns, onChange: (next) => onChange({ [op]: [operands[0] ?? "", next] }) })
|