@bicharts/chart-host 0.5.59 → 0.5.60

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.mjs CHANGED
@@ -651,6 +651,65 @@ function qualifyFailureFallsOpen(viaGenerate) {
651
651
  return viaGenerate === true;
652
652
  }
653
653
 
654
+ // src/qualifyFilter.ts
655
+ function normalizeFilterTerm(raw) {
656
+ if (typeof raw !== "string" || raw === "") return "";
657
+ return raw.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
658
+ }
659
+ var FILTER_MIN_TERM_CHARS = 2;
660
+ function startsAWord(name, t) {
661
+ for (let i = name.indexOf(t); i >= 0; i = name.indexOf(t, i + 1)) {
662
+ if (i === 0) return true;
663
+ const prev = name.charCodeAt(i - 1);
664
+ const alnum = prev >= 97 && prev <= 122 || prev >= 48 && prev <= 57;
665
+ if (!alnum) return true;
666
+ }
667
+ return false;
668
+ }
669
+ function filterQualifyRows(rows, term, read) {
670
+ const all = Array.isArray(rows) ? rows.slice() : [];
671
+ const t = normalizeFilterTerm(term);
672
+ if (t.length < FILTER_MIN_TERM_CHARS) return { rows: all, tier: "all", term: "" };
673
+ const atWordStart = [];
674
+ const midWord = [];
675
+ const byDesc = [];
676
+ for (const row of all) {
677
+ const f = read(row);
678
+ const name = normalizeFilterTerm(f.name);
679
+ if (name === "") continue;
680
+ if (name.indexOf(t) >= 0) {
681
+ (startsAWord(name, t) ? atWordStart : midWord).push(row);
682
+ continue;
683
+ }
684
+ if (normalizeFilterTerm(f.description).indexOf(t) >= 0) byDesc.push(row);
685
+ }
686
+ if (atWordStart.length > 0) return { rows: atWordStart, tier: "name", term: t };
687
+ if (midWord.length > 0) return { rows: midWord, tier: "namePart", term: t };
688
+ if (byDesc.length > 0) return { rows: byDesc, tier: "desc", term: t };
689
+ return { rows: [], tier: "none", term: t };
690
+ }
691
+ var readQualifyChartRow = (r) => ({ name: r.name, description: r.description });
692
+ var readQualifyRefusalRow = (r) => ({ name: r.name, description: r.reason });
693
+ var FILTER_ROW_PX = 32;
694
+ var FILTER_MIN_WIDTH_PX = 420;
695
+ var FILTER_MIN_HEIGHT_PX = 300;
696
+ function filterFitsChooser(width, height) {
697
+ return Number.isFinite(width) && Number.isFinite(height) && width >= FILTER_MIN_WIDTH_PX && height >= FILTER_MIN_HEIGHT_PX;
698
+ }
699
+ function listNeedsFilter(scrollHeight, clientHeight) {
700
+ if (!Number.isFinite(scrollHeight) || !Number.isFinite(clientHeight)) return false;
701
+ return scrollHeight > clientHeight - FILTER_ROW_PX;
702
+ }
703
+ function qualifyFilterGate(i) {
704
+ if (!filterFitsChooser(i.cardWidth, i.cardHeight)) return { show: false, why: "too-small" };
705
+ if (!listNeedsFilter(i.scrollHeight, i.clientHeight)) return { show: false, why: "no-overflow" };
706
+ return { show: true, why: "shown" };
707
+ }
708
+ function inlineFilterGate(rowCount) {
709
+ return rowCount >= INLINE_FILTER_MIN_ROWS ? { show: true, why: "shown" } : { show: false, why: "no-overflow" };
710
+ }
711
+ var INLINE_FILTER_MIN_ROWS = 8;
712
+
654
713
  // src/selectionCard.ts
655
714
  var SYNTHETIC_PREFIX = "__";
656
715
  var NUMERIC_DATATYPE = /int|double|decimal|single|float|number|currency|money/i;
@@ -893,10 +952,15 @@ export {
893
952
  CONTAINER_SLOT_XF_CLEAR,
894
953
  DIM_OPACITY_DEFAULT,
895
954
  DIM_OPACITY_VAR,
955
+ FILTER_MIN_HEIGHT_PX,
956
+ FILTER_MIN_TERM_CHARS,
957
+ FILTER_MIN_WIDTH_PX,
958
+ FILTER_ROW_PX,
896
959
  FLIP_MODE_DEFAULT,
897
960
  GEO_POINT_PRECISIONS,
898
961
  HOST_CONTAINER_CLASS,
899
962
  HOST_CONTRACT_VERSION,
963
+ INLINE_FILTER_MIN_ROWS,
900
964
  LEGEND_MARK_CLASS,
901
965
  LIFT_SELECTED_CLASS,
902
966
  MARK_CLASS,
@@ -927,28 +991,36 @@ export {
927
991
  createMarkResolver,
928
992
  ensureCrossfilterHitTargets,
929
993
  explainRenderFailure,
994
+ filterFitsChooser,
995
+ filterQualifyRows,
930
996
  geoAssetFor,
931
997
  geoFromCache,
932
998
  hasRefusalsToShow,
933
999
  hitBandFlag,
1000
+ inlineFilterGate,
934
1001
  isBlankRender,
935
1002
  launchFavorStyle,
936
1003
  launchGenerates,
1004
+ listNeedsFilter,
937
1005
  loadGeo,
938
1006
  newQualifyGroupState,
939
1007
  newQualifyRefusalGroupState,
940
1008
  noopViewStateProvider,
941
1009
  normaliseAggregation,
1010
+ normalizeFilterTerm,
942
1011
  orderRefusalsForDisplay,
943
1012
  periodTickSuppressesFeedback,
944
1013
  planTrivialChart,
945
1014
  qualifyAuto,
946
1015
  qualifyCancel,
947
1016
  qualifyFailureFallsOpen,
1017
+ qualifyFilterGate,
948
1018
  qualifyGroupHeadingFor,
949
1019
  qualifyPick,
950
1020
  qualifyRefusalHeadingFor,
951
1021
  rasterizeSvgToPngDataUrl,
1022
+ readQualifyChartRow,
1023
+ readQualifyRefusalRow,
952
1024
  refusalIsSelectable,
953
1025
  registerCityTable,
954
1026
  registerGeo,
@@ -13,6 +13,7 @@ export { shouldReview, buildReviewWire, bareBase64, actionFor, type ReviewGate,
13
13
  export { askApplyImprovements, type ReviewDialogOptions, type ReviewDialogText } from "./reviewDialog";
14
14
  export { qualifyGroupHeadingFor, newQualifyGroupState, type QualifyGroupRow, type QualifyGroupState, type QualifyGroupHeading, orderRefusalsForDisplay, refusalIsSelectable, hasRefusalsToShow, qualifyRefusalHeadingFor, newQualifyRefusalGroupState, type QualifyRefusalRow, type QualifyRefusalGroupState, type QualifyRefusalHeading, } from "./qualifyGroups";
15
15
  export { qualifyPick, qualifyAuto, qualifyCancel, launchGenerates, launchFavorStyle, chooserFitsViewport, shouldOpenChooserOnGenerate, shouldOpenInlineChooserOnGenerate, canConfirmLaunch, confirmLaunch, qualifyFailureFallsOpen, CHOOSER_MIN_WIDTH_PX, CHOOSER_MIN_HEIGHT_PX, type QualifyLaunchOutcome, type ChooserGateInput, } from "./qualifyLaunch";
16
+ export { normalizeFilterTerm, filterQualifyRows, readQualifyChartRow, readQualifyRefusalRow, filterFitsChooser, listNeedsFilter, qualifyFilterGate, inlineFilterGate, FILTER_MIN_TERM_CHARS, FILTER_ROW_PX, FILTER_MIN_WIDTH_PX, FILTER_MIN_HEIGHT_PX, INLINE_FILTER_MIN_ROWS, type QualifyFilterTier, type QualifyFilterResult, type QualifyFilterRead, type QualifyFilterGateReason, type QualifyFilterGateInput, } from "./qualifyFilter";
16
17
  export { computeSelectionCard, normaliseAggregation, type SelectionCardModel, type SelectionCardLine, type SelectionCardOptions, } from "./selectionCard";
17
18
  export { ensureCrossfilterHitTargets, type HitTargetReport } from "./hitTargets";
18
19
  export { censusMarks, isBlankRender, blankRenderFlag, type MarkCensus, type BlankVerdictInput } from "./blankRender";
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The comparison form of a term or a field.
3
+ *
4
+ * Accent folding is not decoration. The catalogue is English, but the reader's keyboard need not
5
+ * be, and a "Sankey" typed through a dead key has to match the same row a plain one does. NFD
6
+ * splits a composed character into base + combining marks and the range strip removes the marks,
7
+ * which is the whole of it - no transliteration, no stemming, nothing that could make two
8
+ * different chart names collide.
9
+ *
10
+ * Whitespace is collapsed rather than stripped: "bar chart" and "bar chart" are the same query,
11
+ * but "barchart" is deliberately NOT one. A reader who omits the space is asking for something we
12
+ * do not have a name for, and silently succeeding there would make the failures inexplicable.
13
+ */
14
+ export declare function normalizeFilterTerm(raw: string | null | undefined): string;
15
+ /**
16
+ * THE SHORTEST TERM THAT FILTERS. One character matches most of a 108-row catalogue, so the
17
+ * list would flicker through a near-identity pass and teach the reader nothing; below this the
18
+ * list is returned untouched and the host hides its counter.
19
+ */
20
+ export declare const FILTER_MIN_TERM_CHARS = 2;
21
+ /**
22
+ * WHICH TIER ANSWERED - the host needs this, not just the rows.
23
+ *
24
+ * "all" - no term (or too short). The rows are the input, unfiltered.
25
+ * "name" - the term starts a WORD in at least one name. Every lower tier is suppressed.
26
+ * "namePart" - it appears mid-word in a name, and nowhere at a word start.
27
+ * "desc" - no name matched at all, so the description fallback answered. THE HOST SAYS SO.
28
+ * "none" - nothing matched anywhere.
29
+ *
30
+ * A HOST ONLY HAS TO ANNOUNCE "desc". The first two are both name matches and need no
31
+ * explanation; the third is the one a reader would otherwise read as broken matching.
32
+ */
33
+ export type QualifyFilterTier = "all" | "name" | "namePart" | "desc" | "none";
34
+ export interface QualifyFilterResult<T> {
35
+ rows: T[];
36
+ tier: QualifyFilterTier;
37
+ /** The normalized term actually applied. Empty when the tier is "all". */
38
+ term: string;
39
+ }
40
+ /** How to read a row's two searchable fields. Kept as a callback because the fitting rows and
41
+ * the refused rows carry different field names and must not need two copies of this logic. */
42
+ export type QualifyFilterRead<T> = (row: T) => {
43
+ name?: string | null;
44
+ description?: string | null;
45
+ };
46
+ /**
47
+ * Filter `rows` by `term`, PRESERVING INPUT ORDER EXACTLY in every branch.
48
+ *
49
+ * THREE TIERS, AND THE FIRST NON-EMPTY ONE WINS OUTRIGHT. That single rule is what makes this
50
+ * feel like a name filter instead of a search box:
51
+ *
52
+ * 1. the term starts a WORD in the name - "gan" -> Gantt chart, and NOT Organization chart
53
+ * 2. it appears mid-word in the name - "eth" -> Choropleth, which tier 1 cannot reach
54
+ * 3. it appears in the description - "hierarchy" -> Organization chart
55
+ *
56
+ * Typing "time" returns `Time series plot` and NOT the dozen types whose descriptions happen to
57
+ * say "over time", which is what a flat name-or-description match produces and which reads,
58
+ * correctly, as broken.
59
+ *
60
+ * The description tier exists so a reader who types a word we carry in no NAME still finds
61
+ * something rather than an empty list, and it fires only when both name tiers are empty. When it
62
+ * fires the host has to say so ("No name matches - showing types whose description mentions
63
+ * 'stacked'"): an unannounced fallback is indistinguishable from bad matching. The two NAME tiers
64
+ * need no announcement - both are the reader's own word, found where they expected it.
65
+ *
66
+ * A row with no name is dropped from every tier. It cannot be labelled, so it cannot be chosen,
67
+ * and the hosts already drop it at render time.
68
+ */
69
+ export declare function filterQualifyRows<T>(rows: readonly T[] | null | undefined, term: string | null | undefined, read: QualifyFilterRead<T>): QualifyFilterResult<T>;
70
+ /** Reads a fitting row (`charts[]`): `name` / `description`. */
71
+ export declare const readQualifyChartRow: QualifyFilterRead<{
72
+ name?: string | null;
73
+ description?: string | null;
74
+ }>;
75
+ /**
76
+ * Reads a REFUSED row (`refused[]`). Its second field is the gate's SENTENCE rather than a
77
+ * description, and searching it is right for the same reason the tier exists: the sentence names
78
+ * the reader's own columns, so "region" finding every type refused over Region is a useful
79
+ * answer to "why isn't my chart here" - which is the only question that section is open to ask.
80
+ */
81
+ export declare const readQualifyRefusalRow: QualifyFilterRead<{
82
+ name?: string | null;
83
+ reason?: string | null;
84
+ }>;
85
+ /**
86
+ * THE HEIGHT THE FILTER ROW COSTS THE LIST - the row plus its 6px bottom margin.
87
+ *
88
+ * Measured, not assumed: 32px, and constant across all 195 tile sizes in the sweep below (the
89
+ * row is a flex line around a 0.85em input, so it does not reflow with the card).
90
+ */
91
+ export declare const FILTER_ROW_PX = 32;
92
+ /**
93
+ * THE SMALLEST CARD THE FILTER BOX IS USABLE IN - measured 2026-09-03, and NOT arithmetic off
94
+ * `CHOOSER_MIN_*`.
95
+ *
96
+ * The chooser's own floor (400 x 240) was measured with three pinned elements. The filter row is
97
+ * a FOURTH, in a card that clips, so the old envelope does not survive the addition and could not
98
+ * be adjusted by adding 32px to it - the coupling between the two dimensions moves too.
99
+ *
100
+ * Same harness as the 2026-09-01 chooser sweep, re-run over 195 sizes with the row present. The
101
+ * run reproduces the chooser's published coupling exactly when the row is hidden (320-340 wide
102
+ * needs 280 tall, 360-380 needs 260, 400+ needs 220), which is what says the harness is measuring
103
+ * the same card and not a different one.
104
+ *
105
+ * ONE CRITERION IS TIGHTER, and it is the reason this is a separate floor rather than a bigger
106
+ * version of the old one: the chooser sweep asked for TWO visible list rows, this asks for
107
+ * THREE. A filter that leaves two rows visible did not earn the height it cost.
108
+ *
109
+ * Measured envelope with the row present:
110
+ *
111
+ * 320-340 wide -> 380 tall 400 wide -> 300 tall 420+ wide -> 280 tall
112
+ *
113
+ * 420 x 300 is that envelope at its cheapest width, with one sweep step (20px) of margin on the
114
+ * height for the reason `CHOOSER_MIN_*` states: the measurement used one font stack and one
115
+ * string, every host localizes the title, and a longer translation wraps sooner than the sample.
116
+ *
117
+ * ERRING HIGH IS THE CHEAP DIRECTION, exactly as it is for the chooser. Below this floor the
118
+ * reader gets the chooser they have today, unchanged; above it wrongly, they get a clipped
119
+ * control in a card that cannot scroll to reveal it.
120
+ */
121
+ export declare const FILTER_MIN_WIDTH_PX = 420;
122
+ export declare const FILTER_MIN_HEIGHT_PX = 300;
123
+ /**
124
+ * Condition A: can this card afford the box at all?
125
+ *
126
+ * MEASURE THE REAL SURFACE - the card as drawn, never a viewport the host reports outward. The
127
+ * chooser's gate says the same thing for the same reason: where an author can state a viewport
128
+ * for generation purposes, that stated size describes a tile that does not exist yet.
129
+ */
130
+ export declare function filterFitsChooser(width: number, height: number): boolean;
131
+ /**
132
+ * Condition B: is the list long enough to be worth filtering?
133
+ *
134
+ * A filter box over four rows is clutter that spends pinned height for nothing, so the box
135
+ * appears only when the list actually scrolls.
136
+ *
137
+ * THE `- FILTER_ROW_PX` IS LOAD-BEARING, and leaving it out is how the naive version ships a
138
+ * flicker loop: inserting the box shrinks the list, which can turn a list that did not overflow
139
+ * into one that does, which would remove the box, which restores the overflow. Asking whether the
140
+ * content exceeds the height the list WOULD have is a single stable pass, because `scrollHeight`
141
+ * is content height and does not change when the container shrinks.
142
+ */
143
+ export declare function listNeedsFilter(scrollHeight: number, clientHeight: number): boolean;
144
+ /** Why the box is or is not on screen - logged once per open, so the floor can be judged against
145
+ * real tiles rather than only against the sweep. */
146
+ export type QualifyFilterGateReason = "shown" | "too-small" | "no-overflow";
147
+ export interface QualifyFilterGateInput {
148
+ /** Real drawn width of the CARD, in CSS pixels. */
149
+ cardWidth: number;
150
+ /** Real drawn height of the card. */
151
+ cardHeight: number;
152
+ /** The list's content height and its current viewport height. */
153
+ scrollHeight: number;
154
+ clientHeight: number;
155
+ }
156
+ /**
157
+ * Both conditions, and the reason - which the host logs whichever way it comes out.
158
+ *
159
+ * DECIDED ONCE PER OPEN. Neither host re-asks this while the dialog is up: not when the filter
160
+ * hides rows and the list stops overflowing (a control that vanishes mid-typing is worse than one
161
+ * that is briefly unnecessary), and not on resize (a dialog whose controls appear and disappear
162
+ * under a window drag reads as broken).
163
+ */
164
+ export declare function qualifyFilterGate(i: QualifyFilterGateInput): {
165
+ show: boolean;
166
+ why: QualifyFilterGateReason;
167
+ };
168
+ /**
169
+ * The same question for a host whose chooser is an INLINE, SCROLLING PANEL - and it has no size
170
+ * clause, for the reason `shouldOpenInlineChooserOnGenerate` already sets out at length.
171
+ *
172
+ * THE ASYMMETRY IS THE POINT AND IT IS MEASURED. The modal lives in a card that CLIPS, so past a
173
+ * certain smallness its controls are simply not on screen. A panel that flows inside a scrolling
174
+ * pane, with a wrapping footer and a list carrying its own max-height, cannot reach that state -
175
+ * swept across 63 pane sizes down to 200x120, every one stayed usable. A size clause here would
176
+ * protect nobody and would switch the feature off in a default Excel task pane, which is narrower
177
+ * than the modal's floor.
178
+ *
179
+ * The OVERFLOW half still applies: a five-row answer does not want a filter box in any host.
180
+ */
181
+ export declare function inlineFilterGate(rowCount: number): {
182
+ show: boolean;
183
+ why: QualifyFilterGateReason;
184
+ };
185
+ /**
186
+ * The inline panel's stand-in for "the list scrolls".
187
+ *
188
+ * A COUNT RATHER THAN A MEASUREMENT, because the panel's list carries a fixed `max-height: 220px`
189
+ * and rows are one line each - so the count IS the overflow question there, where in the modal
190
+ * the card's height is the variable and the count is not. Eight rows at ~24px is the point the
191
+ * 220px list starts scrolling; below it there is nothing to scroll past.
192
+ */
193
+ export declare const INLINE_FILTER_MIN_ROWS = 8;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/chart-host",
3
- "version": "0.5.59",
3
+ "version": "0.5.60",
4
4
  "description": "Run a BIC-generated D3 chart in any web host: compiles the generated render() function, applies the shared option defaults, resolves mark clicks (through tooltip overlays), owns the selection affordance, and translates row indices between cross-filtered charts. The same contract the BIC Power BI visual implements, minus Power BI. React bindings at @bicharts/chart-host/react.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",