@wildwinter/expr-editor 0.12.1 → 0.12.3
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/dist/index.cjs +30 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -5
- package/dist/index.d.ts +22 -5
- package/dist/index.js +29 -32
- package/dist/index.js.map +1 -1
- package/dist/styles.css +8 -0
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -84,14 +84,15 @@ function toggleNotAt(ast, path) {
|
|
|
84
84
|
}
|
|
85
85
|
return wrapInNotAt(ast, path);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function findChoicePeer(ast, path) {
|
|
88
88
|
const last = path[path.length - 1];
|
|
89
89
|
if (last !== "left" && last !== "right") return null;
|
|
90
90
|
const parent = getNodeAt(ast, path.slice(0, -1));
|
|
91
|
-
if (parent?.kind !== "binary" || parent.op
|
|
91
|
+
if (parent?.kind !== "binary" || !isComparisonOp(parent.op)) return null;
|
|
92
92
|
const other = last === "left" ? parent.right : parent.left;
|
|
93
93
|
return other.kind === "scopedvar" ? { scope: other.scope, name: other.name } : null;
|
|
94
94
|
}
|
|
95
|
+
var findEnumPeer = findChoicePeer;
|
|
95
96
|
function firstEmptyLeafPath(node, base = []) {
|
|
96
97
|
switch (node.kind) {
|
|
97
98
|
case "string":
|
|
@@ -220,6 +221,22 @@ var BINARY_LABEL = {
|
|
|
220
221
|
"/": "\xF7"
|
|
221
222
|
};
|
|
222
223
|
var UNARY_LABEL = { not: "NOT", neg: "\u2212" };
|
|
224
|
+
var OP_WORD = {
|
|
225
|
+
"==": "equals",
|
|
226
|
+
"!=": "not equal to",
|
|
227
|
+
">": "greater than",
|
|
228
|
+
">=": "at least",
|
|
229
|
+
"<": "less than",
|
|
230
|
+
"<=": "at most",
|
|
231
|
+
and: "and",
|
|
232
|
+
or: "or",
|
|
233
|
+
"+": "plus",
|
|
234
|
+
"-": "minus",
|
|
235
|
+
"*": "times",
|
|
236
|
+
"/": "divided by",
|
|
237
|
+
not: "not",
|
|
238
|
+
neg: "negative"
|
|
239
|
+
};
|
|
223
240
|
var COMPARISON_OPS = ["==", "!=", ">", ">=", "<", "<="];
|
|
224
241
|
var ARITHMETIC_OPS = ["+", "-", "*", "/"];
|
|
225
242
|
var COMPARABLE_TYPES = ["boolean", "number", "string", "enum", "quality"];
|
|
@@ -405,20 +422,6 @@ function pill(kind, label, onClick, opts = {}) {
|
|
|
405
422
|
if (opts.path) b.dataset["exedPath"] = opts.path.join("/");
|
|
406
423
|
return b;
|
|
407
424
|
}
|
|
408
|
-
var OP_ARIA = {
|
|
409
|
-
"==": "equals",
|
|
410
|
-
"!=": "not equal to",
|
|
411
|
-
">": "greater than",
|
|
412
|
-
">=": "at least",
|
|
413
|
-
"<": "less than",
|
|
414
|
-
"<=": "at most",
|
|
415
|
-
"and": "and",
|
|
416
|
-
"or": "or",
|
|
417
|
-
"+": "plus",
|
|
418
|
-
"-": "minus",
|
|
419
|
-
"*": "times",
|
|
420
|
-
"/": "divided by"
|
|
421
|
-
};
|
|
422
425
|
var issueText = (ctx, path) => {
|
|
423
426
|
const list = issuesAt(ctx.byPath, path);
|
|
424
427
|
return list.length ? list.map((i) => i.message).join("; ") : void 0;
|
|
@@ -472,7 +475,7 @@ function renderNode(node, path, ctx, parentOp, side) {
|
|
|
472
475
|
}
|
|
473
476
|
case "unary": {
|
|
474
477
|
const row = el("span", "exed-unary");
|
|
475
|
-
row.append(pill("op", UNARY_LABEL[node.op], () => ctx.apply(deleteOrUnwrapNot(ctx, path, node)), { title: "remove", aria: `${
|
|
478
|
+
row.append(pill("op", UNARY_LABEL[node.op], () => ctx.apply(deleteOrUnwrapNot(ctx, path, node)), { title: "remove", aria: `${OP_WORD[node.op]} (click to remove)` }));
|
|
476
479
|
row.append(renderNode(node.operand, [...path, "operand"], ctx));
|
|
477
480
|
return row;
|
|
478
481
|
}
|
|
@@ -484,7 +487,7 @@ function renderNode(node, path, ctx, parentOp, side) {
|
|
|
484
487
|
const swap = opSwapGroup(node.op);
|
|
485
488
|
const opPill = pill("op", BINARY_LABEL[node.op], (b) => {
|
|
486
489
|
if (swap) operatorEditor(ctx, path, node.op, swap, b);
|
|
487
|
-
}, { title: swap ? "swap operator" : void 0, aria:
|
|
490
|
+
}, { title: swap ? "swap operator" : void 0, aria: OP_WORD[node.op] });
|
|
488
491
|
if (!swap) opPill.classList.add("exed-op-structural");
|
|
489
492
|
row.append(opPill);
|
|
490
493
|
row.append(renderNode(node.right, [...path, "right"], ctx, node.op, "right"));
|
|
@@ -561,7 +564,7 @@ function numberEditor(ctx, path, value, anchor) {
|
|
|
561
564
|
}));
|
|
562
565
|
}
|
|
563
566
|
function stringEditor(ctx, path, node, anchor) {
|
|
564
|
-
const peer =
|
|
567
|
+
const peer = findChoicePeer(ctx.getAst(), path);
|
|
565
568
|
const enumEntry = peer ? lookup(ctx.catalogue, peer.scope, peer.name) : null;
|
|
566
569
|
const rootValueEnums = path.length === 0 && ctx.valueEnumValues?.length ? ctx.valueEnumValues : null;
|
|
567
570
|
const peerChoices = choicesOf(enumEntry);
|
|
@@ -595,12 +598,14 @@ function operatorEditor(ctx, path, current, group, anchor) {
|
|
|
595
598
|
const wrap = el("div", "exed-menu");
|
|
596
599
|
wrap.append(el("div", "exed-menu-head", ["Operator"]));
|
|
597
600
|
for (const op of group) {
|
|
598
|
-
|
|
601
|
+
const row = button(`exed-opt exed-opt-op${op === current ? " sel" : ""}`, "", () => {
|
|
599
602
|
const node = ctx.getAst();
|
|
600
603
|
const cur = setNodeAt(node, path, { ...getBinary(ctx, path), op });
|
|
601
604
|
ctx.apply(cur);
|
|
602
605
|
close();
|
|
603
|
-
})
|
|
606
|
+
});
|
|
607
|
+
row.append(el("span", "exed-opt-name", [BINARY_LABEL[op]]), el("span", "exed-opt-purpose", [OP_WORD[op]]));
|
|
608
|
+
wrap.append(row);
|
|
604
609
|
}
|
|
605
610
|
return wrap;
|
|
606
611
|
});
|
|
@@ -716,17 +721,9 @@ function propertyPicker(ctx, opts) {
|
|
|
716
721
|
}
|
|
717
722
|
|
|
718
723
|
// src/clausewizard.ts
|
|
719
|
-
var OP_WORD = {
|
|
720
|
-
"==": "equals",
|
|
721
|
-
"!=": "not equal to",
|
|
722
|
-
">": "greater than",
|
|
723
|
-
">=": "at least",
|
|
724
|
-
"<": "less than",
|
|
725
|
-
"<=": "at most"
|
|
726
|
-
};
|
|
727
724
|
var opButton = (o, onClick) => {
|
|
728
|
-
const b = button("exed-opt", "", onClick);
|
|
729
|
-
b.append(el("span", "exed-opt-name", [BINARY_LABEL[o]]), el("span", "exed-opt-purpose", [OP_WORD[o]
|
|
725
|
+
const b = button("exed-opt exed-opt-op", "", onClick);
|
|
726
|
+
b.append(el("span", "exed-opt-name", [BINARY_LABEL[o]]), el("span", "exed-opt-purpose", [OP_WORD[o]]));
|
|
730
727
|
return b;
|
|
731
728
|
};
|
|
732
729
|
function header(host, title, back, cancel) {
|
|
@@ -1753,6 +1750,7 @@ exports.BINARY_LABEL = BINARY_LABEL;
|
|
|
1753
1750
|
exports.COMPARABLE_TYPES = COMPARABLE_TYPES;
|
|
1754
1751
|
exports.COMPARISON_OPS = COMPARISON_OPS;
|
|
1755
1752
|
exports.EQUALITY_OPS = EQUALITY_OPS;
|
|
1753
|
+
exports.OP_WORD = OP_WORD;
|
|
1756
1754
|
exports.UNARY_LABEL = UNARY_LABEL;
|
|
1757
1755
|
exports.addArg = addArg;
|
|
1758
1756
|
exports.addChildToContainer = addChildToContainer;
|
|
@@ -1768,6 +1766,7 @@ exports.comparisonOpsFor = comparisonOpsFor;
|
|
|
1768
1766
|
exports.deleteAt = deleteAt;
|
|
1769
1767
|
exports.displayName = displayName;
|
|
1770
1768
|
exports.filterCatalogue = filterCatalogue;
|
|
1769
|
+
exports.findChoicePeer = findChoicePeer;
|
|
1771
1770
|
exports.findEnumPeer = findEnumPeer;
|
|
1772
1771
|
exports.firstEmptyLeafPath = firstEmptyLeafPath;
|
|
1773
1772
|
exports.flagDelta = flagDelta;
|