@wildwinter/expr-editor 0.13.1 → 0.14.1
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 +50 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +50 -12
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2 -1
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -288,6 +288,13 @@ var choicesOf = (e) => {
|
|
|
288
288
|
if (e.type === "enum") return e.enumValues;
|
|
289
289
|
return void 0;
|
|
290
290
|
};
|
|
291
|
+
var propertyTip = (e) => {
|
|
292
|
+
if (!e) return void 0;
|
|
293
|
+
const lines = [];
|
|
294
|
+
if (e.purpose) lines.push(e.purpose);
|
|
295
|
+
if (e.type === "quality" && e.stages?.length) lines.push(`Stages: ${e.stages.join(" \u2192 ")}`);
|
|
296
|
+
return lines.length ? lines.join("\n") : void 0;
|
|
297
|
+
};
|
|
291
298
|
var refOf = (e, defaultScope) => e.scope === defaultScope ? `@${e.name}` : `@${e.scope}.${e.name}`;
|
|
292
299
|
var displayName = (e, defaultScope) => e.scope === defaultScope ? e.name : `${e.scope}.${e.name}`;
|
|
293
300
|
function filterCatalogue(entries, filter = {}) {
|
|
@@ -422,6 +429,14 @@ function textField(opts) {
|
|
|
422
429
|
setTimeout(() => input.focus(), 0);
|
|
423
430
|
return wrap;
|
|
424
431
|
}
|
|
432
|
+
function propertyMenuBody(actions, close) {
|
|
433
|
+
const wrap = el("div", "exed-menu");
|
|
434
|
+
for (const a of actions) wrap.append(button("exed-opt", a.label, () => {
|
|
435
|
+
a.run();
|
|
436
|
+
close();
|
|
437
|
+
}));
|
|
438
|
+
return wrap;
|
|
439
|
+
}
|
|
425
440
|
|
|
426
441
|
// src/flat.ts
|
|
427
442
|
var FLAG_FNS = /* @__PURE__ */ new Set(["check_flags", "set_flags"]);
|
|
@@ -459,7 +474,12 @@ function renderNode(node, path, ctx, parentOp, side) {
|
|
|
459
474
|
case "scopedvar": {
|
|
460
475
|
const entry = lookup(ctx.catalogue, node.scope, node.name);
|
|
461
476
|
const label = displayName({ scope: node.scope, name: node.name }, ctx.defaultScope);
|
|
462
|
-
const varPill = pill(
|
|
477
|
+
const varPill = pill(
|
|
478
|
+
"var",
|
|
479
|
+
label,
|
|
480
|
+
(b) => variableEditor(ctx, path, node, b),
|
|
481
|
+
{ issue: issue ?? (entry ? void 0 : `Unknown property ${label}`), title: propertyTip(entry) }
|
|
482
|
+
);
|
|
463
483
|
attachPropertyMenu(ctx, node, varPill);
|
|
464
484
|
return varPill;
|
|
465
485
|
}
|
|
@@ -535,14 +555,7 @@ function attachPropertyMenu(ctx, node, pillEl) {
|
|
|
535
555
|
const open = ctx.openMenu ?? ctx.openPopover;
|
|
536
556
|
pillEl.addEventListener("contextmenu", (e) => {
|
|
537
557
|
e.preventDefault();
|
|
538
|
-
open(pillEl, (close) =>
|
|
539
|
-
const wrap = el("div", "exed-menu");
|
|
540
|
-
for (const a of actions) wrap.append(button("exed-opt", a.label, () => {
|
|
541
|
-
a.run();
|
|
542
|
-
close();
|
|
543
|
-
}));
|
|
544
|
-
return wrap;
|
|
545
|
-
});
|
|
558
|
+
open(pillEl, (close) => propertyMenuBody(actions, close));
|
|
546
559
|
});
|
|
547
560
|
}
|
|
548
561
|
function isCompoundComparison(node, ctx) {
|
|
@@ -1552,6 +1565,7 @@ function mountEffectsEditor(host, opts) {
|
|
|
1552
1565
|
valueField: true,
|
|
1553
1566
|
...addTerm ? { addTerm } : {},
|
|
1554
1567
|
...selfAdvanceRef ? { selfAdvanceRef } : {},
|
|
1568
|
+
...opts.propertyActions ? { propertyActions: opts.propertyActions } : {},
|
|
1555
1569
|
...opts.popoverContainer ? { popoverContainer: opts.popoverContainer } : {},
|
|
1556
1570
|
text: textMode,
|
|
1557
1571
|
onChange
|
|
@@ -1602,6 +1616,17 @@ function mountEffectsEditor(host, opts) {
|
|
|
1602
1616
|
commit(updateAt(effects, i, { target: refOf(entry, defaultScope), value: initialValueFor(entry, defaultScope).src }));
|
|
1603
1617
|
});
|
|
1604
1618
|
}, "change the target property");
|
|
1619
|
+
const targetEntry = opts.catalogue.find((e) => refOf(e, defaultScope) === eff.target);
|
|
1620
|
+
const tip = propertyTip(targetEntry);
|
|
1621
|
+
if (tip) targetBtn.title = tip;
|
|
1622
|
+
if (targetEntry && opts.propertyActions) {
|
|
1623
|
+
const actions = opts.propertyActions({ scope: targetEntry.scope, name: targetEntry.name });
|
|
1624
|
+
if (actions.length) targetBtn.addEventListener("contextmenu", (e) => {
|
|
1625
|
+
e.preventDefault();
|
|
1626
|
+
closePopover();
|
|
1627
|
+
popover = openPopover(targetBtn, (close) => propertyMenuBody(actions, close), { container: opts.popoverContainer });
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1605
1630
|
const advances = isSelfAdvance(eff, defaultScope, opts.dialect);
|
|
1606
1631
|
row.append(targetBtn);
|
|
1607
1632
|
if (!advances) row.append(el("span", "exed-effect-eq", ["="]));
|
|
@@ -1765,13 +1790,26 @@ function renderConditionPreview(src, o) {
|
|
|
1765
1790
|
const cls = o.propertyActions ? "exed-preview exed-preview-interactive" : "exed-preview";
|
|
1766
1791
|
return el("div", cls, [exprPills(src, o)]);
|
|
1767
1792
|
}
|
|
1793
|
+
function targetPill(ref, o) {
|
|
1794
|
+
const pill2 = el("span", "exed-pill exed-pill-prop", [ref || "(property)"]);
|
|
1795
|
+
const entry = o.catalogue.find((e) => refOf(e, o.dialect.defaultScope) === ref);
|
|
1796
|
+
if (!entry) return pill2;
|
|
1797
|
+
const tip = propertyTip(entry);
|
|
1798
|
+
if (tip) pill2.title = tip;
|
|
1799
|
+
const actions = o.propertyActions?.({ scope: entry.scope, name: entry.name }) ?? [];
|
|
1800
|
+
if (actions.length) pill2.addEventListener("contextmenu", (e) => {
|
|
1801
|
+
e.preventDefault();
|
|
1802
|
+
openPopover(pill2, (close) => propertyMenuBody(actions, close), { container: o.popoverContainer });
|
|
1803
|
+
});
|
|
1804
|
+
return pill2;
|
|
1805
|
+
}
|
|
1768
1806
|
function renderEffectsPreview(effects, o) {
|
|
1769
|
-
const wrap = el("div",
|
|
1807
|
+
const wrap = el("div", `exed-preview exed-preview-effects${o.propertyActions ? " exed-preview-interactive" : ""}`);
|
|
1770
1808
|
for (const eff of effects) {
|
|
1771
1809
|
const row = el("div", "exed-preview-eff");
|
|
1772
1810
|
if (eff.kind === "set") {
|
|
1773
1811
|
const advances = isSelfAdvance(eff, o.dialect.defaultScope, o.dialect);
|
|
1774
|
-
row.append(
|
|
1812
|
+
row.append(targetPill(eff.target, o));
|
|
1775
1813
|
if (!advances) row.append(el("span", "exed-effect-eq", ["="]));
|
|
1776
1814
|
row.append(exprPills(eff.value, o, advances ? eff.target : void 0));
|
|
1777
1815
|
} else {
|
|
@@ -1837,6 +1875,7 @@ exports.numLit = numLit;
|
|
|
1837
1875
|
exports.opSwapGroup = opSwapGroup;
|
|
1838
1876
|
exports.pathKey = pathKey;
|
|
1839
1877
|
exports.placeholderForOp = placeholderForOp;
|
|
1878
|
+
exports.propertyTip = propertyTip;
|
|
1840
1879
|
exports.redirectDeleteForPlaceholderSibling = redirectDeleteForPlaceholderSibling;
|
|
1841
1880
|
exports.refOf = refOf;
|
|
1842
1881
|
exports.removeArgAt = removeArgAt;
|