@wildwinter/expr-editor 0.13.1 → 0.14.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/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 = {}) {
@@ -459,7 +466,12 @@ function renderNode(node, path, ctx, parentOp, side) {
459
466
  case "scopedvar": {
460
467
  const entry = lookup(ctx.catalogue, node.scope, node.name);
461
468
  const label = displayName({ scope: node.scope, name: node.name }, ctx.defaultScope);
462
- const varPill = pill("var", label, (b) => variableEditor(ctx, path, node, b), { issue: issue ?? (entry ? void 0 : `Unknown property ${label}`) });
469
+ const varPill = pill(
470
+ "var",
471
+ label,
472
+ (b) => variableEditor(ctx, path, node, b),
473
+ { issue: issue ?? (entry ? void 0 : `Unknown property ${label}`), title: propertyTip(entry) }
474
+ );
463
475
  attachPropertyMenu(ctx, node, varPill);
464
476
  return varPill;
465
477
  }
@@ -1552,6 +1564,7 @@ function mountEffectsEditor(host, opts) {
1552
1564
  valueField: true,
1553
1565
  ...addTerm ? { addTerm } : {},
1554
1566
  ...selfAdvanceRef ? { selfAdvanceRef } : {},
1567
+ ...opts.propertyActions ? { propertyActions: opts.propertyActions } : {},
1555
1568
  ...opts.popoverContainer ? { popoverContainer: opts.popoverContainer } : {},
1556
1569
  text: textMode,
1557
1570
  onChange
@@ -1602,6 +1615,24 @@ function mountEffectsEditor(host, opts) {
1602
1615
  commit(updateAt(effects, i, { target: refOf(entry, defaultScope), value: initialValueFor(entry, defaultScope).src }));
1603
1616
  });
1604
1617
  }, "change the target property");
1618
+ const targetEntry = opts.catalogue.find((e) => refOf(e, defaultScope) === eff.target);
1619
+ const tip = propertyTip(targetEntry);
1620
+ if (tip) targetBtn.title = tip;
1621
+ if (targetEntry && opts.propertyActions) {
1622
+ const actions = opts.propertyActions({ scope: targetEntry.scope, name: targetEntry.name });
1623
+ if (actions.length) targetBtn.addEventListener("contextmenu", (e) => {
1624
+ e.preventDefault();
1625
+ closePopover();
1626
+ popover = openPopover(targetBtn, (close) => {
1627
+ const wrap = el("div", "exed-menu");
1628
+ for (const a of actions) wrap.append(button("exed-opt", a.label, () => {
1629
+ a.run();
1630
+ close();
1631
+ }));
1632
+ return wrap;
1633
+ }, { container: opts.popoverContainer });
1634
+ });
1635
+ }
1605
1636
  const advances = isSelfAdvance(eff, defaultScope, opts.dialect);
1606
1637
  row.append(targetBtn);
1607
1638
  if (!advances) row.append(el("span", "exed-effect-eq", ["="]));
@@ -1837,6 +1868,7 @@ exports.numLit = numLit;
1837
1868
  exports.opSwapGroup = opSwapGroup;
1838
1869
  exports.pathKey = pathKey;
1839
1870
  exports.placeholderForOp = placeholderForOp;
1871
+ exports.propertyTip = propertyTip;
1840
1872
  exports.redirectDeleteForPlaceholderSibling = redirectDeleteForPlaceholderSibling;
1841
1873
  exports.refOf = refOf;
1842
1874
  exports.removeArgAt = removeArgAt;