@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.d.cts CHANGED
@@ -34,14 +34,25 @@ declare function wrapInNotAt(ast: ExprNode, path: AstPath): ExprNode;
34
34
  /** Add a `not` if absent, strip it if present. */
35
35
  declare function toggleNotAt(ast: ExprNode, path: AstPath): ExprNode;
36
36
  /**
37
- * If the node at `path` is one operand of an equality comparison (`==` / `!=`)
38
- * whose OTHER operand is a property reference, return that property — so a string
39
- * literal can offer the property's enum values. Null otherwise.
37
+ * If the node at `path` is one operand of a COMPARISON whose other operand is a property
38
+ * reference, return that property - so a literal can offer that property's choices (an enum's
39
+ * values, a quality's stages).
40
+ *
41
+ * Every comparison counts, not just `==` / `!=`. Equality was enough while an enum was the only
42
+ * type with a closed value list, because an enum is never ordered; a QUALITY is ordered, and
43
+ * `@investigation >= "certain"` is the shape its type exists for. Restricting to equality left
44
+ * exactly that clause offering a free-text box where the ladder should be.
45
+ *
46
+ * Whether the peer HAS choices is not decided here - that is `choicesOf`'s job. This answers only
47
+ * "which property is this literal being compared against", so a number's `> 1` resolves its peer
48
+ * and then offers nothing, as before.
40
49
  */
41
- declare function findEnumPeer(ast: ExprNode, path: AstPath): {
50
+ declare function findChoicePeer(ast: ExprNode, path: AstPath): {
42
51
  scope: string;
43
52
  name: string;
44
53
  } | null;
54
+ /** @deprecated Renamed to {@link findChoicePeer} - it serves qualities as well as enums now. */
55
+ declare const findEnumPeer: typeof findChoicePeer;
45
56
  /**
46
57
  * DFS for the first unfilled slot in a template-inserted clause: an empty string
47
58
  * literal (a tag / value the author still has to set) or an unnamed flag delta.
@@ -97,6 +108,12 @@ declare function moveChildInContainer(ast: ExprNode, chainPath: AstPath, from: n
97
108
  /** Human label for a binary operator (words for logical, glyphs for relational). */
98
109
  declare const BINARY_LABEL: Record<BinaryOp, string>;
99
110
  declare const UNARY_LABEL: Record<UnaryOp, string>;
111
+ /** Plain-language name for an operator. ONE table, because it is wanted in three places that must
112
+ * agree: a pill's accessible label, the clause wizard's operator step, and the swap menu. The swap
113
+ * menu once printed the label and the raw source instead ("> >"), which is what a second table
114
+ * buys you. Never the glyph twice: this reads NEXT to `BINARY_LABEL`, so it must say something the
115
+ * glyph does not. */
116
+ declare const OP_WORD: Record<BinaryOp | UnaryOp, string>;
100
117
  declare const COMPARISON_OPS: BinaryOp[];
101
118
  declare const ARITHMETIC_OPS: BinaryOp[];
102
119
  /** Property types a comparison clause can be built on - what the clause wizard offers as a left-hand
@@ -481,4 +498,4 @@ interface ValueWizardOptions {
481
498
  /** Build the wizard UI into a fresh element (drive it via the host's popover). */
482
499
  declare function valueWizard(opts: ValueWizardOptions): HTMLElement;
483
500
 
484
- export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, type CatalogueEntry, EQUALITY_OPS, type EditCtx, type EditorEffect, type EffectsEditorHandle, type EffectsEditorOptions, type ExpressionEditorHandle, type ExpressionEditorOptions, type Filter, type FunctionTemplateSpec, type PreviewOptions, type TreeRow, UNARY_LABEL, type Validation, type ValueWizardOptions, type WizardSpec, type WizardStepSpec, type WizardValue, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
501
+ export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, type CatalogueEntry, EQUALITY_OPS, type EditCtx, type EditorEffect, type EffectsEditorHandle, type EffectsEditorOptions, type ExpressionEditorHandle, type ExpressionEditorOptions, type Filter, type FunctionTemplateSpec, OP_WORD, type PreviewOptions, type TreeRow, UNARY_LABEL, type Validation, type ValueWizardOptions, type WizardSpec, type WizardStepSpec, type WizardValue, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findChoicePeer, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
package/dist/index.d.ts CHANGED
@@ -34,14 +34,25 @@ declare function wrapInNotAt(ast: ExprNode, path: AstPath): ExprNode;
34
34
  /** Add a `not` if absent, strip it if present. */
35
35
  declare function toggleNotAt(ast: ExprNode, path: AstPath): ExprNode;
36
36
  /**
37
- * If the node at `path` is one operand of an equality comparison (`==` / `!=`)
38
- * whose OTHER operand is a property reference, return that property — so a string
39
- * literal can offer the property's enum values. Null otherwise.
37
+ * If the node at `path` is one operand of a COMPARISON whose other operand is a property
38
+ * reference, return that property - so a literal can offer that property's choices (an enum's
39
+ * values, a quality's stages).
40
+ *
41
+ * Every comparison counts, not just `==` / `!=`. Equality was enough while an enum was the only
42
+ * type with a closed value list, because an enum is never ordered; a QUALITY is ordered, and
43
+ * `@investigation >= "certain"` is the shape its type exists for. Restricting to equality left
44
+ * exactly that clause offering a free-text box where the ladder should be.
45
+ *
46
+ * Whether the peer HAS choices is not decided here - that is `choicesOf`'s job. This answers only
47
+ * "which property is this literal being compared against", so a number's `> 1` resolves its peer
48
+ * and then offers nothing, as before.
40
49
  */
41
- declare function findEnumPeer(ast: ExprNode, path: AstPath): {
50
+ declare function findChoicePeer(ast: ExprNode, path: AstPath): {
42
51
  scope: string;
43
52
  name: string;
44
53
  } | null;
54
+ /** @deprecated Renamed to {@link findChoicePeer} - it serves qualities as well as enums now. */
55
+ declare const findEnumPeer: typeof findChoicePeer;
45
56
  /**
46
57
  * DFS for the first unfilled slot in a template-inserted clause: an empty string
47
58
  * literal (a tag / value the author still has to set) or an unnamed flag delta.
@@ -97,6 +108,12 @@ declare function moveChildInContainer(ast: ExprNode, chainPath: AstPath, from: n
97
108
  /** Human label for a binary operator (words for logical, glyphs for relational). */
98
109
  declare const BINARY_LABEL: Record<BinaryOp, string>;
99
110
  declare const UNARY_LABEL: Record<UnaryOp, string>;
111
+ /** Plain-language name for an operator. ONE table, because it is wanted in three places that must
112
+ * agree: a pill's accessible label, the clause wizard's operator step, and the swap menu. The swap
113
+ * menu once printed the label and the raw source instead ("> >"), which is what a second table
114
+ * buys you. Never the glyph twice: this reads NEXT to `BINARY_LABEL`, so it must say something the
115
+ * glyph does not. */
116
+ declare const OP_WORD: Record<BinaryOp | UnaryOp, string>;
100
117
  declare const COMPARISON_OPS: BinaryOp[];
101
118
  declare const ARITHMETIC_OPS: BinaryOp[];
102
119
  /** Property types a comparison clause can be built on - what the clause wizard offers as a left-hand
@@ -481,4 +498,4 @@ interface ValueWizardOptions {
481
498
  /** Build the wizard UI into a fresh element (drive it via the host's popover). */
482
499
  declare function valueWizard(opts: ValueWizardOptions): HTMLElement;
483
500
 
484
- export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, type CatalogueEntry, EQUALITY_OPS, type EditCtx, type EditorEffect, type EffectsEditorHandle, type EffectsEditorOptions, type ExpressionEditorHandle, type ExpressionEditorOptions, type Filter, type FunctionTemplateSpec, type PreviewOptions, type TreeRow, UNARY_LABEL, type Validation, type ValueWizardOptions, type WizardSpec, type WizardStepSpec, type WizardValue, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
501
+ export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, type CatalogueEntry, EQUALITY_OPS, type EditCtx, type EditorEffect, type EffectsEditorHandle, type EffectsEditorOptions, type ExpressionEditorHandle, type ExpressionEditorOptions, type Filter, type FunctionTemplateSpec, OP_WORD, type PreviewOptions, type TreeRow, UNARY_LABEL, type Validation, type ValueWizardOptions, type WizardSpec, type WizardStepSpec, type WizardValue, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findChoicePeer, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
package/dist/index.js CHANGED
@@ -82,14 +82,15 @@ function toggleNotAt(ast, path) {
82
82
  }
83
83
  return wrapInNotAt(ast, path);
84
84
  }
85
- function findEnumPeer(ast, path) {
85
+ function findChoicePeer(ast, path) {
86
86
  const last = path[path.length - 1];
87
87
  if (last !== "left" && last !== "right") return null;
88
88
  const parent = getNodeAt(ast, path.slice(0, -1));
89
- if (parent?.kind !== "binary" || parent.op !== "==" && parent.op !== "!=") return null;
89
+ if (parent?.kind !== "binary" || !isComparisonOp(parent.op)) return null;
90
90
  const other = last === "left" ? parent.right : parent.left;
91
91
  return other.kind === "scopedvar" ? { scope: other.scope, name: other.name } : null;
92
92
  }
93
+ var findEnumPeer = findChoicePeer;
93
94
  function firstEmptyLeafPath(node, base = []) {
94
95
  switch (node.kind) {
95
96
  case "string":
@@ -218,6 +219,22 @@ var BINARY_LABEL = {
218
219
  "/": "\xF7"
219
220
  };
220
221
  var UNARY_LABEL = { not: "NOT", neg: "\u2212" };
222
+ var OP_WORD = {
223
+ "==": "equals",
224
+ "!=": "not equal to",
225
+ ">": "greater than",
226
+ ">=": "at least",
227
+ "<": "less than",
228
+ "<=": "at most",
229
+ and: "and",
230
+ or: "or",
231
+ "+": "plus",
232
+ "-": "minus",
233
+ "*": "times",
234
+ "/": "divided by",
235
+ not: "not",
236
+ neg: "negative"
237
+ };
221
238
  var COMPARISON_OPS = ["==", "!=", ">", ">=", "<", "<="];
222
239
  var ARITHMETIC_OPS = ["+", "-", "*", "/"];
223
240
  var COMPARABLE_TYPES = ["boolean", "number", "string", "enum", "quality"];
@@ -403,20 +420,6 @@ function pill(kind, label, onClick, opts = {}) {
403
420
  if (opts.path) b.dataset["exedPath"] = opts.path.join("/");
404
421
  return b;
405
422
  }
406
- var OP_ARIA = {
407
- "==": "equals",
408
- "!=": "not equal to",
409
- ">": "greater than",
410
- ">=": "at least",
411
- "<": "less than",
412
- "<=": "at most",
413
- "and": "and",
414
- "or": "or",
415
- "+": "plus",
416
- "-": "minus",
417
- "*": "times",
418
- "/": "divided by"
419
- };
420
423
  var issueText = (ctx, path) => {
421
424
  const list = issuesAt(ctx.byPath, path);
422
425
  return list.length ? list.map((i) => i.message).join("; ") : void 0;
@@ -470,7 +473,7 @@ function renderNode(node, path, ctx, parentOp, side) {
470
473
  }
471
474
  case "unary": {
472
475
  const row = el("span", "exed-unary");
473
- row.append(pill("op", UNARY_LABEL[node.op], () => ctx.apply(deleteOrUnwrapNot(ctx, path, node)), { title: "remove", aria: `${OP_ARIA[node.op] ?? node.op} (click to remove)` }));
476
+ row.append(pill("op", UNARY_LABEL[node.op], () => ctx.apply(deleteOrUnwrapNot(ctx, path, node)), { title: "remove", aria: `${OP_WORD[node.op]} (click to remove)` }));
474
477
  row.append(renderNode(node.operand, [...path, "operand"], ctx));
475
478
  return row;
476
479
  }
@@ -482,7 +485,7 @@ function renderNode(node, path, ctx, parentOp, side) {
482
485
  const swap = opSwapGroup(node.op);
483
486
  const opPill = pill("op", BINARY_LABEL[node.op], (b) => {
484
487
  if (swap) operatorEditor(ctx, path, node.op, swap, b);
485
- }, { title: swap ? "swap operator" : void 0, aria: OP_ARIA[node.op] ?? node.op });
488
+ }, { title: swap ? "swap operator" : void 0, aria: OP_WORD[node.op] });
486
489
  if (!swap) opPill.classList.add("exed-op-structural");
487
490
  row.append(opPill);
488
491
  row.append(renderNode(node.right, [...path, "right"], ctx, node.op, "right"));
@@ -559,7 +562,7 @@ function numberEditor(ctx, path, value, anchor) {
559
562
  }));
560
563
  }
561
564
  function stringEditor(ctx, path, node, anchor) {
562
- const peer = findEnumPeer(ctx.getAst(), path);
565
+ const peer = findChoicePeer(ctx.getAst(), path);
563
566
  const enumEntry = peer ? lookup(ctx.catalogue, peer.scope, peer.name) : null;
564
567
  const rootValueEnums = path.length === 0 && ctx.valueEnumValues?.length ? ctx.valueEnumValues : null;
565
568
  const peerChoices = choicesOf(enumEntry);
@@ -593,12 +596,14 @@ function operatorEditor(ctx, path, current, group, anchor) {
593
596
  const wrap = el("div", "exed-menu");
594
597
  wrap.append(el("div", "exed-menu-head", ["Operator"]));
595
598
  for (const op of group) {
596
- wrap.append(button(`exed-opt${op === current ? " sel" : ""}`, `${BINARY_LABEL[op]} ${op}`, () => {
599
+ const row = button(`exed-opt exed-opt-op${op === current ? " sel" : ""}`, "", () => {
597
600
  const node = ctx.getAst();
598
601
  const cur = setNodeAt(node, path, { ...getBinary(ctx, path), op });
599
602
  ctx.apply(cur);
600
603
  close();
601
- }));
604
+ });
605
+ row.append(el("span", "exed-opt-name", [BINARY_LABEL[op]]), el("span", "exed-opt-purpose", [OP_WORD[op]]));
606
+ wrap.append(row);
602
607
  }
603
608
  return wrap;
604
609
  });
@@ -714,17 +719,9 @@ function propertyPicker(ctx, opts) {
714
719
  }
715
720
 
716
721
  // src/clausewizard.ts
717
- var OP_WORD = {
718
- "==": "equals",
719
- "!=": "not equal to",
720
- ">": "greater than",
721
- ">=": "at least",
722
- "<": "less than",
723
- "<=": "at most"
724
- };
725
722
  var opButton = (o, onClick) => {
726
- const b = button("exed-opt", "", onClick);
727
- b.append(el("span", "exed-opt-name", [BINARY_LABEL[o]]), el("span", "exed-opt-purpose", [OP_WORD[o] ?? ""]));
723
+ const b = button("exed-opt exed-opt-op", "", onClick);
724
+ b.append(el("span", "exed-opt-name", [BINARY_LABEL[o]]), el("span", "exed-opt-purpose", [OP_WORD[o]]));
728
725
  return b;
729
726
  };
730
727
  function header(host, title, back, cancel) {
@@ -1746,6 +1743,6 @@ function renderEffectsPreview(effects, o) {
1746
1743
  return wrap;
1747
1744
  }
1748
1745
 
1749
- export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, EQUALITY_OPS, UNARY_LABEL, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
1746
+ export { ARITHMETIC_OPS, BINARY_LABEL, COMPARABLE_TYPES, COMPARISON_OPS, EQUALITY_OPS, OP_WORD, UNARY_LABEL, addArg, addChildToContainer, addEmit, addSet, astToTree, binary, boolLit, buildSubGroupClause, callNode, choicesOf, comparisonOpsFor, deleteAt, displayName, filterCatalogue, findChoicePeer, findEnumPeer, firstEmptyLeafPath, flagDelta, flipContainerOp, formatNumber, getNodeAt, groupByScope, initialValueFor, insertSiblingClauseAt, isComparisonOp, isPlaceholderForOp, isWrappedInNot, issuesAt, lookup, mountEffectsEditor, mountExpressionEditor, moveAt, moveChildInContainer, needsParens, notNode, numLit, opSwapGroup, pathKey, placeholderForOp, redirectDeleteForPlaceholderSibling, refOf, removeArgAt, removeAt, renderConditionPreview, renderEffectsPreview, rhsTypesFor, scopedVar, searchCatalogue, seedValueSrc, setArgAt, setNodeAt, strLit, toggleContainerNot, toggleNotAt, updateAt, validateSource, valueWizard, wrapInNotAt };
1750
1747
  //# sourceMappingURL=index.js.map
1751
1748
  //# sourceMappingURL=index.js.map