@wildwinter/expr-editor 0.8.0 → 0.10.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 CHANGED
@@ -63,6 +63,11 @@ Notable options beyond the basics:
63
63
  Pills carry `aria-haspopup`/labels and the tree controls carry aria-labels for
64
64
  assistive tech. A comparison of a numeric dialect function against a number
65
65
  (e.g. `turns_since_tag("x") > 3`) deletes as a unit.
66
+
67
+ `renderConditionPreview(src, opts)` / `renderEffectsPreview(effects, opts)`
68
+ return read-only pill strips (same pills as the editor, non-interactive). Pass
69
+ `propertyActions` to make property pills right-click interactive (e.g. "Go to
70
+ definition") while left-click still falls through to the host.
66
71
  - `setText(on)` — the host's raw-text toggle (`</>`); unparseable input falls
67
72
  back to raw text automatically.
68
73
 
package/dist/index.cjs CHANGED
@@ -443,6 +443,13 @@ function renderNode(node, path, ctx, parentOp, side) {
443
443
  case "flagdelta":
444
444
  return pill(node.sign === "+" ? "flagpos" : "flagneg", `${node.sign}${node.name || "flag"}`, (b) => flagEditor(ctx, path, node, b), { issue, path });
445
445
  case "call": {
446
+ if (ctx.compact && ctx.dialect.functions[node.name]?.flagDeltaArgs && node.args.length >= 2 && node.args[0].kind === "scopedvar" && node.args.slice(1).every((a) => a.kind === "flagdelta")) {
447
+ const row2 = el("span", "exed-call exed-call-flags");
448
+ row2.append(renderNode(node.args[0], [...path, "args", 0], ctx));
449
+ row2.append(el("span", "exed-flagsep", [":"]));
450
+ for (let i = 1; i < node.args.length; i++) row2.append(renderNode(node.args[i], [...path, "args", i], ctx));
451
+ return row2;
452
+ }
446
453
  const row = el("span", "exed-call");
447
454
  row.append(pill("func", node.name, (b) => callEditor(ctx, path, node, b), { issue }));
448
455
  row.append(el("span", "exed-paren", ["("]));
@@ -492,9 +499,10 @@ function attachPropertyMenu(ctx, node, pillEl) {
492
499
  if (!ctx.propertyActions) return;
493
500
  const actions = ctx.propertyActions({ scope: node.scope, name: node.name });
494
501
  if (!actions.length) return;
502
+ const open = ctx.openMenu ?? ctx.openPopover;
495
503
  pillEl.addEventListener("contextmenu", (e) => {
496
504
  e.preventDefault();
497
- ctx.openPopover(pillEl, (close) => {
505
+ open(pillEl, (close) => {
498
506
  const wrap = el("div", "exed-menu");
499
507
  for (const a of actions) wrap.append(button("exed-opt", a.label, () => {
500
508
  a.run();
@@ -1655,6 +1663,7 @@ function frozenCtx(src, o) {
1655
1663
  catalogue: o.catalogue,
1656
1664
  scopeOrder: o.scopeOrder ?? [],
1657
1665
  functions: [],
1666
+ compact: true,
1658
1667
  byPath: v.byPath,
1659
1668
  getAst: () => v.ast,
1660
1669
  apply: () => {
@@ -1664,7 +1673,13 @@ function frozenCtx(src, o) {
1664
1673
  pickNode: () => {
1665
1674
  },
1666
1675
  // enables labelled node pills; never fires (preview is read-only)
1667
- ...o.nodeLabel ? { nodeLabel: o.nodeLabel } : {}
1676
+ ...o.nodeLabel ? { nodeLabel: o.nodeLabel } : {},
1677
+ ...o.propertyActions ? {
1678
+ propertyActions: o.propertyActions,
1679
+ openMenu: (anchor, render) => {
1680
+ openPopover(anchor, render, { container: o.popoverContainer });
1681
+ }
1682
+ } : {}
1668
1683
  };
1669
1684
  return { ctx, ast: v.ast };
1670
1685
  }
@@ -1673,7 +1688,8 @@ function exprPills(src, o) {
1673
1688
  return ast ? renderNode(ast, [], ctx) : el("span", "exed-preview-raw", [src]);
1674
1689
  }
1675
1690
  function renderConditionPreview(src, o) {
1676
- return el("div", "exed-preview", [exprPills(src, o)]);
1691
+ const cls = o.propertyActions ? "exed-preview exed-preview-interactive" : "exed-preview";
1692
+ return el("div", cls, [exprPills(src, o)]);
1677
1693
  }
1678
1694
  function renderEffectsPreview(effects, o) {
1679
1695
  const wrap = el("div", "exed-preview exed-preview-effects");