fsanyoto commited on
Commit
acf3b49
·
verified ·
1 Parent(s): 658edb3

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "805c8f2",
3
  "releases": [
4
  {
5
  "version": "v75",
 
1
  {
2
+ "current": "f121a20",
3
  "releases": [
4
  {
5
  "version": "v75",
VERSION CHANGED
@@ -1 +1 @@
1
- 805c8f2
 
1
+ f121a20
api/routes_sheet.py CHANGED
@@ -2021,8 +2021,9 @@ def refresh_sheet(workbook_id: str, session: Session = Depends(require_session))
2021
  nonlocal input_graph
2022
  nodes, _ = _fe_parts((binding.get("scope") or {}).get("filter"))
2023
  related_nodes, _ = _fe_parts((binding.get("related") or {}).get("filter"))
2024
- refs = [str((node.get("valueRef") or {}).get("ref") or "")
2025
- for node in sheet_mod.filter_cell_nodes([*nodes, *related_nodes])]
 
2026
  period = binding.get("period") or {}
2027
  if period.get("ref"):
2028
  refs.append(period["ref"])
 
2021
  nonlocal input_graph
2022
  nodes, _ = _fe_parts((binding.get("scope") or {}).get("filter"))
2023
  related_nodes, _ = _fe_parts((binding.get("related") or {}).get("filter"))
2024
+ refs = [str((node.get(key) or {}).get("ref") or "")
2025
+ for node in sheet_mod.filter_cell_nodes([*nodes, *related_nodes])
2026
+ for key in ("valueRef", "value2Ref") if key in node]
2027
  period = binding.get("period") or {}
2028
  if period.get("ref"):
2029
  refs.append(period["ref"])
platform/core/sheet_structure.py CHANGED
@@ -20,7 +20,7 @@ _BARE_SHEET = re.compile(r"[A-Za-z_][A-Za-z0-9_]{0,63}")
20
  _PREVIOUS = re.compile(r"[A-Za-z0-9_$]")
21
  _START = re.compile(r"[A-Za-z$']")
22
  _FUNCTION = re.compile(r"\s*\(")
23
- BINDING_REF_KEYS = frozenset({"ref", "valueRef", "cellRef", "endingRef"})
24
 
25
 
26
  def col_to_index(letters: str) -> int:
 
20
  _PREVIOUS = re.compile(r"[A-Za-z0-9_$]")
21
  _START = re.compile(r"[A-Za-z$']")
22
  _FUNCTION = re.compile(r"\s*\(")
23
+ BINDING_REF_KEYS = frozenset({"ref", "valueRef", "value2Ref", "cellRef", "endingRef"})
24
 
25
 
26
  def col_to_index(letters: str) -> int:
platform/modules/sheet.py CHANGED
@@ -681,7 +681,7 @@ def filter_cell_nodes(nodes):
681
  continue
682
  if isinstance(node.get("children"), list):
683
  yield from filter_cell_nodes(node["children"])
684
- elif "valueRef" in node:
685
  yield node
686
 
687
 
@@ -696,7 +696,10 @@ def resolve_filter_cells(nodes, read_cell):
696
  out.append(node)
697
  elif isinstance(node.get("children"), list):
698
  out.append({**node, "children": resolve_filter_cells(node["children"], read_cell)})
699
- elif "valueRef" in node:
 
 
 
700
  slot = node["valueRef"]
701
  ref = str(slot.get("ref") or "").strip() if isinstance(slot, dict) else ""
702
  if node.get("op") == "within" and node.get("rhs") is None:
@@ -709,13 +712,28 @@ def resolve_filter_cells(nodes, read_cell):
709
  or node.get("dateMode") in ANCHOR_VALUE_FREE or node.get("rhs") is not None):
710
  raise SheetRefusal("filter_cell_unreadable", ref or "(blank)",
711
  "this condition uses a window or another operand instead of a value.")
712
- value = read_cell(ref)
713
- if (not isinstance(value, (str, int, float, bool)) or str(value).strip() == ""
714
- or isinstance(value, float) and not math.isfinite(value)):
715
- raise SheetRefusal("filter_cell_unreadable", ref or "(blank)",
716
- "its value is blank or is not a single usable value.")
717
- text = str(value).lower() if isinstance(value, bool) else str(value)
 
 
 
 
718
  leaf = {**node, "value": text, "_cell_value_resolved": True}
 
 
 
 
 
 
 
 
 
 
 
719
  if node.get("op") in MULTI_VALUE_OPS:
720
  leaf["values"] = [text]
721
  out.append(leaf)
 
681
  continue
682
  if isinstance(node.get("children"), list):
683
  yield from filter_cell_nodes(node["children"])
684
+ elif "valueRef" in node or "value2Ref" in node:
685
  yield node
686
 
687
 
 
696
  out.append(node)
697
  elif isinstance(node.get("children"), list):
698
  out.append({**node, "children": resolve_filter_cells(node["children"], read_cell)})
699
+ elif "valueRef" in node or "value2Ref" in node:
700
+ if "valueRef" not in node:
701
+ # Only `between`'s upper bound comes from a cell; the lower bound stays typed.
702
+ node = {**node, "valueRef": {"ref": "", "_typed": True}}
703
  slot = node["valueRef"]
704
  ref = str(slot.get("ref") or "").strip() if isinstance(slot, dict) else ""
705
  if node.get("op") == "within" and node.get("rhs") is None:
 
712
  or node.get("dateMode") in ANCHOR_VALUE_FREE or node.get("rhs") is not None):
713
  raise SheetRefusal("filter_cell_unreadable", ref or "(blank)",
714
  "this condition uses a window or another operand instead of a value.")
715
+ def usable(at):
716
+ value = read_cell(at)
717
+ if (not isinstance(value, (str, int, float, bool)) or str(value).strip() == ""
718
+ or isinstance(value, float) and not math.isfinite(value)):
719
+ raise SheetRefusal("filter_cell_unreadable", at or "(blank)",
720
+ "its value is blank or is not a single usable value.")
721
+ return str(value).lower() if isinstance(value, bool) else str(value)
722
+
723
+ typed_low = isinstance(slot, dict) and slot.get("_typed") is True
724
+ text = str(node.get("value") or "") if typed_low else usable(ref)
725
  leaf = {**node, "value": text, "_cell_value_resolved": True}
726
+ if typed_low:
727
+ leaf.pop("valueRef")
728
+ if "value2Ref" in node:
729
+ # Hotfix 2026-09-25 (owner: "whenever it can refer to a value or other field, it
730
+ # should be able to refer to a Cell"): `between` takes its upper bound from a cell too.
731
+ slot2 = node["value2Ref"]
732
+ ref2 = str(slot2.get("ref") or "").strip() if isinstance(slot2, dict) else ""
733
+ if node.get("op") != "between":
734
+ raise SheetRefusal("filter_cell_unreadable", ref2 or "(blank)",
735
+ "only a between condition has a second value.")
736
+ leaf["value2"] = usable(ref2)
737
  if node.get("op") in MULTI_VALUE_OPS:
738
  leaf["values"] = [text]
739
  out.append(leaf)
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- c692564ee7775979e360cd962f6f00d37f3cb23d0a719bb1a0001fbfb37b5c61
 
1
+ 58391bc0a313931ed8cc8e5dcc382d009fe84feb9b3bdf70ff1edf18eb3b4de8
web/src/customer-grid/types.ts CHANGED
@@ -3380,6 +3380,8 @@ export interface FilterRule {
3380
  * when the binding resolves. `locked` keeps the reference fixed when the bound cell is copied.
3381
  */
3382
  valueRef?: { ref: string; locked?: boolean };
 
 
3383
  /** CG-9 — compare against another attribute instead of a literal. See FilterRhs. */
3384
  rhs?: FilterRhs;
3385
  /**
 
3380
  * when the binding resolves. `locked` keeps the reference fixed when the bound cell is copied.
3381
  */
3382
  valueRef?: { ref: string; locked?: boolean };
3383
+ /** `between` only: the upper bound read from a cell, beside `valueRef` for the lower. */
3384
+ value2Ref?: { ref: string; locked?: boolean };
3385
  /** CG-9 — compare against another attribute instead of a literal. See FilterRhs. */
3386
  rhs?: FilterRhs;
3387
  /**
web/src/filter-kit/FilterBuilderPanel.tsx CHANGED
@@ -696,22 +696,23 @@ export function readFilterCell(read: FilterCellReader, ref: string, type: FieldT
696
  return { ok: true, text: `Cell ${at} reads ${value}` };
697
  }
698
 
699
- /** The cell input a condition shows once it takes its value from a cell. */
700
- function CellRefValue({ rule, read, type, onPatch }: {
701
- rule: FilterRule; read: FilterCellReader; type: FieldType; onPatch: (p: Partial<FilterRule>) => void;
 
702
  }) {
703
- const ref = rule.valueRef?.ref ?? "";
704
- const check = readFilterCell(read, ref, type, rule.op === "within");
705
  return (
706
  <span className="cg-cond-val cg-cond-cell">
707
  <input
708
  type="text"
709
  className="cg-input"
710
- aria-label="Cell"
711
  placeholder="F7"
712
  value={ref}
713
  aria-invalid={ref.trim() !== "" && !check.ok}
714
- onChange={(e) => onPatch({ valueRef: { ...rule.valueRef, ref: e.target.value }, value: "" })}
715
  />
716
  <span className={"cg-cond-cellread" + (check.ok ? "" : " is-error")} role={check.ok ? "status" : "alert"}>
717
  {check.text}
@@ -720,6 +721,26 @@ function CellRefValue({ rule, read, type, onPatch }: {
720
  );
721
  }
722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
723
  /**
724
  * One nesting level: renders its nodes (leaves and nested groups) plus the
725
  * add-buttons. Recurses through GroupNode for children that are groups.
@@ -930,7 +951,7 @@ function LeafRow({
930
  // obvious edit destructive. The comparand goes, because a set question has no other side.
931
  if (MULTI_VALUE_OPS.has(op as FilterOp))
932
  return onRule({ ...rule, op: op as FilterOp, value: "", value2: undefined,
933
- rhs: undefined, dateWindow: undefined,
934
  values: filterValues(rule.values) });
935
  // Leaving the family drops the list rather than leaving it to ride along invisibly on a
936
  // condition that no longer reads it (`clean_filter_tree` emits `values` for these ops only).
@@ -940,9 +961,18 @@ function LeafRow({
940
  // comparand — "the top 10 compared with another field" is not a question.
941
  if (isRankOp(op as string))
942
  return onRule({ ...rule, op: op as FilterOp, value: rankDefault(op as FilterOp),
943
- value2: undefined, rhs: undefined, dateWindow: undefined, valueRef: undefined });
 
944
  if (VALUE_FREE_OPS.has(op as FilterOp))
945
- return onRule({ ...rule, op, value: "", value2: undefined, rhs: undefined, valueRef: undefined });
 
 
 
 
 
 
 
 
946
  if (op === "within")
947
  return onRule({ ...rule, op, value: "", value2: undefined, rhs: undefined,
948
  dateWindow: rule.dateWindow ?? DEFAULT_DATE_WINDOW });
@@ -1036,7 +1066,7 @@ function LeafRow({
1036
  const fieldAria = goneColumn ? `Field, deleted column ${rule.colId}` : "Field";
1037
 
1038
  return (
1039
- <span className={"cg-cond-row" + (isMeasure ? " is-measure" : "")
1040
  + (isCohort ? " is-cohort" : "")
1041
  + (rule.rhs != null ? " has-rhs" : "")}>
1042
  {/* ONE flat list (owner item 1). A measure used to sit under a "Measures (pick a
@@ -1125,9 +1155,10 @@ function LeafRow({
1125
  const mode = e.target.value;
1126
  if (mode === "cell")
1127
  return onRule({ ...rule, valueRef: { ref: rule.valueRef?.ref ?? "" }, rhs: undefined, value: "",
1128
- value2: undefined, dateMode: undefined });
 
1129
  // Leaving "a cell" drops the reference; the other modes then start from a plain rule.
1130
- const { valueRef: _cell, ...plain } = rule;
1131
  const patch = (p: Partial<FilterRule>) => onRule({ ...(plain as FilterRule), ...p });
1132
  if (mode === "stat")
1133
  return patch({ rhs: { kind: "stat", stat: "median" },
@@ -1167,7 +1198,7 @@ function LeafRow({
1167
  onWindow={(w) => patch({ dateWindow: w })}
1168
  kinds={WITHIN_KINDS.filter((kind) => kind !== "custom")}
1169
  />
1170
- <span className="cg-cond-join">up to the date in</span>
1171
  <CellRefValue rule={rule} read={readCell!} type={t} onPatch={patch} />
1172
  </>
1173
  ) : usingCell ? (
 
696
  return { ok: true, text: `Cell ${at} reads ${value}` };
697
  }
698
 
699
+ /** One cell input and, under it, what the cell reads now or why it cannot be used. */
700
+ function CellRefInput({ slot, label, read, type, asDate, onRef }: {
701
+ slot: { ref: string; locked?: boolean } | undefined; label: string; read: FilterCellReader;
702
+ type: FieldType; asDate: boolean; onRef: (ref: string) => void;
703
  }) {
704
+ const ref = slot?.ref ?? "";
705
+ const check = readFilterCell(read, ref, type, asDate);
706
  return (
707
  <span className="cg-cond-val cg-cond-cell">
708
  <input
709
  type="text"
710
  className="cg-input"
711
+ aria-label={label}
712
  placeholder="F7"
713
  value={ref}
714
  aria-invalid={ref.trim() !== "" && !check.ok}
715
+ onChange={(e) => onRef(e.target.value)}
716
  />
717
  <span className={"cg-cond-cellread" + (check.ok ? "" : " is-error")} role={check.ok ? "status" : "alert"}>
718
  {check.text}
 
721
  );
722
  }
723
 
724
+ /** The value a condition reads from a cell; a `between` reads both of its bounds from cells. */
725
+ function CellRefValue({ rule, read, type, onPatch }: {
726
+ rule: FilterRule; read: FilterCellReader; type: FieldType; onPatch: (p: Partial<FilterRule>) => void;
727
+ }) {
728
+ const first = (
729
+ <CellRefInput slot={rule.valueRef} label={rule.op === "between" ? "From cell" : "Cell"} read={read}
730
+ type={type} asDate={rule.op === "within"}
731
+ onRef={(ref) => onPatch({ valueRef: { ...rule.valueRef, ref }, value: "" })} />
732
+ );
733
+ if (rule.op !== "between") return first;
734
+ return (
735
+ <span className="cg-cond-between">
736
+ {first}
737
+ <span className="cg-cond-and">and</span>
738
+ <CellRefInput slot={rule.value2Ref} label="To cell" read={read} type={type} asDate={false}
739
+ onRef={(ref) => onPatch({ value2Ref: { ...rule.value2Ref, ref }, value2: "" })} />
740
+ </span>
741
+ );
742
+ }
743
+
744
  /**
745
  * One nesting level: renders its nodes (leaves and nested groups) plus the
746
  * add-buttons. Recurses through GroupNode for children that are groups.
 
951
  // obvious edit destructive. The comparand goes, because a set question has no other side.
952
  if (MULTI_VALUE_OPS.has(op as FilterOp))
953
  return onRule({ ...rule, op: op as FilterOp, value: "", value2: undefined,
954
+ rhs: undefined, dateWindow: undefined, value2Ref: undefined,
955
  values: filterValues(rule.values) });
956
  // Leaving the family drops the list rather than leaving it to ride along invisibly on a
957
  // condition that no longer reads it (`clean_filter_tree` emits `values` for these ops only).
 
961
  // comparand — "the top 10 compared with another field" is not a question.
962
  if (isRankOp(op as string))
963
  return onRule({ ...rule, op: op as FilterOp, value: rankDefault(op as FilterOp),
964
+ value2: undefined, rhs: undefined, dateWindow: undefined, valueRef: undefined,
965
+ value2Ref: undefined });
966
  if (VALUE_FREE_OPS.has(op as FilterOp))
967
+ return onRule({ ...rule, op, value: "", value2: undefined, rhs: undefined, valueRef: undefined,
968
+ value2Ref: undefined });
969
+ if (rule.valueRef && op === "between" && !rule.value2Ref)
970
+ return onRule({ ...rule, op: op as FilterOp, value2Ref: { ref: "" } });
971
+ if (rule.value2Ref && op !== "between") {
972
+ const { value2Ref: _upper, ...single } = rule;
973
+ return onRule({ ...(single as FilterRule), op: op as FilterOp,
974
+ ...(op === "within" ? { dateWindow: rule.dateWindow ?? DEFAULT_DATE_WINDOW } : {}) });
975
+ }
976
  if (op === "within")
977
  return onRule({ ...rule, op, value: "", value2: undefined, rhs: undefined,
978
  dateWindow: rule.dateWindow ?? DEFAULT_DATE_WINDOW });
 
1066
  const fieldAria = goneColumn ? `Field, deleted column ${rule.colId}` : "Field";
1067
 
1068
  return (
1069
+ <span className={"cg-cond-row" + (isMeasure ? " is-measure" : "") + (usingCell ? " is-cell" : "")
1070
  + (isCohort ? " is-cohort" : "")
1071
  + (rule.rhs != null ? " has-rhs" : "")}>
1072
  {/* ONE flat list (owner item 1). A measure used to sit under a "Measures (pick a
 
1155
  const mode = e.target.value;
1156
  if (mode === "cell")
1157
  return onRule({ ...rule, valueRef: { ref: rule.valueRef?.ref ?? "" }, rhs: undefined, value: "",
1158
+ value2: undefined, dateMode: undefined,
1159
+ ...(rule.op === "between" ? { value2Ref: { ref: rule.value2Ref?.ref ?? "" } } : {}) });
1160
  // Leaving "a cell" drops the reference; the other modes then start from a plain rule.
1161
+ const { valueRef: _cell, value2Ref: _cell2, ...plain } = rule;
1162
  const patch = (p: Partial<FilterRule>) => onRule({ ...(plain as FilterRule), ...p });
1163
  if (mode === "stat")
1164
  return patch({ rhs: { kind: "stat", stat: "median" },
 
1198
  onWindow={(w) => patch({ dateWindow: w })}
1199
  kinds={WITHIN_KINDS.filter((kind) => kind !== "custom")}
1200
  />
1201
+ <span className="cg-cond-join">through</span>
1202
  <CellRefValue rule={rule} read={readCell!} type={t} onPatch={patch} />
1203
  </>
1204
  ) : usingCell ? (
web/src/index.css CHANGED
@@ -2665,6 +2665,7 @@ body > .cg-overlay {
2665
  }
2666
  .cg-cond-cellread {
2667
  font-size: 12px;
 
2668
  color: var(--cg-muted);
2669
  }
2670
  .cg-cond-cellread.is-error {
@@ -2673,6 +2674,30 @@ body > .cg-overlay {
2673
  .cg-cond-join {
2674
  flex: 0 0 auto;
2675
  color: var(--cg-muted);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2676
  }
2677
  .cg-cond-and {
2678
  flex: 0 0 auto;
 
2665
  }
2666
  .cg-cond-cellread {
2667
  font-size: 12px;
2668
+ overflow-wrap: anywhere;
2669
  color: var(--cg-muted);
2670
  }
2671
  .cg-cond-cellread.is-error {
 
2674
  .cg-cond-join {
2675
  flex: 0 0 auto;
2676
  color: var(--cg-muted);
2677
+ white-space: nowrap;
2678
+ line-height: 30px;
2679
+ }
2680
+ /* A cell row wraps like a measure row: the reference and its readout take the room they need
2681
+ rather than squeezing the window picker or running past the dialog's edge. */
2682
+ .cg-cond-row.is-cell {
2683
+ flex-wrap: wrap;
2684
+ row-gap: 6px;
2685
+ align-items: flex-start;
2686
+ }
2687
+ .cg-cond-row.is-cell .cg-cond-cell {
2688
+ flex: 1 1 160px;
2689
+ min-width: 120px;
2690
+ }
2691
+ .cg-cond-row.is-cell .cg-cond-cell .cg-input {
2692
+ width: 100%;
2693
+ box-sizing: border-box;
2694
+ }
2695
+ .cg-cond-row.is-cell .cg-cond-between {
2696
+ flex: 1 1 340px;
2697
+ align-items: flex-start;
2698
+ }
2699
+ .cg-cond-row.is-cell .cg-cond-and {
2700
+ line-height: 30px;
2701
  }
2702
  .cg-cond-and {
2703
  flex: 0 0 auto;
web/src/sheet/BindingEditor.tsx CHANGED
@@ -71,7 +71,7 @@ import { shiftPeriodStart } from "./sheetState";
71
  import { useCellRefHighlight } from "./refHighlight";
72
  import { bindingStepMode, bindingStepValues, resolveEndingCell, seedBindingStep,
73
  bindingRefSlots, filterValueLeaves, keepCellFilterValues, resolveFilterCell, showCellFilterValues,
74
- updateFilterValueLeaf } from "./bindingRefs";
75
  import type { ReadBindingCell } from "./bindingRefs";
76
  import "../styles/wave57/binding-actions.css";
77
  import "../styles/wave58/sheet.css";
@@ -1529,13 +1529,14 @@ export default function BindingEditor({
1529
 
1530
  // The filter conditions that read a cell. The cell is chosen inside the filter itself ("a cell");
1531
  // When copied lists them because whether that reference moves is how this cell copies.
1532
- const cellLeaves = filterValueLeaves(tree).flatMap(({ node, indices }, index) => node.valueRef?.ref
1533
- ? [{ node, indices, index,
1534
- title: filterFields.find((candidate) => candidate.key === node.colId)?.label || node.colId }] : []);
 
1535
  // Every cell this panel names is outlined on the grid while the panel is open (refHighlight.ts).
1536
  useCellRefHighlight([
1537
- ...cellLeaves.map(({ node }) => node.valueRef?.ref ?? ""),
1538
- ...filterValueLeaves(relatedTree).map(({ node }) => node.valueRef?.ref ?? ""),
1539
  periodOn && (refOpen || ending === "cell") && periodRef
1540
  ? (!parsedEndingRef?.sheet && ending === "cell" && endingSheet
1541
  ? `'${endingSheet.replace(/'/g, "")}'!${periodRef.trim()}` : periodRef) : "",
@@ -2243,15 +2244,17 @@ export default function BindingEditor({
2243
  condition that reads a cell is how this cell moves when copied, so the cell
2244
  lives here, as ONE input: filled means "read this cell", blank means the
2245
  value typed in the filter. There is no separate source switch. */}
2246
- {cellLeaves.map(({ node, indices, title }) => (
2247
- <div key={indices.join(".")} className="sheet-step-driver">
2248
  <span>{node.op === "within"
2249
- ? `${title}: ${windowLabel(node.dateWindow).toLowerCase()} up to the date in cell ${node.valueRef!.ref}`
2250
- : `${title} reads cell ${node.valueRef!.ref}`}</span>
 
 
2251
  <label className="sheet-radio">
2252
- <input type="checkbox" checked={node.valueRef!.locked === true}
2253
  onChange={(e) => setTree(updateFilterValueLeaf(tree, indices, (leaf) => ({ ...leaf,
2254
- valueRef: { ...leaf.valueRef!, locked: e.target.checked } })))} />
2255
  <span>Keep this cell when copied</span>
2256
  </label>
2257
  </div>
 
71
  import { useCellRefHighlight } from "./refHighlight";
72
  import { bindingStepMode, bindingStepValues, resolveEndingCell, seedBindingStep,
73
  bindingRefSlots, filterValueLeaves, keepCellFilterValues, resolveFilterCell, showCellFilterValues,
74
+ updateFilterValueLeaf, FILTER_REF_KEYS } from "./bindingRefs";
75
  import type { ReadBindingCell } from "./bindingRefs";
76
  import "../styles/wave57/binding-actions.css";
77
  import "../styles/wave58/sheet.css";
 
1529
 
1530
  // The filter conditions that read a cell. The cell is chosen inside the filter itself ("a cell");
1531
  // When copied lists them because whether that reference moves is how this cell copies.
1532
+ const cellLeaves = filterValueLeaves(tree).flatMap(({ node, indices }, index) =>
1533
+ FILTER_REF_KEYS.flatMap((refKey) => node[refKey]?.ref
1534
+ ? [{ node, indices, index, refKey, ref: node[refKey]!.ref, locked: node[refKey]!.locked === true,
1535
+ title: filterFields.find((candidate) => candidate.key === node.colId)?.label || node.colId }] : []));
1536
  // Every cell this panel names is outlined on the grid while the panel is open (refHighlight.ts).
1537
  useCellRefHighlight([
1538
+ ...cellLeaves.map(({ ref }) => ref),
1539
+ ...filterValueLeaves(relatedTree).flatMap(({ node }) => FILTER_REF_KEYS.map((refKey) => node[refKey]?.ref ?? "")),
1540
  periodOn && (refOpen || ending === "cell") && periodRef
1541
  ? (!parsedEndingRef?.sheet && ending === "cell" && endingSheet
1542
  ? `'${endingSheet.replace(/'/g, "")}'!${periodRef.trim()}` : periodRef) : "",
 
2244
  condition that reads a cell is how this cell moves when copied, so the cell
2245
  lives here, as ONE input: filled means "read this cell", blank means the
2246
  value typed in the filter. There is no separate source switch. */}
2247
+ {cellLeaves.map(({ node, indices, title, refKey, ref, locked }) => (
2248
+ <div key={`${indices.join(".")}.${refKey}`} className="sheet-step-driver">
2249
  <span>{node.op === "within"
2250
+ ? `${title}: ${windowLabel(node.dateWindow).toLowerCase()} up to the date in cell ${ref}`
2251
+ : node.op === "between"
2252
+ ? `${title} ${refKey === "valueRef" ? "from" : "to"} cell ${ref}`
2253
+ : `${title} reads cell ${ref}`}</span>
2254
  <label className="sheet-radio">
2255
+ <input type="checkbox" checked={locked}
2256
  onChange={(e) => setTree(updateFilterValueLeaf(tree, indices, (leaf) => ({ ...leaf,
2257
+ [refKey]: { ...leaf[refKey]!, locked: e.target.checked } })))} />
2258
  <span>Keep this cell when copied</span>
2259
  </label>
2260
  </div>
web/src/sheet/bindingRefs.ts CHANGED
@@ -127,7 +127,9 @@ interface PathRefSlotSpec {
127
 
128
  type RefSlotSpec = PathRefSlotSpec | { readonly kind: "filter"; readonly key: string };
129
 
130
- export type CellFilterRule = FilterRule & { valueRef?: BindingFilterValueRef };
 
 
131
 
132
  /** Indices follow nodes/children arrays, independently of the fixed object-path slot kind. */
133
  export const filterValueLeaves = (tree: FilterTree): { node: CellFilterRule; indices: number[] }[] => {
@@ -168,7 +170,9 @@ const mapFilterLeaves = (tree: FilterTree, change: (node: CellFilterRule) => Cel
168
  export const showCellFilterValues = (tree: FilterTree, read?: ReadBindingCell): FilterTree => !read ? tree
169
  : mapFilterLeaves(tree, (node) => {
170
  const got = node.valueRef?.ref ? read(node.valueRef.ref) : null;
171
- return got && got.value !== "" ? { ...node, value: got.value } : node;
 
 
172
  });
173
 
174
  /**
@@ -178,15 +182,22 @@ export const showCellFilterValues = (tree: FilterTree, read?: ReadBindingCell):
178
  */
179
  export const keepCellFilterValues = (tree: FilterTree, read?: ReadBindingCell): FilterTree => !read ? tree
180
  : mapFilterLeaves(tree, (node) => {
181
- if (!node.valueRef?.ref) return node;
182
- const shown = read(node.valueRef.ref)?.value ?? "";
183
- const typed = typeof node.value === "string" ? node.value : node.value == null ? "" : String(node.value);
184
- if (typed === "" || typed === shown) {
185
- const { value: _shown, ...linked } = node;
186
- return linked as CellFilterRule;
 
 
 
 
 
 
 
 
187
  }
188
- const { valueRef: _link, ...own } = node;
189
- return own as CellFilterRule;
190
  });
191
 
192
  /**
@@ -217,6 +228,8 @@ const REF_SLOTS: readonly RefSlotSpec[] = [
217
  export interface BindingRefSlot {
218
  readonly kind: "path" | "filter";
219
  readonly indices?: readonly number[];
 
 
220
  readonly key: string;
221
  readonly path: readonly string[];
222
  /** The stored text, trimmed exactly as `types.ts::bindingPeriod` trims it. */
@@ -279,7 +292,7 @@ const walkFilterNodes = (
279
  }
280
  if (String(record.colId ?? "") !== field) return node;
281
  // A cell operand moves through the reference slot, never through its last preview value.
282
- if ("valueRef" in record) return node;
283
  found = true;
284
  const presence = mode ? mode === "presence" : record.op === "isEmpty" || record.op === "isNotEmpty";
285
  const member = mode ? mode === "member" : Array.isArray(record.values) && record.values.length === 1;
@@ -378,10 +391,13 @@ export const bindingRefSlots = (binding: unknown): BindingRefSlot[] => {
378
  const tree = asRecord(asRecord(record.scope)?.filter);
379
  if (!tree || !Array.isArray(tree.nodes)) continue;
380
  for (const { node, indices } of filterValueLeaves(tree as unknown as FilterTree)) {
381
- if (!("valueRef" in node)) continue;
382
- const text = typeof node.valueRef?.ref === "string" ? node.valueRef.ref.trim() : "";
383
- out.push({ kind: "filter", key: `${spec.key}.${indices.join(".")}.valueRef`,
384
- path: [], indices, text, parsed: parseRef(text), pinned: node.valueRef?.locked === true });
 
 
 
385
  }
386
  continue;
387
  }
@@ -437,8 +453,9 @@ export const shiftBindingRefs = (
437
  if (slot.kind === "filter") {
438
  const scope = asRecord(out.scope)!;
439
  const tree = scope.filter as FilterTree;
 
440
  out = { ...out, scope: { ...scope, filter: updateFilterValueLeaf(tree, slot.indices!,
441
- (node) => ({ ...node, valueRef: { ...node.valueRef, ref: next } })) } };
442
  } else out = writeAt(out, slot.path, next);
443
  moved.push(slot.key);
444
  }
@@ -473,8 +490,9 @@ export const structureBindingRefs = (
473
  if (slot.kind === "filter") {
474
  const scope = asRecord(out.scope)!;
475
  const tree = scope.filter as FilterTree;
 
476
  out = { ...out, scope: { ...scope, filter: updateFilterValueLeaf(tree, slot.indices!,
477
- (node) => ({ ...node, valueRef: { ...node.valueRef, ref: next } })) } };
478
  } else out = writeAt(out, slot.path, next);
479
  moved.push(slot.key);
480
  }
 
127
 
128
  type RefSlotSpec = PathRefSlotSpec | { readonly kind: "filter"; readonly key: string };
129
 
130
+ export type CellFilterRule = FilterRule & { valueRef?: BindingFilterValueRef; value2Ref?: BindingFilterValueRef };
131
+ /** Both cell slots a filter leaf can carry: the value, and `between`'s upper bound. */
132
+ export const FILTER_REF_KEYS = ["valueRef", "value2Ref"] as const;
133
 
134
  /** Indices follow nodes/children arrays, independently of the fixed object-path slot kind. */
135
  export const filterValueLeaves = (tree: FilterTree): { node: CellFilterRule; indices: number[] }[] => {
 
170
  export const showCellFilterValues = (tree: FilterTree, read?: ReadBindingCell): FilterTree => !read ? tree
171
  : mapFilterLeaves(tree, (node) => {
172
  const got = node.valueRef?.ref ? read(node.valueRef.ref) : null;
173
+ const got2 = node.value2Ref?.ref ? read(node.value2Ref.ref) : null;
174
+ const shown = got && got.value !== "" ? { ...node, value: got.value } : node;
175
+ return got2 && got2.value !== "" ? { ...shown, value2: got2.value } : shown;
176
  });
177
 
178
  /**
 
182
  */
183
  export const keepCellFilterValues = (tree: FilterTree, read?: ReadBindingCell): FilterTree => !read ? tree
184
  : mapFilterLeaves(tree, (node) => {
185
+ let out = node;
186
+ for (const [refKey, valueKey] of [["valueRef", "value"], ["value2Ref", "value2"]] as const) {
187
+ const ref = out[refKey]?.ref;
188
+ if (!ref) continue;
189
+ const shown = read(ref)?.value ?? "";
190
+ const raw = out[valueKey];
191
+ const typed = typeof raw === "string" ? raw : raw == null ? "" : String(raw);
192
+ if (typed === "" || typed === shown) {
193
+ const { [valueKey]: _shown, ...linked } = out;
194
+ out = linked as CellFilterRule;
195
+ } else {
196
+ const { [refKey]: _link, ...own } = out;
197
+ out = own as CellFilterRule;
198
+ }
199
  }
200
+ return out;
 
201
  });
202
 
203
  /**
 
228
  export interface BindingRefSlot {
229
  readonly kind: "path" | "filter";
230
  readonly indices?: readonly number[];
231
+ /** A filter slot's key on its leaf: the value, or `between`'s upper bound. */
232
+ readonly refKey?: "valueRef" | "value2Ref";
233
  readonly key: string;
234
  readonly path: readonly string[];
235
  /** The stored text, trimmed exactly as `types.ts::bindingPeriod` trims it. */
 
292
  }
293
  if (String(record.colId ?? "") !== field) return node;
294
  // A cell operand moves through the reference slot, never through its last preview value.
295
+ if ("valueRef" in record || "value2Ref" in record) return node;
296
  found = true;
297
  const presence = mode ? mode === "presence" : record.op === "isEmpty" || record.op === "isNotEmpty";
298
  const member = mode ? mode === "member" : Array.isArray(record.values) && record.values.length === 1;
 
391
  const tree = asRecord(asRecord(record.scope)?.filter);
392
  if (!tree || !Array.isArray(tree.nodes)) continue;
393
  for (const { node, indices } of filterValueLeaves(tree as unknown as FilterTree)) {
394
+ for (const refKey of FILTER_REF_KEYS) {
395
+ if (!(refKey in node)) continue;
396
+ const slot = node[refKey];
397
+ const text = typeof slot?.ref === "string" ? slot.ref.trim() : "";
398
+ out.push({ kind: "filter", key: `${spec.key}.${indices.join(".")}.${refKey}`, refKey,
399
+ path: [], indices, text, parsed: parseRef(text), pinned: slot?.locked === true });
400
+ }
401
  }
402
  continue;
403
  }
 
453
  if (slot.kind === "filter") {
454
  const scope = asRecord(out.scope)!;
455
  const tree = scope.filter as FilterTree;
456
+ const refKey = slot.refKey ?? "valueRef";
457
  out = { ...out, scope: { ...scope, filter: updateFilterValueLeaf(tree, slot.indices!,
458
+ (node) => ({ ...node, [refKey]: { ...node[refKey], ref: next } })) } };
459
  } else out = writeAt(out, slot.path, next);
460
  moved.push(slot.key);
461
  }
 
490
  if (slot.kind === "filter") {
491
  const scope = asRecord(out.scope)!;
492
  const tree = scope.filter as FilterTree;
493
+ const refKey = slot.refKey ?? "valueRef";
494
  out = { ...out, scope: { ...scope, filter: updateFilterValueLeaf(tree, slot.indices!,
495
+ (node) => ({ ...node, [refKey]: { ...node[refKey], ref: next } })) } };
496
  } else out = writeAt(out, slot.path, next);
497
  moved.push(slot.key);
498
  }