derive-dashboards 0.1.1 → 0.2.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 (167) hide show
  1. package/README.md +5 -3
  2. package/dist/cli/add.mjs +130 -0
  3. package/dist/cli/cli.mjs +14 -12
  4. package/dist/cli/config.mjs +12 -1
  5. package/dist/cli/doctor.mjs +147 -0
  6. package/dist/cli/init.mjs +3 -2
  7. package/dist/cli/json.mjs +21 -0
  8. package/dist/cli/layers.mjs +33 -0
  9. package/dist/core/document/layout.mjs +1 -1
  10. package/dist/core/document/view-layout.d.mts +14 -0
  11. package/dist/core/document/view-layout.mjs +157 -0
  12. package/dist/core/engine/filter.mjs +2 -2
  13. package/dist/core/engine/leaf.mjs +9 -4
  14. package/dist/core/engine/members.mjs +1 -1
  15. package/dist/core/engine/version.d.mts +1 -1
  16. package/dist/core/engine/version.mjs +1 -1
  17. package/dist/core/error/codes.d.mts +2 -1
  18. package/dist/core/error/codes.mjs +2 -1
  19. package/dist/core/index.d.mts +5 -3
  20. package/dist/core/index.mjs +5 -3
  21. package/dist/core/model/member.mjs +5 -2
  22. package/dist/core/model/types.d.mts +13 -13
  23. package/dist/core/model/validate/members.mjs +7 -4
  24. package/dist/core/policy/bind-query.d.mts +12 -0
  25. package/dist/core/policy/bind-query.mjs +53 -0
  26. package/dist/core/query/filter.d.mts +6 -0
  27. package/dist/core/query/picks.d.mts +8 -2
  28. package/dist/core/query/picks.mjs +11 -4
  29. package/dist/core/query/segments.mjs +2 -1
  30. package/dist/core/result/columns.mjs +6 -3
  31. package/dist/core/schema/aliases.d.mts +7 -0
  32. package/dist/core/schema/aliases.mjs +77 -0
  33. package/dist/core/schema/answers.d.mts +1 -0
  34. package/dist/core/schema/answers.mjs +1 -0
  35. package/dist/core/schema/index.d.mts +3 -2
  36. package/dist/core/schema/index.mjs +3 -2
  37. package/dist/core/schema/query.d.mts +81 -0
  38. package/dist/core/schema/query.mjs +9 -5
  39. package/dist/core/types/api.d.mts +7 -1
  40. package/dist/core/types/api.mjs +1 -1
  41. package/dist/dashboards.mjs +4 -0
  42. package/dist/editing.mjs +2 -2
  43. package/dist/endpoints/dashboards.mjs +17 -2
  44. package/dist/endpoints/index.d.mts +12 -2
  45. package/dist/endpoints/meta.mjs +10 -1
  46. package/dist/execute.mjs +20 -11
  47. package/dist/handler.mjs +5 -1
  48. package/dist/llms.txt +22 -0
  49. package/dist/mcp/format.mjs +42 -8
  50. package/dist/mcp/query.mjs +34 -4
  51. package/dist/postgres-store.mjs +1 -0
  52. package/dist/react/Canvas.mjs +28 -5
  53. package/dist/react/Cell.mjs +2 -1
  54. package/dist/react/Dashboard.mjs +15 -3
  55. package/dist/react/DashboardList.mjs +22 -22
  56. package/dist/react/DashboardListRow.mjs +49 -0
  57. package/dist/react/Discard.mjs +5 -2
  58. package/dist/react/Editing.mjs +19 -5
  59. package/dist/react/FilterBar.d.mts +7 -9
  60. package/dist/react/Grid.mjs +7 -19
  61. package/dist/react/Header.mjs +1 -1
  62. package/dist/react/History.mjs +5 -0
  63. package/dist/react/ReadFailed.mjs +23 -0
  64. package/dist/react/Spaces.mjs +15 -1
  65. package/dist/react/Tile.d.mts +2 -0
  66. package/dist/react/Tile.mjs +35 -7
  67. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  68. package/dist/react/arrange-steps.mjs +16 -13
  69. package/dist/react/arrange.mjs +10 -3
  70. package/dist/react/builder/Calcs.mjs +35 -11
  71. package/dist/react/builder/FilterEditor.mjs +196 -0
  72. package/dist/react/builder/Filters.mjs +172 -116
  73. package/dist/react/builder/Formula.mjs +82 -0
  74. package/dist/react/builder/Groups.mjs +1 -0
  75. package/dist/react/builder/Preview.mjs +1 -1
  76. package/dist/react/builder/RangeEditor.mjs +184 -0
  77. package/dist/react/builder/Sections.mjs +41 -6
  78. package/dist/react/builder/Time.mjs +138 -60
  79. package/dist/react/builder/Values.mjs +85 -0
  80. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  81. package/dist/react/builder/base.d.mts +5 -0
  82. package/dist/react/builder/base.mjs +33 -8
  83. package/dist/react/builder/calc.mjs +15 -1
  84. package/dist/react/builder/escape.d.mts +1 -0
  85. package/dist/react/builder/escape.mjs +62 -0
  86. package/dist/react/builder/filter-tree.d.mts +9 -0
  87. package/dist/react/builder/filter-tree.mjs +186 -0
  88. package/dist/react/builder/formula-parse.d.mts +18 -0
  89. package/dist/react/builder/formula-parse.mjs +136 -0
  90. package/dist/react/builder/labels.d.mts +1 -1
  91. package/dist/react/builder/state.d.mts +2 -1
  92. package/dist/react/builder/state.mjs +23 -37
  93. package/dist/react/builder/useBuilder.d.mts +12 -1
  94. package/dist/react/builder/useBuilder.mjs +6 -3
  95. package/dist/react/builder/words.d.mts +59 -0
  96. package/dist/react/builder/words.mjs +73 -0
  97. package/dist/react/context.d.mts +13 -0
  98. package/dist/react/context.mjs +9 -3
  99. package/dist/react/drill/useDrill.d.mts +1 -1
  100. package/dist/react/drill/words.d.mts +3 -0
  101. package/dist/react/drill/words.mjs +2 -0
  102. package/dist/react/english.mjs +20 -5
  103. package/dist/react/filters/bar.d.mts +12 -0
  104. package/dist/react/filters/bar.mjs +135 -0
  105. package/dist/react/filters/calendar.mjs +193 -0
  106. package/dist/react/filters/chip.mjs +174 -0
  107. package/dist/react/filters/context.d.mts +22 -0
  108. package/dist/react/filters/context.mjs +78 -0
  109. package/dist/react/filters/dates.mjs +89 -0
  110. package/dist/react/filters/days.d.mts +36 -0
  111. package/dist/react/filters/days.mjs +87 -0
  112. package/dist/react/filters/field-step.mjs +81 -0
  113. package/dist/react/filters/hooks.d.mts +34 -0
  114. package/dist/react/filters/hooks.mjs +94 -0
  115. package/dist/react/filters/listbox.mjs +131 -0
  116. package/dist/react/filters/logic.d.mts +59 -0
  117. package/dist/react/filters/logic.mjs +109 -0
  118. package/dist/react/filters/menu-search.mjs +211 -0
  119. package/dist/react/filters/menu.mjs +85 -0
  120. package/dist/react/filters/number.mjs +127 -0
  121. package/dist/react/filters/numbers.d.mts +47 -0
  122. package/dist/react/filters/numbers.mjs +151 -0
  123. package/dist/react/filters/operator.mjs +104 -0
  124. package/dist/react/filters/phone.mjs +104 -0
  125. package/dist/react/filters/popover.d.mts +19 -0
  126. package/dist/react/filters/popover.mjs +153 -0
  127. package/dist/react/filters/rules.d.mts +8 -0
  128. package/dist/react/filters/rules.mjs +55 -0
  129. package/dist/react/filters/sheet.mjs +196 -0
  130. package/dist/react/filters/state.mjs +132 -0
  131. package/dist/react/filters/suggest.d.mts +47 -0
  132. package/dist/react/filters/suggest.mjs +97 -0
  133. package/dist/react/filters/values.mjs +166 -0
  134. package/dist/react/filters/words.d.mts +81 -0
  135. package/dist/react/filters/words.mjs +73 -0
  136. package/dist/react/format.mjs +11 -4
  137. package/dist/react/index.d.mts +11 -5
  138. package/dist/react/index.mjs +8 -4
  139. package/dist/react/messages.d.mts +34 -2
  140. package/dist/react/place.mjs +7 -3
  141. package/dist/react/renderers/index.mjs +65 -3
  142. package/dist/react/renderers/list.mjs +6 -6
  143. package/dist/react/series.d.mts +25 -8
  144. package/dist/react/series.mjs +135 -39
  145. package/dist/react/theme.css +930 -19
  146. package/dist/react/useBoard.d.mts +2 -0
  147. package/dist/react/useDashboard.d.mts +3 -0
  148. package/dist/react/useDashboard.mjs +6 -0
  149. package/dist/react/view-grid.mjs +16 -0
  150. package/dist/recharts/axes.mjs +28 -0
  151. package/dist/recharts/axis.mjs +84 -0
  152. package/dist/recharts/bar.d.mts +7 -0
  153. package/dist/recharts/bar.mjs +140 -0
  154. package/dist/recharts/charts.d.mts +4 -5
  155. package/dist/recharts/charts.mjs +2 -208
  156. package/dist/recharts/index.d.mts +3 -1
  157. package/dist/recharts/index.mjs +4 -1
  158. package/dist/recharts/line.d.mts +2 -0
  159. package/dist/recharts/line.mjs +111 -0
  160. package/dist/recharts/marks.mjs +47 -18
  161. package/dist/recharts/parts.mjs +88 -0
  162. package/dist/recharts/table.mjs +71 -0
  163. package/dist/records-read.mjs +1 -1
  164. package/dist/registry/filter-bar.json +26 -0
  165. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  166. package/package.json +6 -2
  167. package/dist/react/FilterBar.mjs +0 -119
@@ -4,11 +4,17 @@ import { Builder, useBuilder } from "./builder/useBuilder.mjs";
4
4
  import { WidgetBuilder, WidgetBuilderProps } from "./builder/WidgetBuilder.mjs";
5
5
  import { DashboardsError, DashboardsErrorCode } from "./errors.mjs";
6
6
  import { ClientOptions, DashboardsClient, DashboardsServer, TypedCall, createDashboardsClient } from "./client.mjs";
7
- import { DashboardsProvider, DashboardsProviderProps, LinkComponent, LinkProps, useDashboards } from "./context.mjs";
7
+ import { Components, DashboardsProvider, DashboardsProviderProps, LinkComponent, LinkProps, useDashboards } from "./context.mjs";
8
+ import { ENGLISH_FILTERS, FilterWords } from "./filters/words.mjs";
9
+ import { FilterBarOptions, FilterIcon } from "./filters/context.mjs";
10
+ import { FilterBarProps, fieldOf, useControlValues, useFilterFields } from "./filters/hooks.mjs";
11
+ import { FilterBar } from "./filters/bar.mjs";
12
+ import { Popover } from "./filters/popover.mjs";
13
+ import { rules_d_exports } from "./filters/rules.mjs";
8
14
  import { Dashboard, DashboardProps } from "./Dashboard.mjs";
9
15
  import { DashboardList } from "./DashboardList.mjs";
10
- import { ENGLISH } from "./english.mjs";
11
16
  import { Attempt, DraftClosed, DraftEditor, DraftStatus, useDraft } from "./draft.mjs";
17
+ import { ENGLISH } from "./english.mjs";
12
18
  import { DashboardDrillProps, DrillEvent } from "./drill/board.mjs";
13
19
  import { DashboardTile, DashboardTileProps } from "./drill/DashboardTile.mjs";
14
20
  import { DrillPanelProps } from "./drill/DrillPanel.mjs";
@@ -19,7 +25,7 @@ import { DrillChange, DrillHistory, drillFrom } from "./drill/state.mjs";
19
25
  import { DrillController, DrillOptions, useDrill } from "./drill/useDrill.mjs";
20
26
  import { DrillMessages, ENGLISH_DRILL } from "./drill/words.mjs";
21
27
  import { EditBar } from "./EditBar.mjs";
22
- import { FilterBar } from "./FilterBar.mjs";
28
+ import "./FilterBar.mjs";
23
29
  import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
24
30
  import { HistoryPanel, VersionBar } from "./History.mjs";
25
31
  import { CellFormat, Messages } from "./messages.mjs";
@@ -30,7 +36,7 @@ import { NumberTile, TableTile, TileRenderer, TileRendererProps } from "./render
30
36
  import { ListDisplay, ListTile } from "./renderers/list.mjs";
31
37
  import { Moved, Review, useReview } from "./review.mjs";
32
38
  import { ENGLISH_REVIEW, ReviewMessages } from "./review-words.mjs";
33
- import { Drawn, OTHER_KEY, Point, Series, rowAt, toSeries } from "./series.mjs";
39
+ import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen, rowAt, toSeries } from "./series.mjs";
34
40
  import { Tile } from "./Tile.mjs";
35
41
  import { useBoard } from "./useBoard.mjs";
36
42
  import { useDashboard } from "./useDashboard.mjs";
@@ -47,4 +53,4 @@ export interface Register {}
47
53
  export type Item = Register extends {
48
54
  server: infer S;
49
55
  } ? ItemFor<S> : DrillItem;
50
- export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, type Review, type ReviewMessages, ReviewPanel, type Series, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, createDashboardsClient, drillFrom, formatBucket, formatCell, formatInstant, formatTick, plotValue, rowAt, toSeries, useBoard, useBuilder, useDashboard, useDashboards, useDraft, useDrill, useReview, useTiles };
56
+ export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, type Components, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, Popover, type Review, type ReviewMessages, ReviewPanel, type Series, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, createDashboardsClient, drillFrom, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
@@ -6,15 +6,19 @@ import { createDashboardsClient } from "./client.mjs";
6
6
  import { DashboardsProvider, useDashboards } from "./context.mjs";
7
7
  import { Dashboard } from "./Dashboard.mjs";
8
8
  import { DashboardList } from "./DashboardList.mjs";
9
- import { DashboardsError } from "./errors.mjs";
10
9
  import { useDraft } from "./draft.mjs";
11
10
  import { DashboardTile } from "./drill/DashboardTile.mjs";
12
11
  import { DrillPanel } from "./drill/lazy.mjs";
13
12
  import { drillFrom } from "./drill/state.mjs";
14
13
  import { useDrill } from "./drill/useDrill.mjs";
14
+ import { DashboardsError } from "./errors.mjs";
15
15
  import { ENGLISH_DRILL } from "./drill/words.mjs";
16
16
  import { EditBar } from "./EditBar.mjs";
17
- import { FilterBar } from "./FilterBar.mjs";
17
+ import { ENGLISH_FILTERS } from "./filters/words.mjs";
18
+ import { FilterBar } from "./filters/bar.mjs";
19
+ import { fieldOf, useControlValues, useFilterFields } from "./filters/hooks.mjs";
20
+ import { rules_exports } from "./filters/rules.mjs";
21
+ import { Popover } from "./filters/popover.mjs";
18
22
  import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
19
23
  import { HistoryPanel, VersionBar } from "./History.mjs";
20
24
  import { ENGLISH } from "./english.mjs";
@@ -24,9 +28,9 @@ import { NumberTile, TableTile } from "./renderers/index.mjs";
24
28
  import { ListTile } from "./renderers/list.mjs";
25
29
  import { useReview } from "./review.mjs";
26
30
  import { ENGLISH_REVIEW } from "./review-words.mjs";
27
- import { OTHER_KEY, rowAt, toSeries } from "./series.mjs";
31
+ import { OTHER_KEY, lastBucketOpen, rowAt, toSeries } from "./series.mjs";
28
32
  import { Tile } from "./Tile.mjs";
29
33
  import { useBoard } from "./useBoard.mjs";
30
34
  import { useDashboard } from "./useDashboard.mjs";
31
35
  import { useTiles } from "./useTiles.mjs";
32
- export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, ReviewPanel, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, createDashboardsClient, drillFrom, formatBucket, formatCell, formatInstant, formatTick, plotValue, rowAt, toSeries, useBoard, useBuilder, useDashboard, useDashboards, useDraft, useDrill, useReview, useTiles };
36
+ export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, Popover, ReviewPanel, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, createDashboardsClient, drillFrom, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
@@ -1,4 +1,6 @@
1
+ import { BuilderMessages } from "./builder/words.mjs";
1
2
  import { DrillMessages } from "./drill/words.mjs";
3
+ import { FilterWords } from "./filters/words.mjs";
2
4
  import { ReviewMessages } from "./review-words.mjs";
3
5
  import { ENGLISH } from "./english.mjs";
4
6
  import { RelativeRange } from "derive-dashboards/core";
@@ -6,7 +8,7 @@ import { RelativeRange } from "derive-dashboards/core";
6
8
  * Every word the built-in components show. English by default; pass `messages` to the
7
9
  * provider to change any of them, for another language or another house style.
8
10
  */
9
- export type Messages = ReviewMessages & DrillMessages & {
11
+ export type Messages = ReviewMessages & DrillMessages & BuilderMessages & {
10
12
  /** A dimension cell for the values a limit left out. */
11
13
  other: string;
12
14
  /** A dimension cell for every value: a total row. */
@@ -19,6 +21,8 @@ export type Messages = ReviewMessages & DrillMessages & {
19
21
  noAccess: string;
20
22
  noData: string;
21
23
  noRows: string;
24
+ /** Beside the last time bucket while it is still running: its value is not final yet. */
25
+ soFar: string;
22
26
  dashboardFailed: string;
23
27
  /** A dashboard already shown, while the server cannot be reached. */
24
28
  dashboardUnreachable: string;
@@ -32,10 +36,12 @@ export type Messages = ReviewMessages & DrillMessages & {
32
36
  /** How many rows the rows panel shows, and whether there are more. */
33
37
  rowsShowing: (n: number, more: boolean) => string;
34
38
  reset: string;
39
+ /** The filter bar's words; any subset, the rest stay English. */
40
+ filterBar?: Partial<FilterWords>;
35
41
  rowsBehind: (title: string) => string;
36
42
  notFilteredBy: (controls: readonly string[]) => string;
37
43
  firstRows: (count: number) => string;
38
- /** A date-range preset: "Last 7 days", "This month", "Last 3 complete months". */
44
+ /** A date-range preset: "Today", "Last 7 days", "This month", "Last month", "Previous 3 months". */
39
45
  range: (range: RelativeRange) => string;
40
46
  untitledWidget: string;
41
47
  save: string;
@@ -87,6 +93,24 @@ export type Messages = ReviewMessages & DrillMessages & {
87
93
  refOf: Record<"total" | "bucket" | "previous", string>;
88
94
  /** Under Over time: calcs a change of time removed, since they no longer fit. */
89
95
  removedCalcs: (names: readonly string[]) => string;
96
+ /** Under a chart: the values it does not draw, which the table shows. */
97
+ notDrawn: (labels: readonly string[]) => string;
98
+ /** A chart's data table caption, read by screen readers in place of the picture. */
99
+ chartTable: (chart: {
100
+ title: string;
101
+ kind: "line" | "bar";
102
+ points: number;
103
+ }) => string;
104
+ /** The name of a chart's list of points to open; arrow keys move along it. */
105
+ chartPoints: string;
106
+ /** What the builder keeps as it was, though it cannot edit it. */
107
+ keptAside: (kept: {
108
+ display: boolean;
109
+ queries: readonly string[];
110
+ fields: readonly string[];
111
+ }) => string;
112
+ /** A widget the builder cannot open: it has no main query to edit. */
113
+ noMainQuery: (title: string) => string;
90
114
  /** Under the chart kinds: which dashboard filters the widget will follow. */
91
115
  followsFilters: (labels: readonly string[]) => string;
92
116
  /** The grip that reorders a group. */
@@ -98,6 +122,8 @@ export type Messages = ReviewMessages & DrillMessages & {
98
122
  editing: string;
99
123
  publish: string;
100
124
  discard: string;
125
+ /** Leaving edit mode with no changes: nothing to discard, so nothing is asked. */
126
+ doneEditing: string;
101
127
  addWidget: string;
102
128
  addToDashboard: string;
103
129
  /** Screen-reader names of a tile's Edit and Remove, which say which tile. */
@@ -132,6 +158,12 @@ export type Messages = ReviewMessages & DrillMessages & {
132
158
  removedTile: (title: string) => string;
133
159
  /** A tile whose request failed before any answer came. */
134
160
  tileUnreachable: string;
161
+ /** A list (a field's values, the history) that could not be read; with drillRetry beside it. */
162
+ readFailed: string;
163
+ /** A field with no values this viewer can see (or none matching the search). */
164
+ noValues: string;
165
+ /** Copy refused by the browser: the text is shown to copy by hand. */
166
+ copyByHand: string;
135
167
  /** Said once a draft is discarded, as focus returns to Edit. */
136
168
  changesDiscarded: string;
137
169
  /** Draft refusals, in words that say what to do. */
@@ -1,10 +1,14 @@
1
1
  import { useEffect, useRef } from "react";
2
2
  // src/place.ts
3
3
  const overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
4
- /** Where a box is drawn on the 12-column CSS grid. */
4
+ /**
5
+ * Where a box is drawn on the 12-column CSS grid, as variables the theme places it by: a rule
6
+ * (the one-column phone layout, or a host's own) can then place it otherwise, which an inline
7
+ * grid position would always beat.
8
+ */
5
9
  const placeOf = (box) => ({
6
- gridColumn: `${box.x + 1} / span ${box.w}`,
7
- gridRow: `${box.y + 1} / span ${box.h}`
10
+ "--dd-at-column": `${String(box.x + 1)} / span ${String(box.w)}`,
11
+ "--dd-at-row": `${String(box.y + 1)} / span ${String(box.h)}`
8
12
  });
9
13
  /** Brings an element into view when asked, without motion if the viewer asked for none. */
10
14
  function useBringIntoView(wanted) {
@@ -42,14 +42,76 @@ function NumberTile(props) {
42
42
  ]
43
43
  });
44
44
  }
45
- /** The value of the period before, when the answer compares: it opens that period's rows. */
45
+ /** A cell as a number, for the change against the period before. */
46
+ const numberOf = (cell) => {
47
+ if (typeof cell === "number") return cell;
48
+ if (cell !== null && typeof cell === "object" && "v" in cell) return Number(cell.v);
49
+ };
50
+ const PLAIN_DECIMAL = /^-?\d+(\.\d+)?$/u;
51
+ /** A cell's exact digits ("12.50"), when it has them: exact cells, and whole JS numbers. */
52
+ const digitsOf = (cell) => {
53
+ if (typeof cell === "number") return Number.isSafeInteger(cell) ? String(cell) : void 0;
54
+ if (cell !== null && typeof cell === "object" && "v" in cell && typeof cell.v === "string") return PLAIN_DECIMAL.test(cell.v) ? cell.v : void 0;
55
+ };
56
+ /** A decimal as an integer of `scale` fraction digits: "12.5" at scale 2 is 1250n. */
57
+ const scaled = (digits, scale) => {
58
+ const negative = digits.startsWith("-");
59
+ const [whole = "0", fraction = ""] = digits.replace("-", "").split(".");
60
+ return BigInt(`${negative ? "-" : ""}${whole}${fraction.padEnd(scale, "0")}`);
61
+ };
62
+ /** now − was in floats, for values that are not exact digits. */
63
+ function floatDifference(now, was) {
64
+ const [x, y] = [numberOf(now), numberOf(was)];
65
+ if (x === void 0 || y === void 0) return void 0;
66
+ return {
67
+ sign: Math.sign(x - y),
68
+ size: Math.abs(x - y)
69
+ };
70
+ }
71
+ /** a − b of two decimal strings, exactly, as a cell of `type`. */
72
+ function exactDifference(a, b, type) {
73
+ const scale = Math.max(a.split(".")[1]?.length ?? 0, b.split(".")[1]?.length ?? 0);
74
+ const d = scaled(a, scale) - scaled(b, scale);
75
+ const abs = (d < 0n ? -d : d).toString().padStart(scale + 1, "0");
76
+ const v = scale === 0 ? abs : `${abs.slice(0, -scale)}.${abs.slice(-scale)}`;
77
+ return {
78
+ sign: d === 0n ? 0 : d > 0n ? 1 : -1,
79
+ size: {
80
+ t: type,
81
+ v
82
+ }
83
+ };
84
+ }
85
+ /**
86
+ * now − was, exactly when both are exact (a 2^53 amount that moved by 1 moved by 1), else in
87
+ * floats; its sign and its size as a cell to format. Undefined when either is not a number.
88
+ */
89
+ function difference(now, was) {
90
+ const [a, b] = [digitsOf(now), digitsOf(was)];
91
+ if (a === void 0 || b === void 0) return floatDifference(now, was);
92
+ return exactDifference(a, b, typeof now === "object" && now !== null && "t" in now ? now.t : "decimal");
93
+ }
94
+ /** What the period before says: "+17 from 0", "No change from 12", or the bare value when it is not a number. */
95
+ function beforeText(props, column, now, was) {
96
+ const wasText = formatCell(was, column, props);
97
+ const delta = difference(now, was);
98
+ if (delta === void 0) return props.messages.drillBefore(wasText);
99
+ if (delta.sign === 0) return props.messages.beforeSame(wasText);
100
+ const change = `${delta.sign > 0 ? "+" : "−"}${formatCell(delta.size, column, props)}`;
101
+ return props.messages.beforeChange(change, wasText);
102
+ }
103
+ /**
104
+ * The change against the period before, when the answer compares ("+17 from 0"): it opens that
105
+ * period's rows. No value before (a rate over no rows) says nothing, so it is left out.
106
+ */
46
107
  function Before(props) {
47
108
  const { answer, index } = props;
48
109
  const before = answer.compare?.rows[0];
49
110
  const column = answer.columns[index];
50
- if (before === void 0 || column === void 0) return null;
111
+ const was = before?.[index] ?? null;
112
+ if (before === void 0 || column === void 0 || was === null) return null;
51
113
  const marks = props.drill?.props(before, column.id);
52
- const text = props.messages.drillBefore(formatCell(before[index] ?? null, column, props));
114
+ const text = beforeText(props, column, answer.rows[0]?.[index], was);
53
115
  const named = marks === void 0 ? marks : {
54
116
  ...marks,
55
117
  "aria-label": props.messages.drillMark(text)
@@ -22,7 +22,7 @@ function defaults(columns) {
22
22
  * server runs it; `display` names them as the widget's query does. This maps one to the other.
23
23
  */
24
24
  function answerIds(widget) {
25
- const query = widget.queries["main"];
25
+ const query = widget.queries.main;
26
26
  if (query === void 0) return /* @__PURE__ */ new Map();
27
27
  return new Map([
28
28
  ...query.measures.map((entry, i) => [entry.id, `m${String(i + 1)}`]),
@@ -35,12 +35,12 @@ function readDisplay(widget, columns) {
35
35
  const ids = answerIds(widget);
36
36
  const id = (entry) => entry === void 0 ? void 0 : ids.get(entry) ?? entry;
37
37
  const fallback = defaults(columns);
38
- const href = asText(display["href"]);
38
+ const href = asText(display.href);
39
39
  return {
40
- title: id(asText(display["title"])) ?? fallback.title,
41
- subtitle: asList(display["subtitle"])?.map((entry) => id(entry) ?? entry) ?? fallback.subtitle,
42
- avatar: id(asText(display["avatar"])),
43
- meta: id(asText(display["meta"])) ?? fallback.meta,
40
+ title: id(asText(display.title)) ?? fallback.title,
41
+ subtitle: asList(display.subtitle)?.map((entry) => id(entry) ?? entry) ?? fallback.subtitle,
42
+ avatar: id(asText(display.avatar)),
43
+ meta: id(asText(display.meta)) ?? fallback.meta,
44
44
  href: href?.replaceAll(/\{([^}]+)\}/gu, (_, entry) => `{${id(entry) ?? entry}}`)
45
45
  };
46
46
  }
@@ -1,32 +1,41 @@
1
1
  import { CellFormat } from "./messages.mjs";
2
- import { ResultColumn, TileAnswer } from "derive-dashboards/core";
3
- /** One point of a chart: its x label and a number per series key. */
2
+ import { Receipt, ResultColumn, TileAnswer } from "derive-dashboards/core";
3
+ /** One point of a chart: its x label, its place (`#`, never an entry id) and a number per series key. */
4
4
  export type Point = {
5
5
  x: string;
6
6
  } & Record<string, number | string | null>;
7
+ /**
8
+ * A drawn series: its key in each point, its label and the column it reads. `axis` is the side
9
+ * of the chart its scale is read on: values in another unit than the first get the right axis.
10
+ */
7
11
  export type Series = {
8
12
  key: string;
9
13
  label: string;
10
14
  column: ResultColumn;
15
+ axis: "left" | "right";
11
16
  };
12
17
  /** The series key a dimension's Other draws as. */
13
18
  export declare const OTHER_KEY = "other";
14
19
  /**
15
- * Chart data from an answer. The first non-value column is the x axis (the time bucket when
16
- * there is one). With a second key column, the first value is split into one series per
17
- * value of it, and Other in that column is one more series; otherwise every value column is
18
- * its own series. Other on the x axis is one more point; totals are not drawn.
20
+ * Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
21
+ * when there is one) and, after it, what splits the series; value columns are what is drawn.
22
+ * With split keys, the first value (the first calc, when there are calcs) becomes one series per
23
+ * combination of the keys ("Design · High"), Other one more. Without, every value is a series.
24
+ * Values in a second unit are read on a right axis; a third unit, or more values than a split can
25
+ * draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
26
+ * keyed by raw values, so two that read alike stay apart. Totals are not drawn.
19
27
  */
20
28
  export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): Drawn;
21
29
  /**
22
30
  * What a chart draws, and the way back from any chart kit's point to the answer's row:
23
31
  * `rowAt(point, seriesKey)` gives the row's index in `answer.rows` (for a drill), or undefined
24
- * for a point no row stands behind.
32
+ * for a point no row stands behind. `notDrawn` lists the values the chart leaves to the table.
25
33
  */
26
34
  export type Drawn = {
27
35
  points: Point[];
28
36
  series: Series[];
29
37
  split: boolean;
38
+ notDrawn: ResultColumn[];
30
39
  rowAt: (point: number | Point, seriesKey: string) => number | undefined;
31
40
  };
32
41
  /**
@@ -34,4 +43,12 @@ export type Drawn = {
34
43
  * point) and the series key; undefined for a point no row stands behind. Pass it to
35
44
  * `drill.open(row, series.column.id)` to open what is behind the point.
36
45
  */
37
- export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
46
+ export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
47
+ /**
48
+ * Whether the answer's last time bucket is still running: the range ends before the bucket
49
+ * does, as this week does on its Monday. Its value is not final, so a chart marks it rather
50
+ * than draw it as a fall.
51
+ */
52
+ export declare function lastBucketOpen(answer: Pick<TileAnswer, "columns" | "rows"> & {
53
+ receipt: Pick<Receipt, "range" | "calendar">;
54
+ }): boolean;
@@ -6,11 +6,20 @@ const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
6
6
  /** The series key a dimension's Other draws as. */
7
7
  const OTHER_KEY = "other";
8
8
  const isAll = (cell) => isMark(cell) && cell.mark === "all";
9
+ /** What a value is read against: two columns share an axis only when this is equal. */
10
+ const scaleOf = (c) => JSON.stringify([
11
+ c.unit ?? null,
12
+ c.format ?? null,
13
+ c.fraction ?? null
14
+ ]);
9
15
  /**
10
- * Chart data from an answer. The first non-value column is the x axis (the time bucket when
11
- * there is one). With a second key column, the first value is split into one series per
12
- * value of it, and Other in that column is one more series; otherwise every value column is
13
- * its own series. Other on the x axis is one more point; totals are not drawn.
16
+ * Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
17
+ * when there is one) and, after it, what splits the series; value columns are what is drawn.
18
+ * With split keys, the first value (the first calc, when there are calcs) becomes one series per
19
+ * combination of the keys ("Design · High"), Other one more. Without, every value is a series.
20
+ * Values in a second unit are read on a right axis; a third unit, or more values than a split can
21
+ * draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
22
+ * keyed by raw values, so two that read alike stay apart. Totals are not drawn.
14
23
  */
15
24
  function toSeries(answer, format = {}) {
16
25
  const at = /* @__PURE__ */ new Map();
@@ -25,11 +34,15 @@ function toSeries(answer, format = {}) {
25
34
  }
26
35
  };
27
36
  }
28
- function drawSeries(answer, format, seen) {
29
- const keyCount = answer.columns.filter((c) => !isValue(c)).length;
30
- const all = answer.columns.slice(keyCount);
37
+ /** The values to draw: calcs when there are any (what the widget was built to see), else measures. */
38
+ function valuesOf(columns) {
39
+ const all = columns.filter((c) => isValue(c));
31
40
  const calcs = all.filter((c) => c.id.startsWith("c"));
32
- const values = calcs.length > 0 ? calcs : all;
41
+ return calcs.length > 0 ? calcs : all;
42
+ }
43
+ function drawSeries(answer, format, seen) {
44
+ const keys = answer.columns.flatMap((c, i) => isValue(c) ? [] : [i]);
45
+ const values = valuesOf(answer.columns);
33
46
  const rows = answer.rows.map((row, index) => ({
34
47
  row,
35
48
  index
@@ -39,57 +52,140 @@ function drawSeries(answer, format, seen) {
39
52
  const words = format.messages ?? ENGLISH;
40
53
  return column === void 0 ? words.empty : words.drillNone(column.label);
41
54
  };
42
- const xOf = (row) => keyText(row[0] ?? null, answer.columns[0]);
43
- if (keyCount < 2) {
44
- const series = values.map((column) => ({
45
- key: column.id,
46
- label: column.label,
47
- column
48
- }));
49
- return {
50
- points: rows.map(({ row, index }, i) => {
51
- seen(i, "*", index);
52
- return {
53
- x: keyCount === 0 ? "" : xOf(row),
54
- ...Object.fromEntries(values.map((c) => [c.id, plotValue(row[answer.columns.indexOf(c)] ?? null)]))
55
- };
56
- }),
57
- series,
58
- split: false
59
- };
60
- }
61
- const first = values[0];
55
+ const shape = {
56
+ answer,
57
+ keys,
58
+ keyText,
59
+ seen
60
+ };
61
+ return keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
62
+ }
63
+ /** The x label of a row, from its first key. */
64
+ const xOf = (shape, row) => {
65
+ const at = shape.keys[0];
66
+ return at === void 0 ? "" : shape.keyText(row[at] ?? null, shape.answer.columns[at]);
67
+ };
68
+ /** One series per value: the first unit on the left axis, a second on the right, a third not drawn. */
69
+ function plainSeries(rows, values, shape) {
70
+ const scales = [...new Set(values.map((c) => scaleOf(c)))];
71
+ const side = (c) => scales.indexOf(scaleOf(c));
72
+ const drawn = values.filter((c) => side(c) < 2);
73
+ const series = drawn.map((column) => ({
74
+ key: column.id,
75
+ label: column.label,
76
+ column,
77
+ axis: side(column) === 0 ? "left" : "right"
78
+ }));
79
+ return {
80
+ points: rows.map(({ row, index }, i) => {
81
+ shape.seen(i, "*", index);
82
+ const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
83
+ return {
84
+ x: xOf(shape, row),
85
+ "#": i,
86
+ ...Object.fromEntries(cells)
87
+ };
88
+ }),
89
+ series,
90
+ split: false,
91
+ notDrawn: values.filter((c) => side(c) >= 2)
92
+ };
93
+ }
94
+ /** One value split into a series per combination of the keys after the first; other values are not drawn. */
95
+ function splitSeries(rows, values, shape) {
96
+ const [first, ...rest] = values;
62
97
  if (first === void 0) return {
63
98
  points: [],
64
99
  series: [],
65
- split: true
100
+ split: true,
101
+ notDrawn: []
66
102
  };
103
+ const { answer, keys, keyText } = shape;
104
+ const valueAt = answer.columns.indexOf(first);
67
105
  const byX = /* @__PURE__ */ new Map();
68
106
  const names = /* @__PURE__ */ new Map();
69
107
  for (const { row, index } of rows) {
70
- const split = row[1] ?? null;
71
- const key = isMark(split) ? split.mark : `s${JSON.stringify(split)}`;
72
- names.set(key, keyText(split, answer.columns[1]));
73
- const point = byX.get(xOf(row)) ?? { x: xOf(row) };
74
- point[key] = plotValue(row[keyCount] ?? null);
75
- byX.set(xOf(row), point);
76
- seen([...byX.keys()].indexOf(xOf(row)), key, index);
108
+ const splitCells = keys.slice(1).map((i) => row[i] ?? null);
109
+ const key = splitKey(splitCells);
110
+ const label = splitCells.map((cell, i) => keyText(cell, answer.columns[keys[i + 1] ?? -1]));
111
+ names.set(key, label.join(" · "));
112
+ const xKey = JSON.stringify(row[keys[0] ?? 0] ?? null);
113
+ const point = byX.get(xKey) ?? {
114
+ x: xOf(shape, row),
115
+ "#": byX.size
116
+ };
117
+ point[key] = plotValue(row[valueAt] ?? null);
118
+ byX.set(xKey, point);
119
+ shape.seen(Number(point["#"]), key, index);
77
120
  }
78
121
  const series = [...names].map(([key, label]) => ({
79
122
  key,
80
123
  label,
81
- column: first
124
+ column: first,
125
+ axis: "left"
82
126
  })).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
83
127
  return {
84
128
  points: [...byX.values()],
85
129
  series,
86
- split: true
130
+ split: true,
131
+ notDrawn: rest
87
132
  };
88
133
  }
134
+ /** A series' key from its split cells: Other stays "other", any value is its raw JSON. */
135
+ function splitKey(cells) {
136
+ const [only] = cells;
137
+ if (cells.length === 1 && only !== void 0 && isMark(only)) return only.mark;
138
+ return `s${JSON.stringify(cells.length === 1 ? only ?? null : cells)}`;
139
+ }
89
140
  /**
90
141
  * The row of the answer behind a point of any chart kit's series, by the point's place (or the
91
142
  * point) and the series key; undefined for a point no row stands behind. Pass it to
92
143
  * `drill.open(row, series.column.id)` to open what is behind the point.
93
144
  */
94
145
  const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
95
- export { OTHER_KEY, rowAt, toSeries };
146
+ const DAY = 864e5;
147
+ const DAYS = {
148
+ day: 1,
149
+ week: 7
150
+ };
151
+ const MONTHS = {
152
+ month: 1,
153
+ quarter: 3,
154
+ year: 12
155
+ };
156
+ /** A calendar date ("2026-11-16") as the UTC midnight that names it. */
157
+ const dateOf = (text) => {
158
+ const [year = 0, month = 1, day = 1] = text.slice(0, 10).split("-").map(Number);
159
+ return Date.UTC(year, month - 1, day);
160
+ };
161
+ /** Where a bucket that starts on a calendar date ends, at its grain; none for a grain it cannot step. */
162
+ function bucketEnd(start, grain) {
163
+ const days = DAYS[grain];
164
+ if (days !== void 0) return start + days * DAY;
165
+ const months = MONTHS[grain];
166
+ if (months === void 0) return void 0;
167
+ const at = new Date(start);
168
+ return Date.UTC(at.getUTCFullYear(), at.getUTCMonth() + months, at.getUTCDate());
169
+ }
170
+ /** An instant as the calendar day it falls on in a zone, named as a bucket names its day. */
171
+ const dayIn = (instant, timeZone) => new Intl.DateTimeFormat("en-CA", {
172
+ timeZone,
173
+ year: "numeric",
174
+ month: "2-digit",
175
+ day: "2-digit"
176
+ }).format(new Date(instant));
177
+ /**
178
+ * Whether the answer's last time bucket is still running: the range ends before the bucket
179
+ * does, as this week does on its Monday. Its value is not final, so a chart marks it rather
180
+ * than draw it as a fall.
181
+ */
182
+ function lastBucketOpen(answer) {
183
+ const grain = answer.columns[0]?.grain;
184
+ const to = answer.receipt.range?.to;
185
+ const last = answer.rows.findLast((row) => typeof row[0] === "string")?.[0];
186
+ if (grain === void 0 || to === void 0 || typeof last !== "string") return false;
187
+ if (!/^\d{4}-\d{2}-\d{2}/u.test(last)) return false;
188
+ const end = bucketEnd(dateOf(last), grain);
189
+ return end !== void 0 && dateOf(dayIn(to, answer.receipt.calendar.timezone)) + DAY < end;
190
+ }
191
+ export { OTHER_KEY, lastBucketOpen, rowAt, toSeries };