derive-dashboards 0.6.0 → 0.7.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.
Files changed (134) hide show
  1. package/dist/charts/kinds/area-marks.mjs +2 -1
  2. package/dist/charts/kinds/funnel-words.mjs +1 -1
  3. package/dist/charts/kinds/grid-marks.mjs +9 -4
  4. package/dist/charts/theme.d.mts +13 -13
  5. package/dist/charts/theme.mjs +17 -14
  6. package/dist/charts-react/Overlay.mjs +1 -0
  7. package/dist/charts-react/chart-unlayered.css +1 -107
  8. package/dist/charts-react/chart.css +1 -121
  9. package/dist/charts-react/tip-place.mjs +30 -15
  10. package/dist/core/document/display-comparisons.mjs +49 -0
  11. package/dist/core/document/display-validation.d.mts +12 -0
  12. package/dist/core/document/display-validation.mjs +56 -0
  13. package/dist/core/document/display.d.mts +6 -12
  14. package/dist/core/document/display.mjs +23 -48
  15. package/dist/core/engine/dialect.d.mts +2 -0
  16. package/dist/core/engine/index.mjs +1 -1
  17. package/dist/core/engine/levels.mjs +33 -1
  18. package/dist/core/engine/postgres.mjs +1 -0
  19. package/dist/core/engine/rank.mjs +1 -1
  20. package/dist/core/engine/reader.d.mts +4 -0
  21. package/dist/core/engine/sql-partition.mjs +45 -0
  22. package/dist/core/engine/sql-reads.mjs +4 -1
  23. package/dist/core/engine/statement.mjs +4 -4
  24. package/dist/core/engine/version.d.mts +1 -1
  25. package/dist/core/engine/version.mjs +1 -1
  26. package/dist/core/error/codes.d.mts +1 -1
  27. package/dist/core/error/codes.mjs +1 -1
  28. package/dist/core/index.d.mts +6 -5
  29. package/dist/core/index.mjs +8 -7
  30. package/dist/core/model/validate/fields.mjs +1 -1
  31. package/dist/core/query/drill/compose.d.mts +2 -0
  32. package/dist/core/query/drill/compose.mjs +1 -1
  33. package/dist/core/query/drill/synthetic.mjs +1 -1
  34. package/dist/core/query/drill/types.d.mts +7 -0
  35. package/dist/core/query/drill/types.mjs +3 -1
  36. package/dist/core/schema/answers.d.mts +1176 -362
  37. package/dist/core/schema/drill-answers.mjs +19 -1
  38. package/dist/core/schema/drill.d.mts +21 -6
  39. package/dist/core/schema/drill.mjs +7 -1
  40. package/dist/core/schema/tools.mjs +13 -0
  41. package/dist/core/time/index.d.mts +2 -2
  42. package/dist/core/time/text-time.d.mts +9 -2
  43. package/dist/core/time/text-time.mjs +18 -3
  44. package/dist/core/types/api.d.mts +1 -1
  45. package/dist/core/types/api.mjs +1 -1
  46. package/dist/core/types/drill-api.d.mts +22 -2
  47. package/dist/dashboard-documents.d.mts +8 -0
  48. package/dist/dashboard-documents.mjs +52 -0
  49. package/dist/drill-access.mjs +40 -3
  50. package/dist/drill-comparison.mjs +71 -0
  51. package/dist/drill-crumbs.mjs +21 -2
  52. package/dist/drill-group-seal.mjs +13 -0
  53. package/dist/drill-open.mjs +7 -1
  54. package/dist/drill-seal.mjs +4 -6
  55. package/dist/drill-views.mjs +5 -13
  56. package/dist/drill.mjs +28 -58
  57. package/dist/editing.mjs +1 -1
  58. package/dist/endpoints/drill.mjs +2 -3
  59. package/dist/endpoints/index.d.mts +20 -0
  60. package/dist/index.d.mts +2 -1
  61. package/dist/index.mjs +6 -27
  62. package/dist/llms.txt +1 -1
  63. package/dist/react/Cell.mjs +2 -2
  64. package/dist/react/DashboardList.mjs +3 -3
  65. package/dist/react/Editing.mjs +3 -3
  66. package/dist/react/Header.mjs +2 -2
  67. package/dist/react/History.mjs +3 -3
  68. package/dist/react/Parts.mjs +2 -2
  69. package/dist/react/RowBody.d.mts +2 -4
  70. package/dist/react/RowBody.mjs +14 -39
  71. package/dist/react/Tile.mjs +4 -5
  72. package/dist/react/builder/FilterEditor.mjs +2 -2
  73. package/dist/react/builder/Picker.mjs +3 -3
  74. package/dist/react/builder/RangeEditor.mjs +3 -3
  75. package/dist/react/builder/Time.mjs +3 -3
  76. package/dist/react/builder/Values.mjs +2 -2
  77. package/dist/react/builder/WidgetBuilder.mjs +2 -2
  78. package/dist/react/drill/Bars.mjs +34 -38
  79. package/dist/react/drill/Comparison.mjs +204 -0
  80. package/dist/react/drill/Controls.mjs +8 -12
  81. package/dist/react/drill/DrillDrawer.mjs +42 -0
  82. package/dist/react/drill/DrillPanel.mjs +61 -41
  83. package/dist/react/drill/Header.mjs +65 -35
  84. package/dist/react/drill/ItemLink.mjs +40 -0
  85. package/dist/react/drill/Items.d.mts +2 -1
  86. package/dist/react/drill/Items.mjs +126 -99
  87. package/dist/react/drill/ItemsBody.mjs +38 -0
  88. package/dist/react/drill/ItemsFoot.mjs +24 -19
  89. package/dist/react/drill/Notes.mjs +23 -13
  90. package/dist/react/drill/PanelBody.mjs +7 -25
  91. package/dist/react/drill/RecordRow.mjs +47 -0
  92. package/dist/react/drill/Trend.mjs +186 -0
  93. package/dist/react/drill/board.mjs +21 -11
  94. package/dist/react/drill/drawer-context.mjs +5 -0
  95. package/dist/react/drill/item-parts.mjs +53 -35
  96. package/dist/react/drill/item-type.d.mts +2 -2
  97. package/dist/react/drill/lazy.d.mts +1 -4
  98. package/dist/react/drill/lazy.mjs +29 -11
  99. package/dist/react/drill/panel-focus.mjs +18 -7
  100. package/dist/react/drill/props.d.mts +7 -1
  101. package/dist/react/drill/props.mjs +39 -8
  102. package/dist/react/drill/record-page.mjs +61 -0
  103. package/dist/react/drill/state.mjs +17 -2
  104. package/dist/react/drill/trend-touch.mjs +33 -0
  105. package/dist/react/drill/useDrill.d.mts +3 -3
  106. package/dist/react/drill/useDrill.mjs +35 -15
  107. package/dist/react/drill/words.d.mts +14 -0
  108. package/dist/react/drill/words.mjs +19 -7
  109. package/dist/react/english.d.mts +1 -0
  110. package/dist/react/english.mjs +1 -0
  111. package/dist/react/filters/chip.mjs +2 -2
  112. package/dist/react/filters/menu-search.mjs +5 -5
  113. package/dist/react/filters/menu.mjs +2 -2
  114. package/dist/react/filters/number.mjs +2 -2
  115. package/dist/react/filters/operator.mjs +2 -2
  116. package/dist/react/filters/phone.mjs +2 -2
  117. package/dist/react/filters/values.mjs +4 -4
  118. package/dist/react/format-time.d.mts +1 -0
  119. package/dist/react/format-time.mjs +39 -33
  120. package/dist/react/format.mjs +10 -1
  121. package/dist/react/renderers/list.mjs +8 -10
  122. package/dist/react/renderers/table-cells.mjs +38 -9
  123. package/dist/react/renderers/table-measure.mjs +2 -0
  124. package/dist/react/renderers/table-row.mjs +64 -7
  125. package/dist/react/renderers/table-sort.mjs +2 -8
  126. package/dist/react/renderers/table.mjs +16 -15
  127. package/dist/react/theme-unlayered.css +1 -3148
  128. package/dist/react/theme.css +1 -3150
  129. package/dist/recharts/parts.mjs +1 -1
  130. package/dist/skills/derive-dashboards/SKILL.md +4 -2
  131. package/dist/store/apply.mjs +2 -2
  132. package/dist/store/editor.mjs +2 -2
  133. package/dist/store/writer.mjs +2 -2
  134. package/package.json +1 -1
@@ -5,7 +5,7 @@ import { Picker } from "./Picker.mjs";
5
5
  import { RangeEditor } from "./RangeEditor.mjs";
6
6
  import { Entry, Section } from "./Sections.mjs";
7
7
  import { useState } from "react";
8
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
9
  // src/builder/Time.tsx
10
10
  /** The quick ranges, each with the grain it reads best at. */
11
11
  const RANGES = [
@@ -61,7 +61,7 @@ function TimeField({ b, time }) {
61
61
  };
62
62
  const others = fieldOptions(b.meta, source, true).filter((o) => o.id !== time.dimension);
63
63
  if (others.length === 0) return null;
64
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
64
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
65
65
  className: "dd-form-label",
66
66
  children: messages.timeField
67
67
  }), /* @__PURE__ */ jsxs("div", {
@@ -96,7 +96,7 @@ function QuickRanges(props) {
96
96
  const [open, setOpen] = useState(false);
97
97
  const preset = RANGES.findIndex((r) => same(time.range, r.range));
98
98
  const custom = open || preset === -1;
99
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("fieldset", {
99
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
100
100
  className: "dd-seg dd-seg-fill",
101
101
  "aria-label": messages.timeRange,
102
102
  children: [RANGES.map((r, i) => /* @__PURE__ */ jsx("button", {
@@ -3,7 +3,7 @@ import { useDebounced } from "../debounce.mjs";
3
3
  import { Chip } from "./Sections.mjs";
4
4
  import { useState } from "react";
5
5
  import useSWR from "swr";
6
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
7
  // src/builder/Values.tsx
8
8
  /** A field's values as chips, the chosen ones pressed. */
9
9
  function ValueChips(props) {
@@ -59,7 +59,7 @@ function ValuePicker(props) {
59
59
  limit: 50,
60
60
  ...sent === "" ? {} : { search: sent }
61
61
  }));
62
- return /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
63
63
  /* @__PURE__ */ jsx("input", {
64
64
  className: "dd-search",
65
65
  type: "search",
@@ -8,7 +8,7 @@ import { Chip, KeptNote, MeasureSection, OpenSection } from "./Sections.mjs";
8
8
  import { TimeSection } from "./Time.mjs";
9
9
  import { useBuilder } from "./useBuilder.mjs";
10
10
  import { useEffect, useRef, useState } from "react";
11
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
12
  // src/builder/WidgetBuilder.tsx
13
13
  /** The usual kinds first; any other renderer the host registered follows, by its kind. */
14
14
  const USUAL = [
@@ -120,7 +120,7 @@ function OptionsSection({ b }) {
120
120
  onClick: () => void copy(),
121
121
  children: copied === "yes" ? messages.copied : messages.copyJson
122
122
  }),
123
- copied === "refused" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
123
+ copied === "refused" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("p", {
124
124
  className: "dd-builder-note",
125
125
  role: "status",
126
126
  children: messages.copyByHand
@@ -1,8 +1,10 @@
1
- import { formatBucket } from "../format-time.mjs";
2
1
  import { useDashboards } from "../context.mjs";
2
+ import { formatBucket } from "../format-time.mjs";
3
+ import { ENGLISH } from "../english.mjs";
3
4
  import { formatCell, plotValue } from "../format.mjs";
4
5
  import { rowEntry } from "./state.mjs";
5
- import { isMark, roleOf } from "derive-dashboards/core";
6
+ import { Columns } from "./Trend.mjs";
7
+ import { MAX_DRILL_ROWS, isMark, parseTextTime, roleOf } from "derive-dashboards/core";
6
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
9
  // src/drill/Bars.tsx
8
10
  /** A row's name: its time bucket or its group, as the tile names it ("No assignee" for no value). */
@@ -26,6 +28,27 @@ const lineAt = (view, entry) => {
26
28
  /** A change with its sign: "+6" when it went up. */
27
29
  const signed = (text, size) => size > 0 && !text.startsWith("+") ? `+${text}` : text;
28
30
  const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
31
+ /** Use the reporting instant, so a clipped historical month has a different label from this month. */
32
+ function isRunning(bucket, now) {
33
+ const from = parseTextTime(bucket.from);
34
+ const to = parseTextTime(bucket.to);
35
+ return bucket.partial !== "start" && now !== void 0 && from !== void 0 && to !== void 0 && from <= now && now < to;
36
+ }
37
+ /** A range ending before the reporting instant is clipped, even if both instants name the same month. */
38
+ function runningAt(view) {
39
+ const receipt = view.answer.receipt;
40
+ const now = parseTextTime(receipt.computedAt);
41
+ const end = view.range?.to ?? receipt.range?.to;
42
+ const until = end === void 0 ? void 0 : parseTextTime(end);
43
+ if (view.throughNow !== void 0) return view.throughNow ? until : void 0;
44
+ return now !== void 0 && until !== void 0 && now <= until ? now : void 0;
45
+ }
46
+ function partialNotes(view, { messages }) {
47
+ const notes = /* @__PURE__ */ new Map();
48
+ const now = runningAt(view);
49
+ for (const bucket of view.answer.time?.buckets ?? []) if (bucket.partial) notes.set(bucket.label, isRunning(bucket, now) ? messages.soFar : messages.chartPartial ?? ENGLISH.chartPartial);
50
+ return notes;
51
+ }
29
52
  /**
30
53
  * Each row as a bar: sized by its value, or for a Breakdown of the change by its change, and
31
54
  * read as the value, or as now, before and the change. A total is not drawn.
@@ -43,11 +66,13 @@ function barsOf(view, entry, format) {
43
66
  const sized = compared ? change : at;
44
67
  const max = Math.max(0, ...rows.map(({ row }) => Math.abs(plotValue(row[sized] ?? null) ?? 0)));
45
68
  const text = (row, i) => formatCell(row[i] ?? null, columns[i], format);
69
+ const notes = partialNotes(view, format);
46
70
  return rows.map(({ row, selection }) => {
47
71
  const size = plotValue(row[sized] ?? null) ?? 0;
48
72
  return {
49
73
  bar: {
50
74
  name: rowName(view, row, format),
75
+ note: typeof row[0] === "string" ? notes.get(row[0]) : void 0,
51
76
  width: max === 0 ? 0 : Math.abs(size) / max * 100,
52
77
  negative: size < 0,
53
78
  text: compared && (row[before] ?? null) !== null ? format.messages.drillChange(text(row, at), formatCell(row[before] ?? null, columns[at], format), signed(text(row, sized), size)) : text(row, at)
@@ -116,51 +141,22 @@ function changeLine(view, entry, format) {
116
141
  const size = plotValue(total[change] ?? null) ?? 0;
117
142
  return format.messages.drillVersus(formatCell(total[before] ?? null, columns[at], format), signed(formatCell(total[change] ?? null, columns[change], format), size));
118
143
  }
119
- /** Over time as columns, oldest to newest: each bucket a column to scale, a button when it goes deeper. */
120
- function Columns(props) {
121
- return /* @__PURE__ */ jsx("ol", {
122
- className: "dd-drill-columns",
123
- children: props.bars.map(({ bar, selection }, i) => {
124
- const label = `${bar.name}, ${bar.text}`;
125
- const column = /* @__PURE__ */ jsx("span", {
126
- className: "dd-drill-column",
127
- "data-negative": bar.negative,
128
- style: { blockSize: `${Math.max(bar.width, 2)}%` }
129
- });
130
- return /* @__PURE__ */ jsx("li", {
131
- title: label,
132
- children: selection === void 0 ? /* @__PURE__ */ jsx("span", {
133
- role: "img",
134
- "aria-label": label,
135
- children: column
136
- }) : /* @__PURE__ */ jsx("button", {
137
- type: "button",
138
- "aria-label": label,
139
- onClick: () => {
140
- props.onOpen(selection);
141
- },
142
- children: column
143
- })
144
- }, i);
145
- })
146
- });
147
- }
148
- /**
149
- * A Breakdown as a list of bars, or Over time as columns: each group or bucket with its value
150
- * to scale and, when it drills, a button that goes one step deeper. A total is not drawn; a
151
- * Breakdown of the change says the whole change first.
152
- */
144
+ /** A breakdown shows groups and their changes. A trend shows the same values in time order. */
153
145
  function Bars(props) {
154
146
  const format = useDashboards();
155
147
  const { view } = props;
148
+ const { messages } = format;
156
149
  const bars = barsOf(view, props.entry, format);
157
150
  if (bars.length === 0) return /* @__PURE__ */ jsx("p", {
158
151
  className: "dd-tile-state",
159
- children: view.search === void 0 ? format.messages.drillNoGroups : format.messages.drillNoMatch
152
+ children: view.search === void 0 ? messages.drillNoGroups : messages.drillNoMatch
160
153
  });
161
154
  if (view.by === "trend") return /* @__PURE__ */ jsx(Columns, {
162
155
  bars,
163
- onOpen: props.onOpen
156
+ onOpen: props.onOpen,
157
+ details: messages.drillHint,
158
+ pages: messages.drillRecordPages,
159
+ limitNote: view.answer.rows.length > MAX_DRILL_ROWS ? messages.drillReasons.ROW_CAP : void 0
164
160
  });
165
161
  const change = changeLine(view, props.entry, format);
166
162
  return /* @__PURE__ */ jsxs(Fragment, { children: [change === void 0 ? null : /* @__PURE__ */ jsx("p", {
@@ -0,0 +1,204 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell, groupText } from "../format.mjs";
3
+ import { formatPeriod } from "../format-time.mjs";
4
+ import { isTotal } from "../renderers/table-scale.mjs";
5
+ import { crumbText } from "./Header.mjs";
6
+ import { rowEntry } from "./state.mjs";
7
+ import { useDrill } from "./useDrill.mjs";
8
+ import { Fragment, useId, useState } from "react";
9
+ import { MAX_DRILL_STEPS, isMark } from "derive-dashboards/core";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
+ // src/drill/Comparison.tsx
12
+ function GroupName({ label }) {
13
+ return label.split(/(?<=[_-])/u).map((part, i) => /* @__PURE__ */ jsxs(Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("wbr", {}), part] }, i));
14
+ }
15
+ function GroupRow({ view, row, toggle, child }) {
16
+ const format = useDashboards();
17
+ const [, ...metrics] = view.answer.columns;
18
+ const value = row[0] ?? null;
19
+ const label = groupLabel({
20
+ view,
21
+ row
22
+ }, format);
23
+ return /* @__PURE__ */ jsxs("tr", {
24
+ "data-child": child === void 0 ? void 0 : true,
25
+ "data-mark": isMark(value) ? value.mark : void 0,
26
+ children: [/* @__PURE__ */ jsxs("th", {
27
+ scope: "row",
28
+ children: [child !== void 0 && /* @__PURE__ */ jsxs("span", {
29
+ className: "dd-sr-only",
30
+ children: [child, " · "]
31
+ }), toggle ? /* @__PURE__ */ jsxs("button", {
32
+ type: "button",
33
+ "aria-label": toggle.label,
34
+ "aria-expanded": toggle.expanded,
35
+ "aria-controls": toggle.controls,
36
+ onClick: toggle.click,
37
+ children: [/* @__PURE__ */ jsx("span", {
38
+ className: "dd-disclosure dd-direction",
39
+ "aria-hidden": "true",
40
+ children: "›"
41
+ }), /* @__PURE__ */ jsx(GroupName, { label })]
42
+ }) : /* @__PURE__ */ jsx(GroupName, { label })]
43
+ }), metrics.map((column, i) => /* @__PURE__ */ jsx("td", { children: formatCell(row[i + 1] ?? null, column, format) }, column.id))]
44
+ });
45
+ }
46
+ function InlineNote({ columns, children }) {
47
+ return /* @__PURE__ */ jsx("tr", {
48
+ "data-child": "true",
49
+ children: /* @__PURE__ */ jsx("td", {
50
+ colSpan: columns,
51
+ className: "dd-comparison-note",
52
+ "aria-live": "polite",
53
+ children
54
+ })
55
+ });
56
+ }
57
+ /** Fetch a group's children only while it is open. Keep every value under its parent column. */
58
+ function Children(props) {
59
+ const { messages } = useDashboards();
60
+ const [state, setState] = useState(props.state);
61
+ const d = useDrill({
62
+ state,
63
+ onStateChange: setState
64
+ });
65
+ if (d.status === "error") return /* @__PURE__ */ jsxs(InlineNote, {
66
+ columns: props.columns,
67
+ children: [
68
+ messages.drillFailed,
69
+ " ",
70
+ /* @__PURE__ */ jsx("button", {
71
+ type: "button",
72
+ onClick: d.retry,
73
+ children: messages.drillRetry
74
+ })
75
+ ]
76
+ });
77
+ const view = d.shown;
78
+ if (view?.by !== "comparison") return /* @__PURE__ */ jsx(InlineNote, {
79
+ columns: props.columns,
80
+ children: messages.loading
81
+ });
82
+ if (view.answer.unreadable || view.omitted) return /* @__PURE__ */ jsx(InlineNote, {
83
+ columns: props.columns,
84
+ children: messages.noAccess
85
+ });
86
+ const rows = view.answer.rows.filter((row) => !isTotal(row));
87
+ if (rows.length === 0) return /* @__PURE__ */ jsx(InlineNote, {
88
+ columns: props.columns,
89
+ children: messages.drillNoGroups
90
+ });
91
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("tr", {
92
+ className: "dd-comparison-subhead",
93
+ children: /* @__PURE__ */ jsx("th", {
94
+ colSpan: props.columns,
95
+ children: props.label
96
+ })
97
+ }), rows.map((row) => /* @__PURE__ */ jsx(GroupRow, {
98
+ view,
99
+ row,
100
+ child: props.parent
101
+ }, JSON.stringify(row[0])))] });
102
+ }
103
+ function groupLabel(props, format) {
104
+ const value = props.row[0] ?? null;
105
+ const column = props.view.answer.columns[0];
106
+ return groupText(value, column, format);
107
+ }
108
+ function Group(props) {
109
+ const format = useDashboards();
110
+ const [expanded, setExpanded] = useState(false);
111
+ const childrenId = useId();
112
+ const { view, row, state } = props;
113
+ const field = view.thenBy;
114
+ const selection = rowEntry(view.drill, props.index);
115
+ const terminal = isMark(row[0] ?? null) || state.path.length >= MAX_DRILL_STEPS;
116
+ if (!field || selection === void 0 || terminal) return /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx(GroupRow, { ...props }) });
117
+ const label = groupLabel(props, format);
118
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx(GroupRow, {
119
+ ...props,
120
+ toggle: {
121
+ controls: childrenId,
122
+ expanded,
123
+ label: `${label} · ${format.messages.drillBy} ${field.label}`,
124
+ click: () => {
125
+ setExpanded(!expanded);
126
+ }
127
+ }
128
+ }) }), /* @__PURE__ */ jsx("tbody", {
129
+ id: childrenId,
130
+ hidden: !expanded,
131
+ "aria-label": label,
132
+ children: expanded && /* @__PURE__ */ jsx(Children, {
133
+ state: {
134
+ ...state,
135
+ path: [...state.path, selection],
136
+ view: {
137
+ by: "comparison",
138
+ member: field.id
139
+ }
140
+ },
141
+ columns: view.answer.columns.length,
142
+ parent: label,
143
+ label: field.label
144
+ }, selection)
145
+ })] });
146
+ }
147
+ function ComparisonTable({ label, view, state }) {
148
+ const { columns, rows } = view.answer;
149
+ return /* @__PURE__ */ jsx("div", {
150
+ className: "dd-comparison-scroll",
151
+ children: /* @__PURE__ */ jsxs("table", {
152
+ "aria-label": label,
153
+ style: { minWidth: `${17 + (columns.length - 1) * 10}ch` },
154
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((c) => /* @__PURE__ */ jsx("th", {
155
+ scope: "col",
156
+ children: c.label
157
+ }, c.id)) }) }), rows.map((row, index) => /* @__PURE__ */ jsx(Group, {
158
+ row,
159
+ index,
160
+ view,
161
+ state
162
+ }, JSON.stringify(row[0])))]
163
+ })
164
+ });
165
+ }
166
+ function ComparisonHeading({ answer, label, by, receipt }) {
167
+ const format = useDashboards();
168
+ const last = answer.path.at(-1);
169
+ return /* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsxs("h4", { children: [last?.kind === "group" && !last.parts && last.value !== null ? /* @__PURE__ */ jsxs("small", { children: [last.label, " "] }) : null, label] }), /* @__PURE__ */ jsxs("p", { children: [by, receipt.range && /* @__PURE__ */ jsxs(Fragment$1, { children: [" · ", formatPeriod(receipt.range, format, receipt.calendar.timezone)] })] })] });
170
+ }
171
+ function Comparison({ answer, view }) {
172
+ const format = useDashboards();
173
+ const { messages } = format;
174
+ const { columns, rows, receipt } = view.answer;
175
+ const last = answer.path.at(-1);
176
+ const label = last ? crumbText(last, format, receipt.calendar.timezone) : messages.total;
177
+ const field = columns[0]?.label ?? "";
178
+ const by = messages.drillGroupedBy?.(field) ?? field;
179
+ if (view.answer.unreadable) return /* @__PURE__ */ jsx("p", {
180
+ role: "status",
181
+ children: messages.noAccess
182
+ });
183
+ return /* @__PURE__ */ jsxs("section", {
184
+ className: "dd-comparison",
185
+ children: [
186
+ /* @__PURE__ */ jsx(ComparisonHeading, {
187
+ answer,
188
+ label,
189
+ by,
190
+ receipt
191
+ }),
192
+ view.omitted && /* @__PURE__ */ jsx("p", {
193
+ role: "status",
194
+ children: messages.drillOmitted
195
+ }),
196
+ rows.length === 0 ? /* @__PURE__ */ jsx("p", { children: messages.drillNoGroups }) : /* @__PURE__ */ jsx(ComparisonTable, {
197
+ label: `${label} · ${by}`,
198
+ view,
199
+ state: answer.state
200
+ })
201
+ ]
202
+ });
203
+ }
204
+ export { Comparison };
@@ -1,23 +1,19 @@
1
- import { formatInstantAt } from "../format-time.mjs";
2
1
  import { useDashboards } from "../context.mjs";
3
2
  import { formatCell } from "../format.mjs";
3
+ import { TrendPeriod } from "./Notes.mjs";
4
4
  import { useEffect, useState } from "react";
5
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/drill/Controls.tsx
7
7
  /** Over time's range in words and its grain picker. */
8
8
  function TrendControls({ d }) {
9
- const format = useDashboards();
10
- const { messages } = format;
9
+ const { messages } = useDashboards();
11
10
  const shown = d.shown;
12
11
  if (shown?.by !== "trend") return null;
13
- const zone = d.summary?.receipt.calendar.timezone;
14
- const range = shown.range;
15
- const day = (text) => formatInstantAt(text, "day", format.locale, zone);
16
12
  return /* @__PURE__ */ jsxs("div", {
17
13
  className: "dd-drill-controls",
18
- children: [range === void 0 ? null : /* @__PURE__ */ jsx("span", {
19
- className: "dd-drill-range",
20
- children: messages.drillRange(day(range.from), day(range.to))
14
+ children: [/* @__PURE__ */ jsx(TrendPeriod, {
15
+ range: shown.range,
16
+ summary: d.summary
21
17
  }), (shown.grains ?? []).length < 2 ? null : /* @__PURE__ */ jsxs("label", {
22
18
  className: "dd-drill-by",
23
19
  children: [/* @__PURE__ */ jsx("span", {
@@ -120,7 +116,7 @@ function OnlyToggle({ d }) {
120
116
  if (numerator === void 0) return null;
121
117
  const count = numerator.count === void 0 ? "" : formatCell(numerator.count, { type: "int" }, format);
122
118
  const only = numerator.only === true;
123
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
119
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
124
120
  type: "button",
125
121
  className: "dd-drill-only",
126
122
  "aria-pressed": only,
@@ -144,7 +140,7 @@ function Operands({ d }) {
144
140
  return /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsx("h4", { children: format.messages.drillOperands }), /* @__PURE__ */ jsx("ul", {
145
141
  className: "dd-drill-operands",
146
142
  children: shown.operands.map((o) => {
147
- const body = /* @__PURE__ */ jsxs(Fragment, { children: [
143
+ const body = /* @__PURE__ */ jsxs(Fragment$1, { children: [
148
144
  /* @__PURE__ */ jsxs("span", { children: [
149
145
  o.label,
150
146
  " ",
@@ -0,0 +1,42 @@
1
+ import { InDrillDrawer } from "./drawer-context.mjs";
2
+ import { useFocusReturn } from "./panel-focus.mjs";
3
+ import { useEffect, useLayoutEffect, useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/drill/DrillDrawer.tsx
6
+ const useLayout = typeof document === "undefined" ? useEffect : useLayoutEffect;
7
+ /** The built-in inspector owns focus while open. A host placing DrillPanel itself owns its surface. */
8
+ function DrillDrawer(props) {
9
+ const dialog = useRef(null);
10
+ const pressedOutside = useRef(false);
11
+ useFocusReturn(dialog, props.widgetId);
12
+ useLayout(() => {
13
+ const node = dialog.current;
14
+ node?.toggleAttribute("data-gutter", window.innerWidth > document.documentElement.clientWidth);
15
+ node?.showModal();
16
+ node?.querySelector(".dd-drill-head h3")?.focus({ preventScroll: true });
17
+ return () => node?.close();
18
+ }, []);
19
+ return /* @__PURE__ */ jsx("dialog", {
20
+ className: "dd-drill-drawer",
21
+ ref: dialog,
22
+ "aria-label": props.title,
23
+ onKeyDown: (event) => {
24
+ event.stopPropagation();
25
+ },
26
+ onCancel: (event) => {
27
+ event.preventDefault();
28
+ props.close();
29
+ },
30
+ onPointerDown: (event) => {
31
+ pressedOutside.current = event.target === event.currentTarget;
32
+ },
33
+ onPointerUp: (event) => {
34
+ if (pressedOutside.current && event.target === event.currentTarget) props.close();
35
+ },
36
+ children: /* @__PURE__ */ jsx(InDrillDrawer.Provider, {
37
+ value: true,
38
+ children: props.children
39
+ })
40
+ });
41
+ }
42
+ export { DrillDrawer };
@@ -2,11 +2,12 @@ import { useDashboards } from "../context.mjs";
2
2
  import { Tabs } from "./DrillTabs.mjs";
3
3
  import { Crumbs, DrillHead, Value, crumbText } from "./Header.mjs";
4
4
  import { Main } from "./PanelBody.mjs";
5
+ import { useFocusReturn, usePanelLandmark, usePeek } from "./panel-focus.mjs";
6
+ import { showsFields } from "./state.mjs";
5
7
  import { SeeRows } from "./PanelStates.mjs";
6
- import { useFocusReturn, usePeek } from "./panel-focus.mjs";
7
8
  import { useDrill } from "./useDrill.mjs";
8
9
  import { useRef } from "react";
9
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
10
11
  // src/drill/DrillPanel.tsx
11
12
  /** The panel over its own controller. */
12
13
  function OwnController(props) {
@@ -22,6 +23,7 @@ function OwnController(props) {
22
23
  /** Escape closes the drill; the dashboard's own Escape would close it again, so it stops here. */
23
24
  function closeOnEscape(event, close) {
24
25
  if (event.key !== "Escape") return;
26
+ event.preventDefault();
25
27
  event.stopPropagation();
26
28
  close();
27
29
  }
@@ -32,58 +34,76 @@ function parentText(parent, title, named) {
32
34
  }
33
35
  /** The widget a dashboard's drill opened from: its tile is lit, and focus goes back to it. */
34
36
  const widgetOf = (state) => state?.origin.kind === "dashboard" ? state.origin.widgetId : void 0;
37
+ function rootLink(d) {
38
+ if (d.path.every((c) => c.kind === "total")) return;
39
+ return () => {
40
+ d.goTo(0);
41
+ };
42
+ }
43
+ const isComparison = (d) => d.view?.by === "comparison";
44
+ const hasParent = (d) => showsFields(d.state) || (d.state?.path.length ?? 0) > 1;
45
+ function PanelHead({ d, title, close }) {
46
+ const format = useDashboards();
47
+ const comparison = isComparison(d);
48
+ const zone = d.summary?.receipt.calendar.timezone;
49
+ const parent = d.path.at(-2);
50
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(DrillHead, {
51
+ title,
52
+ step: JSON.stringify(d.state?.path),
53
+ onRoot: comparison ? void 0 : rootLink(d),
54
+ onBack: hasParent(d) ? d.back : void 0,
55
+ onClose: close,
56
+ children: comparison ? null : /* @__PURE__ */ jsx(Crumbs, {
57
+ path: d.path,
58
+ timeZone: zone,
59
+ onGoTo: d.goTo
60
+ })
61
+ }), d.summary === void 0 || comparison ? null : /* @__PURE__ */ jsx(Value, {
62
+ summary: d.summary,
63
+ parent: parentText(parent, title, (c) => crumbText(c, format, zone)),
64
+ onRefresh: d.retry
65
+ })] });
66
+ }
67
+ const explicitRecords = (d) => d.state?.view?.by === "items";
35
68
  function Panel({ d, ...props }) {
36
69
  const format = useDashboards();
70
+ const title = props.title ?? format.messages.drillTitle;
71
+ const landmark = usePanelLandmark(title);
37
72
  const panel = useRef(null);
38
- useFocusReturn(panel, widgetOf(d.state));
39
- const [peek, expand] = usePeek();
73
+ useFocusReturn(panel, widgetOf(d.state), landmark.role === "presentation");
74
+ const comparison = isComparison(d);
75
+ const wide = comparison || showsFields(d.state);
76
+ const [peek, expand] = usePeek(wide, explicitRecords(d));
40
77
  if (d.state === void 0) return null;
41
- const title = props.title ?? format.messages.drillTitle;
42
78
  const close = props.onClose ?? d.close;
43
- const zone = d.summary?.receipt.calendar.timezone;
44
- const parent = d.path.at(-2);
45
79
  return /* @__PURE__ */ jsxs("aside", {
46
80
  ref: panel,
47
81
  className: "dd-panel dd-drill",
48
- "aria-label": title,
82
+ ...landmark,
49
83
  "data-peek": peek,
84
+ "data-wide": wide || void 0,
50
85
  onKeyDown: (event) => {
51
86
  closeOnEscape(event, close);
52
87
  },
53
- children: [
54
- /* @__PURE__ */ jsx(DrillHead, {
55
- title,
56
- step: JSON.stringify(d.state.path),
57
- onBack: d.back,
58
- onClose: close
59
- }),
60
- /* @__PURE__ */ jsx(Crumbs, {
61
- root: title,
62
- path: d.path,
63
- timeZone: zone,
64
- onGoTo: d.goTo
65
- }),
66
- d.summary === void 0 ? null : /* @__PURE__ */ jsx(Value, {
67
- summary: d.summary,
68
- parent: parentText(parent, title, (c) => crumbText(c, format, zone)),
69
- onRefresh: d.retry
70
- }),
71
- peek ? /* @__PURE__ */ jsx(SeeRows, {
88
+ children: [/* @__PURE__ */ jsx(PanelHead, {
89
+ d,
90
+ title,
91
+ close
92
+ }), peek ? /* @__PURE__ */ jsx(SeeRows, {
93
+ d,
94
+ onExpand: expand
95
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
96
+ comparison ? null : /* @__PURE__ */ jsx(Tabs, { d }),
97
+ /* @__PURE__ */ jsx(Main, {
72
98
  d,
73
- onExpand: expand
74
- }) : /* @__PURE__ */ jsxs(Fragment, { children: [
75
- /* @__PURE__ */ jsx(Tabs, { d }),
76
- /* @__PURE__ */ jsx(Main, {
77
- d,
78
- props,
79
- close
80
- }),
81
- props.actions === void 0 ? null : /* @__PURE__ */ jsx("div", {
82
- className: "dd-panel-foot",
83
- children: props.actions
84
- })
85
- ] })
86
- ]
99
+ props,
100
+ close
101
+ }),
102
+ props.actions === void 0 ? null : /* @__PURE__ */ jsx("div", {
103
+ className: "dd-panel-foot",
104
+ children: props.actions
105
+ })
106
+ ] })]
87
107
  });
88
108
  }
89
109
  /**