@wildwinter/expr-editor 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/README.md +5 -5
- package/dist/index.cjs +39 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +39 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,11 +50,11 @@ Notable options beyond the basics:
|
|
|
50
50
|
outcome-style value cell: `valueEnumValues` offers a target's enum values on
|
|
51
51
|
the root literal, and `valueField` makes an empty value render one editable
|
|
52
52
|
"set a value…" pill instead of the condition clause-menu empty state.
|
|
53
|
-
- `flagValue: { target }` — flat compact editor for a
|
|
54
|
-
value whose target is implied by context: renders only
|
|
55
|
-
plus an "+ flag" chip
|
|
56
|
-
|
|
57
|
-
can't be removed.
|
|
53
|
+
- `flagValue: { target, flags }` — flat compact editor for a
|
|
54
|
+
`set_flags(@target, …)` value whose target is implied by context: renders only
|
|
55
|
+
the flag-delta pills plus an "+ flag" chip (which picks sign + name from
|
|
56
|
+
`flags`), hiding the function name and target arg, and seeds the call on the
|
|
57
|
+
first flag add. Pair with `requireNonEmpty` so the last flag can't be removed.
|
|
58
58
|
- `setText(on)` — the host's raw-text toggle (`</>`); unparseable input falls
|
|
59
59
|
back to raw text automatically.
|
|
60
60
|
|
package/dist/index.cjs
CHANGED
|
@@ -1145,27 +1145,52 @@ function mountExpressionEditor(host, opts) {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
function flagValueBody(call) {
|
|
1147
1147
|
const wrap = el("div", "exed-flat exed-flagvalue");
|
|
1148
|
+
const ctx = buildCtx(call ?? boolLit(true));
|
|
1148
1149
|
if (call) {
|
|
1149
|
-
const ctx = buildCtx(call);
|
|
1150
1150
|
call.args.forEach((arg, i) => {
|
|
1151
1151
|
if (arg.kind === "flagdelta") wrap.append(renderNode(arg, ["args", i], ctx));
|
|
1152
1152
|
});
|
|
1153
|
-
wrap.append(addFlagChip(call));
|
|
1154
|
-
} else {
|
|
1155
|
-
wrap.append(addFlagChip(null));
|
|
1156
1153
|
}
|
|
1154
|
+
wrap.append(addFlagChip(ctx, call));
|
|
1157
1155
|
return wrap;
|
|
1158
1156
|
}
|
|
1159
|
-
function addFlagChip(call) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1157
|
+
function addFlagChip(ctx, call) {
|
|
1158
|
+
const flags = opts.flagValue?.flags ?? [];
|
|
1159
|
+
const used = call ? call.args.filter((a) => a.kind === "flagdelta").map((a) => a.name) : [];
|
|
1160
|
+
const available = flags.filter((f) => !used.includes(f));
|
|
1161
|
+
return button("exed-add exed-addflag", "+ flag", (e) => {
|
|
1162
|
+
const anchor = e.currentTarget;
|
|
1163
|
+
ctx.openPopover(anchor, (close) => {
|
|
1164
|
+
let sign = "+";
|
|
1165
|
+
const wrap = el("div", "exed-menu");
|
|
1166
|
+
wrap.append(el("div", "exed-menu-head", ["Add flag"]));
|
|
1167
|
+
const signRow = el("div", "exed-field-row");
|
|
1168
|
+
const drawSign = () => {
|
|
1169
|
+
signRow.replaceChildren(
|
|
1170
|
+
button(`exed-opt${sign === "+" ? " sel" : ""}`, "+ set", () => {
|
|
1171
|
+
sign = "+";
|
|
1172
|
+
drawSign();
|
|
1173
|
+
}),
|
|
1174
|
+
button(`exed-opt${sign === "-" ? " sel" : ""}`, "\u2212 unset", () => {
|
|
1175
|
+
sign = "-";
|
|
1176
|
+
drawSign();
|
|
1177
|
+
})
|
|
1178
|
+
);
|
|
1179
|
+
};
|
|
1180
|
+
drawSign();
|
|
1181
|
+
wrap.append(signRow);
|
|
1182
|
+
const commit = (name) => {
|
|
1183
|
+
const delta = flagDelta(sign, name);
|
|
1184
|
+
emit(toSrc(call ? { ...call, args: [...call.args, delta] } : callNode("set_flags", [parseRef(opts.flagValue.target), delta])));
|
|
1185
|
+
close();
|
|
1186
|
+
};
|
|
1187
|
+
if (available.length) {
|
|
1188
|
+
for (const n of available) wrap.append(button("exed-opt", n, () => commit(n)));
|
|
1189
|
+
} else {
|
|
1190
|
+
wrap.append(el("div", "exed-hint", [flags.length === 0 ? "This flags property declares no flag values yet." : "All declared flags are already used."]));
|
|
1191
|
+
}
|
|
1192
|
+
return wrap;
|
|
1193
|
+
});
|
|
1169
1194
|
}, "add a flag");
|
|
1170
1195
|
}
|
|
1171
1196
|
function addTermControl(ctx) {
|