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
@@ -22,34 +22,57 @@ function nounOnly(summary, format) {
22
22
  if (summary.noun === void 0) return format.messages.drillNoun(n);
23
23
  return n === 1 ? summary.noun.one : summary.noun.other;
24
24
  }
25
- /** The panel's head: Back, its title, Close. The title takes focus whenever the step changes. */
26
- function DrillHead(props) {
25
+ function FocusTitle(props) {
27
26
  const { messages } = useDashboards();
28
27
  const heading = useRef(null);
29
28
  const { step } = props;
30
29
  useEffect(() => {
31
30
  if (step !== "") heading.current?.focus({ preventScroll: true });
32
31
  }, [step]);
32
+ return /* @__PURE__ */ jsx("h3", {
33
+ ref: heading,
34
+ tabIndex: -1,
35
+ children: props.onRoot === void 0 ? props.title : /* @__PURE__ */ jsx("button", {
36
+ type: "button",
37
+ className: "dd-drill-root",
38
+ onClick: props.onRoot,
39
+ children: messages.drillRoot(props.title)
40
+ })
41
+ });
42
+ }
43
+ /** The panel's head: Back, its title, Close. The title takes focus whenever the step changes. */
44
+ function DrillHead(props) {
45
+ const { messages } = useDashboards();
33
46
  return /* @__PURE__ */ jsxs("header", {
34
47
  className: "dd-panel-head dd-drill-head",
35
48
  children: [
36
- /* @__PURE__ */ jsxs("button", {
49
+ props.onBack === void 0 ? null : /* @__PURE__ */ jsx("button", {
37
50
  type: "button",
38
- className: "dd-button dd-quiet",
51
+ className: "dd-drill-icon",
52
+ "aria-label": messages.drillBack,
53
+ title: messages.drillBack,
39
54
  onClick: props.onBack,
40
- children: ["‹ ", messages.drillBack]
55
+ children: /* @__PURE__ */ jsx("span", {
56
+ className: "dd-direction",
57
+ "aria-hidden": "true",
58
+ children: "‹"
59
+ })
41
60
  }),
42
- /* @__PURE__ */ jsx("h3", {
43
- ref: heading,
44
- tabIndex: -1,
45
- children: props.title
61
+ /* @__PURE__ */ jsxs("div", {
62
+ className: "dd-drill-trail",
63
+ children: [/* @__PURE__ */ jsx(FocusTitle, { ...props }), props.children]
46
64
  }),
47
65
  /* @__PURE__ */ jsx("button", {
48
66
  type: "button",
49
- className: "dd-button dd-quiet",
67
+ className: "dd-drill-icon dd-drill-close",
68
+ "aria-label": messages.close,
69
+ title: messages.close,
50
70
  "aria-keyshortcuts": "Escape",
51
71
  onClick: props.onClose,
52
- children: messages.close
72
+ children: /* @__PURE__ */ jsx("span", {
73
+ "aria-hidden": "true",
74
+ children: "×"
75
+ })
53
76
  })
54
77
  ]
55
78
  });
@@ -76,25 +99,23 @@ function crumbText(c, format, timeZone) {
76
99
  /** The path as breadcrumbs: the tile, then each step, each going back to it. */
77
100
  function Crumbs(props) {
78
101
  const format = useDashboards();
102
+ if (props.path.every((c) => c.kind === "total")) return null;
79
103
  return /* @__PURE__ */ jsx("nav", {
80
104
  className: "dd-drill-crumbs",
81
105
  "aria-label": format.messages.drillTitle,
82
- children: /* @__PURE__ */ jsxs("ol", { children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
83
- type: "button",
84
- onClick: () => {
85
- props.onGoTo(0);
86
- },
87
- children: format.messages.drillRoot(props.root)
88
- }) }), props.path.map((c, i) => c.kind === "total" ? null : /* @__PURE__ */ jsx("li", {
106
+ children: /* @__PURE__ */ jsx("ol", { children: props.path.map((c, i) => c.kind === "total" ? null : /* @__PURE__ */ jsx("li", {
89
107
  "aria-current": i === props.path.length - 1 ? "step" : void 0,
90
- children: i === props.path.length - 1 ? /* @__PURE__ */ jsx("span", { children: crumbText(c, format, props.timeZone) }) : /* @__PURE__ */ jsx("button", {
108
+ children: i === props.path.length - 1 ? /* @__PURE__ */ jsxs("span", { children: [c.kind === "group" && !c.parts && c.value !== null ? /* @__PURE__ */ jsxs("small", {
109
+ className: "dd-sr-only",
110
+ children: [c.label, " "]
111
+ }) : null, crumbText(c, format, props.timeZone)] }) : /* @__PURE__ */ jsx("button", {
91
112
  type: "button",
92
113
  onClick: () => {
93
114
  props.onGoTo(i + 1);
94
115
  },
95
116
  children: crumbText(c, format, props.timeZone)
96
117
  })
97
- }, `${c.label}-${String(i)}`))] })
118
+ }, `${c.label}-${String(i)}`)) })
98
119
  });
99
120
  }
100
121
  /** "396 tasks with Hours (57 without)", or the rows alone. */
@@ -105,28 +126,37 @@ function rowsLine(summary, format) {
105
126
  const missing = without === void 0 || without <= 0 ? void 0 : formatCell(without, { type: "int" }, format);
106
127
  return format.messages.drillWith(rows, summary.operand, missing);
107
128
  }
129
+ function shareText(summary, parent, format) {
130
+ const share = summary.share;
131
+ if (share === void 0) return null;
132
+ const percent = new Intl.NumberFormat(format.locale, { style: "percent" }).format(share.value);
133
+ const metric = summary.column?.label;
134
+ const tile = metric === void 0 ? void 0 : format.messages.drillMetricTotal?.(metric);
135
+ return format.messages.drillShare(percent, share.of === "parent" ? parent : tile);
136
+ }
108
137
  /** The value, the rows behind it when they differ, its share, and what the viewer should know about it. */
109
138
  function Value({ summary, parent, onRefresh }) {
110
139
  const format = useDashboards();
111
140
  const value = formatCell(summary.value, valueColumn(summary), format);
112
141
  const rows = rowsLine(summary, format);
113
- const share = summary.share === void 0 ? void 0 : new Intl.NumberFormat(format.locale, { style: "percent" }).format(summary.share.value);
142
+ const share = shareText(summary, parent, format);
143
+ const counted = sameCount(summary);
144
+ const label = summary.column?.label ?? (counted ? nounOnly(summary, format) : void 0);
114
145
  return /* @__PURE__ */ jsxs("div", {
115
146
  className: "dd-drill-value",
116
- children: [/* @__PURE__ */ jsxs("p", { children: [
117
- /* @__PURE__ */ jsx("strong", { children: value }),
118
- rows === void 0 ? null : sameCount(summary) ? /* @__PURE__ */ jsxs("span", { children: [" ", nounOnly(summary, format)] }) : /* @__PURE__ */ jsxs("span", { children: [" · ", rows] }),
119
- share === void 0 ? null : /* @__PURE__ */ jsxs("span", { children: [
120
- " ",
121
- "·",
122
- " ",
123
- format.messages.drillShare(share, summary.share?.of === "parent" ? parent : void 0)
124
- ] })
125
- ] }), /* @__PURE__ */ jsx(Notes, {
126
- summary,
127
- value,
128
- onRefresh
129
- })]
147
+ children: [
148
+ /* @__PURE__ */ jsxs("p", {
149
+ className: "dd-drill-stat",
150
+ children: [/* @__PURE__ */ jsx("strong", { children: value }), label === void 0 ? null : /* @__PURE__ */ jsx("span", { children: label })]
151
+ }),
152
+ rows !== void 0 && !counted ? /* @__PURE__ */ jsx("p", { children: rows }) : null,
153
+ share === null ? null : /* @__PURE__ */ jsx("p", { children: share }),
154
+ /* @__PURE__ */ jsx(Notes, {
155
+ summary,
156
+ value,
157
+ onRefresh
158
+ })
159
+ ]
130
160
  });
131
161
  }
132
162
  export { Crumbs, DrillHead, Value, crumbText };
@@ -0,0 +1,40 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { asItem } from "./item-type.mjs";
3
+ import { itemLink } from "derive-dashboards/core";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/drill/ItemLink.tsx
6
+ const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
7
+ /**
8
+ * An item's link: the host's `itemHref` when it gives one (its `undefined` turns the link off),
9
+ * else its source's `itemLinks` template, else the server's. A hidden key never has one.
10
+ */
11
+ const hrefOf = (options, item) => options.itemHref === void 0 ? itemLink(options.itemLinks, item) ?? item.link : options.itemHref(asItem(item));
12
+ /** How an item opens: as a link, a button, or not at all. */
13
+ function Opener(props) {
14
+ const { link: Link = "a" } = useDashboards();
15
+ const { item, options } = props;
16
+ const href = hrefOf(options, item);
17
+ const onItem = options.onItem;
18
+ if (href === void 0 && onItem === void 0) return /* @__PURE__ */ jsx("div", {
19
+ className: props.className,
20
+ children: props.children
21
+ });
22
+ if (href === void 0) return /* @__PURE__ */ jsx("button", {
23
+ type: "button",
24
+ className: props.className,
25
+ onClick: (event) => onItem?.(asItem(item), { event }),
26
+ children: props.children
27
+ });
28
+ const onClick = (event) => {
29
+ if (onItem === void 0 || !plainClick(event)) return;
30
+ event.preventDefault();
31
+ onItem(asItem(item), { event });
32
+ };
33
+ return /* @__PURE__ */ jsx(Link, {
34
+ href,
35
+ className: props.className,
36
+ onClick,
37
+ children: props.children
38
+ });
39
+ }
40
+ export { Opener, hrefOf };
@@ -1,5 +1,6 @@
1
- import { Item } from "../index.mjs";
2
1
  import { ItemParts } from "./item-parts.mjs";
2
+ import "./item-type.mjs";
3
+ import { Item } from "../index.mjs";
3
4
  import { ComponentType, MouseEvent, ReactNode } from "react";
4
5
  import { DrillItem, DrillItemsView, ItemLinks } from "derive-dashboards/core";
5
6
  /** What a host's own item row is given: the item's link and parts, and how to open it. */
@@ -1,47 +1,14 @@
1
1
  import { isNumberType } from "../columns.mjs";
2
2
  import { useDashboards } from "../context.mjs";
3
3
  import { formatCell } from "../format.mjs";
4
- import { RowBody } from "../RowBody.mjs";
5
- import { columnShape, itemParts, readMode, writeMode } from "./item-parts.mjs";
4
+ import { Opener, hrefOf } from "./ItemLink.mjs";
5
+ import { columnShape, itemParts, itemTitle, recordField, recordParts, sortDate } from "./item-parts.mjs";
6
6
  import { asItem } from "./item-type.mjs";
7
- import { useEffect, useRef, useState } from "react";
8
- import { itemLink } from "derive-dashboards/core";
9
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { RecordHeading, RecordRow } from "./RecordRow.mjs";
8
+ import { RecordPager, useRecordPage } from "./record-page.mjs";
9
+ import { useEffect, useRef } from "react";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
10
11
  // src/drill/Items.tsx
11
- const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
12
- /**
13
- * An item's link: the host's `itemHref` when it gives one (its `undefined` turns the link off),
14
- * else its source's `itemLinks` template, else the server's. A hidden key never has one.
15
- */
16
- const hrefOf = (options, item) => options.itemHref === void 0 ? itemLink(options.itemLinks, item) ?? item.link : options.itemHref(asItem(item));
17
- /** How an item opens: as a link, a button, or not at all. */
18
- function Opener(props) {
19
- const { link: Link = "a" } = useDashboards();
20
- const { item, options } = props;
21
- const href = hrefOf(options, item);
22
- const onItem = options.onItem;
23
- if (href === void 0 && onItem === void 0) return /* @__PURE__ */ jsx("div", {
24
- className: props.className,
25
- children: props.children
26
- });
27
- if (href === void 0) return /* @__PURE__ */ jsx("button", {
28
- type: "button",
29
- className: props.className,
30
- onClick: (event) => onItem?.(asItem(item), { event }),
31
- children: props.children
32
- });
33
- const onClick = (event) => {
34
- if (onItem === void 0 || !plainClick(event)) return;
35
- event.preventDefault();
36
- onItem(asItem(item), { event });
37
- };
38
- return /* @__PURE__ */ jsx(Link, {
39
- href,
40
- className: props.className,
41
- onClick,
42
- children: props.children
43
- });
44
- }
45
12
  /** A noun as a column heading: "task" reads "Task". */
46
13
  const headOf = (noun) => noun === void 0 ? void 0 : `${noun.charAt(0).toLocaleUpperCase()}${noun.slice(1)}`;
47
14
  /**
@@ -52,14 +19,18 @@ const headOf = (noun) => noun === void 0 ? void 0 : `${noun.charAt(0).toLocaleUp
52
19
  function Table(props) {
53
20
  const format = useDashboards();
54
21
  const { view } = props;
22
+ const body = useAppendedRow(props);
55
23
  const cell = {
56
24
  ...format,
57
25
  timeZone: props.timeZone
58
26
  };
59
- const rest = view.columns.filter((c) => c.member !== view.title);
27
+ const priority = (member) => member === view.sorted?.member ? 0 : view.fixed?.includes(member) === true ? 2 : 1;
28
+ const rest = view.columns.filter((c) => c.member !== view.title).toSorted((a, b) => priority(a.member) - priority(b.member));
60
29
  const named = view.columns.find((c) => c.member === view.title);
61
- return /* @__PURE__ */ jsx("div", {
30
+ return /* @__PURE__ */ jsx("section", {
62
31
  className: "dd-records-scroll",
32
+ tabIndex: 0,
33
+ "aria-label": format.messages.drillViews.items,
63
34
  children: /* @__PURE__ */ jsxs("table", {
64
35
  className: "dd-table",
65
36
  children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
@@ -69,21 +40,28 @@ function Table(props) {
69
40
  scope: "col",
70
41
  "data-numeric": isNumberType(c.type),
71
42
  children: c.label
72
- }, c.member))] }) }), /* @__PURE__ */ jsx("tbody", { children: props.items.map((item, i) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
73
- scope: "row",
74
- children: /* @__PURE__ */ jsx(Opener, {
75
- item,
76
- options: props.options,
77
- className: "dd-item-cell",
78
- children: itemParts(view, item, {
79
- n: i + 1,
80
- noun: props.noun
81
- }, cell).title
82
- })
83
- }), rest.map((c) => /* @__PURE__ */ jsx("td", {
84
- "data-numeric": isNumberType(c.type),
85
- children: formatCell(item.values[c.member] ?? null, columnShape(c), cell)
86
- }, c.member))] }, item.id)) })]
43
+ }, c.member))] }) }), /* @__PURE__ */ jsx("tbody", {
44
+ ref: body,
45
+ children: props.items.map((item, i) => /* @__PURE__ */ jsxs("tr", {
46
+ tabIndex: -1,
47
+ children: [/* @__PURE__ */ jsx("th", {
48
+ scope: "row",
49
+ children: /* @__PURE__ */ jsx(Opener, {
50
+ item,
51
+ options: props.options,
52
+ className: "dd-item-cell",
53
+ children: itemTitle(named, item, {
54
+ n: props.start + i + 1,
55
+ noun: props.noun
56
+ }, cell)
57
+ })
58
+ }), rest.map((c) => /* @__PURE__ */ jsx("td", {
59
+ "data-numeric": isNumberType(c.type),
60
+ "data-type": c.type,
61
+ children: formatCell(item.values[c.member] ?? null, columnShape(c), cell)
62
+ }, c.member))]
63
+ }, item.id))
64
+ })]
87
65
  })
88
66
  });
89
67
  }
@@ -99,71 +77,120 @@ function helpersOf(options, item, base) {
99
77
  } }
100
78
  };
101
79
  }
102
- /** The items as a list: the default row, or the host's own (`renderItem`). After Show more, the first new row takes focus. */
103
- function List(props) {
104
- const format = useDashboards();
105
- const { view, options } = props;
80
+ /** Reveal the first new record for keyboard and pointer users, including read-only records. */
81
+ function useAppendedRow({ loaded, start }) {
106
82
  const list = useRef(null);
107
- const seen = useRef(props.items.length);
83
+ const seen = useRef(loaded);
108
84
  useEffect(() => {
109
85
  const before = seen.current;
110
- seen.current = props.items.length;
111
- if (props.items.length <= before || before === 0) return;
112
- list.current?.children[before]?.querySelector("a, button, [tabindex]")?.focus();
113
- }, [props.items.length]);
86
+ seen.current = loaded;
87
+ if (loaded <= before || before === 0 || before < start) return;
88
+ const row = list.current?.children[before - start];
89
+ if (!(row instanceof HTMLElement)) return;
90
+ const target = row.querySelector("a[href], button:not(:disabled), [tabindex]") ?? row;
91
+ target.focus({ preventScroll: true });
92
+ target.scrollIntoView({
93
+ block: "nearest",
94
+ inline: "nearest"
95
+ });
96
+ }, [loaded, start]);
97
+ return list;
98
+ }
99
+ function List(props) {
100
+ const format = useDashboards();
101
+ const { view, options } = props;
102
+ const list = useAppendedRow(props);
114
103
  const cell = {
115
104
  ...format,
116
105
  timeZone: props.timeZone
117
106
  };
107
+ const field = recordField(view);
108
+ const sorted = sortDate(view);
118
109
  return /* @__PURE__ */ jsx("ul", {
119
110
  className: "dd-items",
120
111
  ref: list,
121
112
  children: props.items.map((item, i) => {
122
- const parts = itemParts(view, item, {
123
- n: i + 1,
124
- noun: props.noun
125
- }, cell);
126
113
  const render = options.renderItem;
114
+ const row = {
115
+ n: props.start + i + 1,
116
+ noun: props.noun
117
+ };
127
118
  const opens = hrefOf(options, item) !== void 0 || options.onItem !== void 0;
128
- return /* @__PURE__ */ jsx("li", { children: render === void 0 ? /* @__PURE__ */ jsx(Opener, {
129
- item,
130
- options,
131
- className: "dd-item",
132
- children: /* @__PURE__ */ jsx(RowBody, {
133
- row: {
134
- ...parts,
135
- opens
136
- },
137
- family: "item"
138
- })
139
- }) : render(asItem(item), helpersOf(options, item, {
140
- ...parts,
141
- view
142
- })) }, item.id);
119
+ return /* @__PURE__ */ jsx("li", {
120
+ tabIndex: -1,
121
+ children: render === void 0 ? /* @__PURE__ */ jsx(Opener, {
122
+ item,
123
+ options,
124
+ className: "dd-item",
125
+ children: /* @__PURE__ */ jsx(RecordRow, {
126
+ parts: recordParts(view, item, {
127
+ ...row,
128
+ date: sorted?.member
129
+ }, cell),
130
+ opens,
131
+ date: sorted?.label,
132
+ field,
133
+ value: field && formatCell(item.values[field.member] ?? null, columnShape(field), cell)
134
+ })
135
+ }) : render(asItem(item), helpersOf(options, item, {
136
+ ...itemParts(view, item, row, cell),
137
+ view
138
+ }))
139
+ }, item.id);
143
140
  })
144
141
  });
145
142
  }
146
- /** The items as a list (the default) or a table, the choice kept in this browser. */
143
+ /** The toggle survives both layouts and takes focus back when the wide table closes. */
144
+ function useReturnToSummary(fields) {
145
+ const toggle = useRef(null);
146
+ const previous = useRef(fields);
147
+ useEffect(() => {
148
+ if (previous.current && !fields) toggle.current?.focus({ preventScroll: true });
149
+ previous.current = fields;
150
+ }, [fields]);
151
+ return toggle;
152
+ }
153
+ /** The same page of records as a summary list or a full table. */
147
154
  function Items(props) {
148
155
  const format = useDashboards();
149
156
  const { view, Empty } = props;
150
- const [mode, setMode] = useState(() => readMode(view.source));
157
+ const toggle = useReturnToSummary(props.fields);
158
+ const page = useRecordPage(props.items);
159
+ const visible = {
160
+ ...props,
161
+ start: page.start,
162
+ items: page.items,
163
+ loaded: props.items.length
164
+ };
151
165
  if (props.items.length === 0) return Empty === void 0 ? /* @__PURE__ */ jsx("p", {
152
166
  className: "dd-tile-state",
153
167
  children: format.messages.drillNoItems
154
168
  }) : /* @__PURE__ */ jsx(Empty, {});
155
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("fieldset", {
156
- className: "dd-drill-modes",
157
- "aria-label": format.messages.drillViews.items,
158
- children: ["list", "table"].map((m) => /* @__PURE__ */ jsx("button", {
159
- type: "button",
160
- "aria-pressed": mode === m,
161
- onClick: () => {
162
- setMode(m);
163
- writeMode(view.source, m);
164
- },
165
- children: m === "list" ? format.messages.drillList : format.messages.drillTable
166
- }, m))
167
- }), mode === "table" ? /* @__PURE__ */ jsx(Table, { ...props }) : /* @__PURE__ */ jsx(List, { ...props })] });
169
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
170
+ /* @__PURE__ */ jsxs("div", {
171
+ className: "dd-drill-records-head",
172
+ children: [props.count(page.paged ? {
173
+ first: page.start + 1,
174
+ last: page.end
175
+ } : void 0), /* @__PURE__ */ jsx("button", {
176
+ className: "dd-records-switch",
177
+ ref: toggle,
178
+ type: "button",
179
+ onClick: props.switchMode,
180
+ "aria-expanded": props.fields,
181
+ children: props.fields ? format.messages.drillList : format.messages.drillTable
182
+ })]
183
+ }),
184
+ page.paged && /* @__PURE__ */ jsx(RecordPager, {
185
+ page,
186
+ loaded: props.items.length
187
+ }),
188
+ !props.fields && props.options.renderItem === void 0 ? /* @__PURE__ */ jsx(RecordHeading, {
189
+ view,
190
+ noun: props.noun,
191
+ field: recordField(view)
192
+ }) : null,
193
+ props.fields ? /* @__PURE__ */ jsx(Table, { ...visible }) : /* @__PURE__ */ jsx(List, { ...visible })
194
+ ] });
168
195
  }
169
196
  export { Items };
@@ -0,0 +1,38 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell } from "../format.mjs";
3
+ import { OnlyToggle } from "./Controls.mjs";
4
+ import { Items } from "./Items.mjs";
5
+ import { RecordCount } from "./ItemsFoot.mjs";
6
+ import { itemFields, showsFields } from "./state.mjs";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ // src/drill/ItemsBody.tsx
9
+ /** Items: the Only filter, a percentile's marker row, then the rows. */
10
+ function ItemsBody(a) {
11
+ const format = useDashboards();
12
+ const { d, view, props } = a;
13
+ const p = view.percentile;
14
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
15
+ /* @__PURE__ */ jsx(OnlyToggle, { d }),
16
+ p === void 0 || d.summary === void 0 ? null : /* @__PURE__ */ jsx("p", {
17
+ className: "dd-drill-marker",
18
+ children: format.messages.drillPercentile(p, formatCell(d.summary.value, d.summary.column, format))
19
+ }),
20
+ /* @__PURE__ */ jsx(Items, {
21
+ count: (range) => /* @__PURE__ */ jsx(RecordCount, {
22
+ d,
23
+ range
24
+ }),
25
+ fields: showsFields(d.state),
26
+ switchMode: () => {
27
+ if (d.state) d.setView(itemFields(d.state, !showsFields(d.state)).view, "push");
28
+ },
29
+ view,
30
+ items: d.items.items,
31
+ options: props,
32
+ noun: d.summary?.noun?.one,
33
+ timeZone: d.summary?.receipt.calendar.timezone,
34
+ Empty: props.components?.Empty
35
+ })
36
+ ] });
37
+ }
38
+ export { ItemsBody };
@@ -1,5 +1,7 @@
1
1
  import { useDashboards } from "../context.mjs";
2
+ import { formatCell } from "../format.mjs";
2
3
  import { countText } from "./counts.mjs";
4
+ import { RECORD_PAGES } from "./words.mjs";
3
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
6
  // src/drill/ItemsFoot.tsx
5
7
  /**
@@ -11,7 +13,7 @@ function listCount(view, summary) {
11
13
  return summary.semantics === "distinct" ? summary.value : summary.itemCount;
12
14
  }
13
15
  /** Items' count and sort, then Show more while there are more, with a retry when a page fails. */
14
- function ItemsFoot({ d }) {
16
+ function RecordCount({ d, range }) {
15
17
  const format = useDashboards();
16
18
  const { messages } = format;
17
19
  const view = d.items.view;
@@ -19,23 +21,26 @@ function ItemsFoot({ d }) {
19
21
  const count = listCount(view, d.summary);
20
22
  const total = count === void 0 ? void 0 : countText(count, format);
21
23
  const sort = sortText(view, messages);
22
- return /* @__PURE__ */ jsxs(Fragment, { children: [
23
- /* @__PURE__ */ jsxs("p", {
24
- className: "dd-records-count",
25
- "aria-live": "polite",
26
- children: [
27
- messages.drillShowing(d.items.items.length, total),
28
- " · ",
29
- sort
30
- ]
31
- }),
32
- d.items.moreError === void 0 ? null : /* @__PURE__ */ jsx("p", {
33
- className: "dd-tile-error",
34
- role: "alert",
35
- children: messages.drillFailed
36
- }),
37
- d.items.hasMore ? /* @__PURE__ */ jsx(More, { d }) : null
38
- ] });
24
+ const number = (n) => formatCell(n, { type: "int" }, format);
25
+ return /* @__PURE__ */ jsxs("p", {
26
+ className: "dd-records-count",
27
+ "aria-live": "polite",
28
+ children: [
29
+ range === void 0 ? messages.drillShowing(d.items.items.length, total) : (messages.drillRecordPages ?? RECORD_PAGES).range(number(range.first), number(range.last), number(d.items.items.length), total),
30
+ " ",
31
+ "· ",
32
+ sort
33
+ ]
34
+ });
35
+ }
36
+ function ItemsFoot({ d }) {
37
+ const { messages } = useDashboards();
38
+ if (d.items.view === void 0) return null;
39
+ return /* @__PURE__ */ jsxs(Fragment, { children: [d.items.moreError === void 0 ? null : /* @__PURE__ */ jsx("p", {
40
+ className: "dd-tile-error",
41
+ role: "alert",
42
+ children: messages.drillFailed
43
+ }), d.items.hasMore ? /* @__PURE__ */ jsx(More, { d }) : null] });
39
44
  }
40
45
  /** How the Items are sorted, in words: the declared order, or by the value. */
41
46
  function sortText(view, messages) {
@@ -57,4 +62,4 @@ function More({ d }) {
57
62
  children: label
58
63
  });
59
64
  }
60
- export { ItemsFoot };
65
+ export { ItemsFoot, RecordCount };
@@ -1,6 +1,7 @@
1
- import { formatInstantAt } from "../format-time.mjs";
2
1
  import { useDashboards } from "../context.mjs";
3
2
  import { formatCell } from "../format.mjs";
3
+ import { formatPeriod } from "../format-time.mjs";
4
+ import { trendWindowLabel } from "./words.mjs";
4
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
6
  // src/drill/Notes.tsx
6
7
  /** The value as the line reads it: a ratio as a percent when its column says so. */
@@ -10,17 +11,26 @@ const valueColumn = (summary) => summary.semantics === "ratio" && summary.column
10
11
  fraction: true,
11
12
  type: "float"
12
13
  } : summary.column;
13
- /** For the period before: the note that these are its rows, with its dates. */
14
- function Earlier({ summary }) {
14
+ /** Show a trend's window separately only when it differs from the selection. */
15
+ function TrendPeriod({ range, summary }) {
16
+ const format = useDashboards();
17
+ const selected = summary?.range;
18
+ if (range === void 0 || range.from === selected?.from && range.to === selected.to) return null;
19
+ const period = formatPeriod(range, format, summary?.receipt.calendar.timezone);
20
+ const window = format.messages.drillTrendWindow ?? trendWindowLabel;
21
+ return /* @__PURE__ */ jsx("span", {
22
+ className: "dd-drill-range",
23
+ children: summary && !selected ? window(period) : period
24
+ });
25
+ }
26
+ function Period({ summary }) {
15
27
  const format = useDashboards();
16
28
  const { messages } = format;
17
- const { range } = summary;
18
- if (summary.previous !== true || range === void 0) return null;
19
- const zone = summary.receipt.calendar.timezone;
20
- const day = (at) => formatInstantAt(at, "day", format.locale, zone);
29
+ if (summary.range === void 0) return null;
30
+ const period = formatPeriod(summary.range, format, summary.receipt.calendar.timezone);
21
31
  return /* @__PURE__ */ jsx("p", {
22
32
  className: "dd-drill-period",
23
- children: messages.drillEarlier(messages.drillRange(day(range.from), day(range.to)))
33
+ children: summary.previous === true ? messages.drillEarlier(period) : period
24
34
  });
25
35
  }
26
36
  /** The notes under the value: the period before, a moved value (the viewer's own link only), a shared link's limits. */
@@ -28,14 +38,14 @@ function Notes({ summary, value, onRefresh }) {
28
38
  const format = useDashboards();
29
39
  const { messages } = format;
30
40
  const clicked = summary.clicked;
31
- const moved = summary.foreign !== true && clicked !== void 0 && JSON.stringify(clicked) !== JSON.stringify(summary.value);
41
+ const previous = clicked === void 0 || summary.foreign === true ? void 0 : formatCell(clicked, valueColumn(summary), format);
32
42
  return /* @__PURE__ */ jsxs(Fragment, { children: [
33
- /* @__PURE__ */ jsx(Earlier, { summary }),
34
- moved ? /* @__PURE__ */ jsxs("p", {
43
+ /* @__PURE__ */ jsx(Period, { summary }),
44
+ previous !== void 0 && previous !== value ? /* @__PURE__ */ jsxs("p", {
35
45
  className: "dd-tile-note",
36
46
  role: "status",
37
47
  children: [
38
- messages.drillMoved(value, formatCell(clicked, valueColumn(summary), format)),
48
+ messages.drillMoved(value, previous),
39
49
  " ",
40
50
  /* @__PURE__ */ jsx("button", {
41
51
  type: "button",
@@ -56,4 +66,4 @@ function Notes({ summary, value, onRefresh }) {
56
66
  }) : null
57
67
  ] });
58
68
  }
59
- export { Notes, valueColumn };
69
+ export { Notes, TrendPeriod, valueColumn };