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.
- package/dist/charts/kinds/area-marks.mjs +2 -1
- package/dist/charts/kinds/funnel-words.mjs +1 -1
- package/dist/charts/kinds/grid-marks.mjs +9 -4
- package/dist/charts/theme.d.mts +13 -13
- package/dist/charts/theme.mjs +17 -14
- package/dist/charts-react/Overlay.mjs +1 -0
- package/dist/charts-react/chart-unlayered.css +1 -107
- package/dist/charts-react/chart.css +1 -121
- package/dist/charts-react/tip-place.mjs +30 -15
- package/dist/core/document/display-comparisons.mjs +49 -0
- package/dist/core/document/display-validation.d.mts +12 -0
- package/dist/core/document/display-validation.mjs +56 -0
- package/dist/core/document/display.d.mts +6 -12
- package/dist/core/document/display.mjs +23 -48
- package/dist/core/engine/dialect.d.mts +2 -0
- package/dist/core/engine/index.mjs +1 -1
- package/dist/core/engine/levels.mjs +33 -1
- package/dist/core/engine/postgres.mjs +1 -0
- package/dist/core/engine/rank.mjs +1 -1
- package/dist/core/engine/reader.d.mts +4 -0
- package/dist/core/engine/sql-partition.mjs +45 -0
- package/dist/core/engine/sql-reads.mjs +4 -1
- package/dist/core/engine/statement.mjs +4 -4
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +1 -1
- package/dist/core/error/codes.mjs +1 -1
- package/dist/core/index.d.mts +6 -5
- package/dist/core/index.mjs +8 -7
- package/dist/core/model/validate/fields.mjs +1 -1
- package/dist/core/query/drill/compose.d.mts +2 -0
- package/dist/core/query/drill/compose.mjs +1 -1
- package/dist/core/query/drill/synthetic.mjs +1 -1
- package/dist/core/query/drill/types.d.mts +7 -0
- package/dist/core/query/drill/types.mjs +3 -1
- package/dist/core/schema/answers.d.mts +1176 -362
- package/dist/core/schema/drill-answers.mjs +19 -1
- package/dist/core/schema/drill.d.mts +21 -6
- package/dist/core/schema/drill.mjs +7 -1
- package/dist/core/schema/tools.mjs +13 -0
- package/dist/core/time/index.d.mts +2 -2
- package/dist/core/time/text-time.d.mts +9 -2
- package/dist/core/time/text-time.mjs +18 -3
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +22 -2
- package/dist/dashboard-documents.d.mts +8 -0
- package/dist/dashboard-documents.mjs +52 -0
- package/dist/drill-access.mjs +40 -3
- package/dist/drill-comparison.mjs +71 -0
- package/dist/drill-crumbs.mjs +21 -2
- package/dist/drill-group-seal.mjs +13 -0
- package/dist/drill-open.mjs +7 -1
- package/dist/drill-seal.mjs +4 -6
- package/dist/drill-views.mjs +5 -13
- package/dist/drill.mjs +28 -58
- package/dist/editing.mjs +1 -1
- package/dist/endpoints/drill.mjs +2 -3
- package/dist/endpoints/index.d.mts +20 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +6 -27
- package/dist/llms.txt +1 -1
- package/dist/react/Cell.mjs +2 -2
- package/dist/react/DashboardList.mjs +3 -3
- package/dist/react/Editing.mjs +3 -3
- package/dist/react/Header.mjs +2 -2
- package/dist/react/History.mjs +3 -3
- package/dist/react/Parts.mjs +2 -2
- package/dist/react/RowBody.d.mts +2 -4
- package/dist/react/RowBody.mjs +14 -39
- package/dist/react/Tile.mjs +4 -5
- package/dist/react/builder/FilterEditor.mjs +2 -2
- package/dist/react/builder/Picker.mjs +3 -3
- package/dist/react/builder/RangeEditor.mjs +3 -3
- package/dist/react/builder/Time.mjs +3 -3
- package/dist/react/builder/Values.mjs +2 -2
- package/dist/react/builder/WidgetBuilder.mjs +2 -2
- package/dist/react/drill/Bars.mjs +34 -38
- package/dist/react/drill/Comparison.mjs +204 -0
- package/dist/react/drill/Controls.mjs +8 -12
- package/dist/react/drill/DrillDrawer.mjs +42 -0
- package/dist/react/drill/DrillPanel.mjs +61 -41
- package/dist/react/drill/Header.mjs +65 -35
- package/dist/react/drill/ItemLink.mjs +40 -0
- package/dist/react/drill/Items.d.mts +2 -1
- package/dist/react/drill/Items.mjs +126 -99
- package/dist/react/drill/ItemsBody.mjs +38 -0
- package/dist/react/drill/ItemsFoot.mjs +24 -19
- package/dist/react/drill/Notes.mjs +23 -13
- package/dist/react/drill/PanelBody.mjs +7 -25
- package/dist/react/drill/RecordRow.mjs +47 -0
- package/dist/react/drill/Trend.mjs +186 -0
- package/dist/react/drill/board.mjs +21 -11
- package/dist/react/drill/drawer-context.mjs +5 -0
- package/dist/react/drill/item-parts.mjs +53 -35
- package/dist/react/drill/item-type.d.mts +2 -2
- package/dist/react/drill/lazy.d.mts +1 -4
- package/dist/react/drill/lazy.mjs +29 -11
- package/dist/react/drill/panel-focus.mjs +18 -7
- package/dist/react/drill/props.d.mts +7 -1
- package/dist/react/drill/props.mjs +39 -8
- package/dist/react/drill/record-page.mjs +61 -0
- package/dist/react/drill/state.mjs +17 -2
- package/dist/react/drill/trend-touch.mjs +33 -0
- package/dist/react/drill/useDrill.d.mts +3 -3
- package/dist/react/drill/useDrill.mjs +35 -15
- package/dist/react/drill/words.d.mts +14 -0
- package/dist/react/drill/words.mjs +19 -7
- package/dist/react/english.d.mts +1 -0
- package/dist/react/english.mjs +1 -0
- package/dist/react/filters/chip.mjs +2 -2
- package/dist/react/filters/menu-search.mjs +5 -5
- package/dist/react/filters/menu.mjs +2 -2
- package/dist/react/filters/number.mjs +2 -2
- package/dist/react/filters/operator.mjs +2 -2
- package/dist/react/filters/phone.mjs +2 -2
- package/dist/react/filters/values.mjs +4 -4
- package/dist/react/format-time.d.mts +1 -0
- package/dist/react/format-time.mjs +39 -33
- package/dist/react/format.mjs +10 -1
- package/dist/react/renderers/list.mjs +8 -10
- package/dist/react/renderers/table-cells.mjs +38 -9
- package/dist/react/renderers/table-measure.mjs +2 -0
- package/dist/react/renderers/table-row.mjs +64 -7
- package/dist/react/renderers/table-sort.mjs +2 -8
- package/dist/react/renderers/table.mjs +16 -15
- package/dist/react/theme-unlayered.css +1 -3148
- package/dist/react/theme.css +1 -3150
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +4 -2
- package/dist/store/apply.mjs +2 -2
- package/dist/store/editor.mjs +2 -2
- package/dist/store/writer.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useDashboards } from "../context.mjs";
|
|
2
|
-
import { formatCell } from "../format.mjs";
|
|
3
1
|
import { Bars } from "./Bars.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { Comparison } from "./Comparison.mjs";
|
|
3
|
+
import { FieldPicker, Operands } from "./Controls.mjs";
|
|
4
|
+
import { ItemsBody } from "./ItemsBody.mjs";
|
|
6
5
|
import { ItemsFoot } from "./ItemsFoot.mjs";
|
|
7
6
|
import { Failed, SeeRows } from "./PanelStates.mjs";
|
|
8
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -11,6 +10,10 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
11
10
|
function Body({ d, props }) {
|
|
12
11
|
const shown = d.shown;
|
|
13
12
|
if (shown === void 0) return null;
|
|
13
|
+
if (shown.by === "comparison") return d.answer && /* @__PURE__ */ jsx(Comparison, {
|
|
14
|
+
answer: d.answer,
|
|
15
|
+
view: shown
|
|
16
|
+
});
|
|
14
17
|
if (shown.by === "items") return /* @__PURE__ */ jsx(ItemsBody, {
|
|
15
18
|
d,
|
|
16
19
|
view: shown,
|
|
@@ -23,27 +26,6 @@ function Body({ d, props }) {
|
|
|
23
26
|
onOpen: d.open
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
|
-
/** Items: the Only filter, a percentile's marker row, then the rows. */
|
|
27
|
-
function ItemsBody(a) {
|
|
28
|
-
const format = useDashboards();
|
|
29
|
-
const { d, view, props } = a;
|
|
30
|
-
const p = view.percentile;
|
|
31
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
32
|
-
/* @__PURE__ */ jsx(OnlyToggle, { d }),
|
|
33
|
-
p === void 0 || d.summary === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
34
|
-
className: "dd-drill-marker",
|
|
35
|
-
children: format.messages.drillPercentile(p, formatCell(d.summary.value, d.summary.column, format))
|
|
36
|
-
}),
|
|
37
|
-
/* @__PURE__ */ jsx(Items, {
|
|
38
|
-
view,
|
|
39
|
-
items: d.items.items,
|
|
40
|
-
options: props,
|
|
41
|
-
noun: d.summary?.noun?.one,
|
|
42
|
-
timeZone: d.summary?.receipt.calendar.timezone,
|
|
43
|
-
Empty: props.components?.Empty
|
|
44
|
-
})
|
|
45
|
-
] });
|
|
46
|
-
}
|
|
47
29
|
/** A failed read, or the panel loading, or its body. */
|
|
48
30
|
function Main({ d, props, close }) {
|
|
49
31
|
if (d.status === "error") return /* @__PURE__ */ jsx(Failed, {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isNumberType } from "../columns.mjs";
|
|
2
|
+
import { useDashboards } from "../context.mjs";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/drill/RecordRow.tsx
|
|
5
|
+
function RecordRow(props) {
|
|
6
|
+
const { parts, field } = props;
|
|
7
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("span", {
|
|
8
|
+
className: "dd-record-name",
|
|
9
|
+
children: [
|
|
10
|
+
/* @__PURE__ */ jsx("strong", { children: parts.title }),
|
|
11
|
+
props.opens ? /* @__PURE__ */ jsxs("span", {
|
|
12
|
+
className: "dd-direction",
|
|
13
|
+
"aria-hidden": "true",
|
|
14
|
+
children: [" ", "›"]
|
|
15
|
+
}) : null,
|
|
16
|
+
parts.value === void 0 ? null : /* @__PURE__ */ jsxs("small", { children: [/* @__PURE__ */ jsxs("span", {
|
|
17
|
+
className: "dd-sr-only",
|
|
18
|
+
children: [props.date, " "]
|
|
19
|
+
}), parts.value] }),
|
|
20
|
+
parts.badge === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
21
|
+
className: "dd-item-badge",
|
|
22
|
+
"data-tone": parts.badge.tone,
|
|
23
|
+
children: parts.badge.text
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
}), field === void 0 ? null : /* @__PURE__ */ jsxs("span", {
|
|
27
|
+
className: "dd-record-field",
|
|
28
|
+
"data-numeric": isNumberType(field.type),
|
|
29
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
30
|
+
className: "dd-sr-only",
|
|
31
|
+
children: [field.label, " "]
|
|
32
|
+
}), props.value]
|
|
33
|
+
})] });
|
|
34
|
+
}
|
|
35
|
+
function RecordHeading(props) {
|
|
36
|
+
const { messages } = useDashboards();
|
|
37
|
+
const name = props.view.columns.find((c) => c.member === props.view.title)?.label ?? props.noun ?? messages.drillItem;
|
|
38
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
39
|
+
className: "dd-record-heading",
|
|
40
|
+
"aria-hidden": "true",
|
|
41
|
+
children: [/* @__PURE__ */ jsx("span", { children: name }), props.field === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
42
|
+
"data-numeric": isNumberType(props.field.type),
|
|
43
|
+
children: props.field.label
|
|
44
|
+
})]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export { RecordHeading, RecordRow };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { useTouchPreview } from "./trend-touch.mjs";
|
|
2
|
+
import { ENGLISH_DRILL, RECORD_PAGES } from "./words.mjs";
|
|
3
|
+
import { memo, useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/drill/Trend.tsx
|
|
6
|
+
const periodName = (bar) => bar.note === void 0 ? bar.name : `${bar.name} · ${bar.note}`;
|
|
7
|
+
/** Only the previously focused mark and the newly focused one change when an arrow is pressed. */
|
|
8
|
+
const Mark = memo(function Mark(props) {
|
|
9
|
+
const { bar, selection, index } = props;
|
|
10
|
+
const inspect = (event) => {
|
|
11
|
+
if (event.pointerType !== "touch") props.onHover(index);
|
|
12
|
+
};
|
|
13
|
+
const label = `${periodName(bar)}, ${bar.text}`;
|
|
14
|
+
const column = /* @__PURE__ */ jsx("span", {
|
|
15
|
+
className: "dd-drill-column",
|
|
16
|
+
"data-negative": bar.negative,
|
|
17
|
+
"data-partial": bar.note !== void 0 || void 0,
|
|
18
|
+
style: { blockSize: `${Math.max(bar.width, 2)}%` }
|
|
19
|
+
});
|
|
20
|
+
return /* @__PURE__ */ jsx("li", {
|
|
21
|
+
"data-index": index,
|
|
22
|
+
"data-active": props.active,
|
|
23
|
+
onFocus: () => {
|
|
24
|
+
props.onFocus(index);
|
|
25
|
+
},
|
|
26
|
+
onPointerEnter: inspect,
|
|
27
|
+
onPointerMove: inspect,
|
|
28
|
+
onPointerLeave: () => {
|
|
29
|
+
props.onHover();
|
|
30
|
+
},
|
|
31
|
+
children: selection === void 0 ? /* @__PURE__ */ jsx("span", {
|
|
32
|
+
role: "img",
|
|
33
|
+
"aria-label": label,
|
|
34
|
+
tabIndex: props.tabIndex,
|
|
35
|
+
children: column
|
|
36
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
37
|
+
type: "button",
|
|
38
|
+
"aria-label": label,
|
|
39
|
+
tabIndex: props.tabIndex,
|
|
40
|
+
onClick: () => {
|
|
41
|
+
props.onOpen(selection);
|
|
42
|
+
},
|
|
43
|
+
children: column
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const Marks = memo(function Marks(props) {
|
|
48
|
+
return props.bars.map((period, i) => /* @__PURE__ */ jsx(Mark, {
|
|
49
|
+
...period,
|
|
50
|
+
index: i,
|
|
51
|
+
active: i === props.active,
|
|
52
|
+
tabIndex: i === props.entry ? 0 : -1,
|
|
53
|
+
onOpen: props.onOpen,
|
|
54
|
+
onHover: props.onHover,
|
|
55
|
+
onFocus: props.onFocus
|
|
56
|
+
}, i));
|
|
57
|
+
});
|
|
58
|
+
function move(event, entry, last) {
|
|
59
|
+
const backward = getComputedStyle(event.currentTarget).direction === "rtl" ? 1 : -1;
|
|
60
|
+
const next = {
|
|
61
|
+
ArrowLeft: entry + backward,
|
|
62
|
+
ArrowRight: entry - backward,
|
|
63
|
+
Home: 0,
|
|
64
|
+
End: last
|
|
65
|
+
}[event.key];
|
|
66
|
+
if (next === void 0) return false;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
event.currentTarget.children[Math.max(0, Math.min(last, next))]?.querySelector("[tabindex]")?.focus();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
function usePeriods(bars) {
|
|
72
|
+
const [hover, setHover] = useState();
|
|
73
|
+
const [focus, setFocus] = useState();
|
|
74
|
+
const [entry, setEntry] = useState();
|
|
75
|
+
const last = bars.length - 1;
|
|
76
|
+
const complete = useMemo(() => bars.findLastIndex(({ bar }) => bar.note === void 0), [bars]);
|
|
77
|
+
const initial = complete < 0 ? last : complete;
|
|
78
|
+
const at = Math.min(focus ?? initial, last);
|
|
79
|
+
return {
|
|
80
|
+
active: bars[Math.min(hover ?? at, last)]?.bar,
|
|
81
|
+
at,
|
|
82
|
+
hovering: hover !== void 0,
|
|
83
|
+
entry: Math.min(entry ?? initial, last),
|
|
84
|
+
setHover,
|
|
85
|
+
setFocus,
|
|
86
|
+
focusMark: useCallback((index) => {
|
|
87
|
+
setHover(void 0);
|
|
88
|
+
setEntry(index);
|
|
89
|
+
setFocus(index);
|
|
90
|
+
}, [])
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function Axis({ bars }) {
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
95
|
+
className: "dd-drill-axis",
|
|
96
|
+
"aria-hidden": "true",
|
|
97
|
+
children: [/* @__PURE__ */ jsx("span", { children: bars[0]?.bar.name }), bars.length > 1 && /* @__PURE__ */ jsx("span", { children: bars.at(-1)?.bar.name })]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function TrendPage(props) {
|
|
101
|
+
const p = usePeriods(props.bars);
|
|
102
|
+
const { selected, handlers } = useTouchPreview();
|
|
103
|
+
const touched = selected === null ? void 0 : props.bars[selected];
|
|
104
|
+
const selection = touched?.bar === p.active ? touched?.selection : void 0;
|
|
105
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
106
|
+
className: "dd-drill-trend",
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsxs("figcaption", { children: [
|
|
109
|
+
p.active && periodName(p.active),
|
|
110
|
+
" ",
|
|
111
|
+
/* @__PURE__ */ jsx("strong", { children: p.active?.text }),
|
|
112
|
+
selection !== void 0 && /* @__PURE__ */ jsx("button", {
|
|
113
|
+
type: "button",
|
|
114
|
+
className: "dd-button dd-quiet",
|
|
115
|
+
onClick: () => {
|
|
116
|
+
props.onOpen(selection);
|
|
117
|
+
},
|
|
118
|
+
children: props.details ?? ENGLISH_DRILL.drillHint
|
|
119
|
+
})
|
|
120
|
+
] }),
|
|
121
|
+
/* @__PURE__ */ jsx("ol", {
|
|
122
|
+
className: "dd-drill-columns",
|
|
123
|
+
style: { columnGap: `min(2px, ${30 / Math.max(1, props.bars.length)}%)` },
|
|
124
|
+
"data-hovering": p.hovering || void 0,
|
|
125
|
+
...handlers,
|
|
126
|
+
onBlur: (e) => {
|
|
127
|
+
if (!e.currentTarget.contains(e.relatedTarget) && selected === null) p.setFocus(void 0);
|
|
128
|
+
},
|
|
129
|
+
onKeyDown: (e) => {
|
|
130
|
+
if (move(e, p.entry, props.bars.length - 1)) p.setHover(void 0);
|
|
131
|
+
},
|
|
132
|
+
children: /* @__PURE__ */ jsx(Marks, {
|
|
133
|
+
...props,
|
|
134
|
+
active: p.at,
|
|
135
|
+
entry: p.entry,
|
|
136
|
+
onHover: p.setHover,
|
|
137
|
+
onFocus: p.focusMark
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
/* @__PURE__ */ jsx(Axis, { bars: props.bars })
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const PAGE_SIZE = 400;
|
|
145
|
+
/** Show the latest periods first. Longer answers remain browsable at their original grain and scale. */
|
|
146
|
+
function Columns(props) {
|
|
147
|
+
const [back, setBack] = useState(0);
|
|
148
|
+
const last = Math.max(0, Math.ceil(props.bars.length / PAGE_SIZE) - 1);
|
|
149
|
+
const page = Math.max(0, last - back);
|
|
150
|
+
const end = props.bars.length - (last - page) * PAGE_SIZE;
|
|
151
|
+
const bars = useMemo(() => last === 0 ? props.bars : props.bars.slice(Math.max(0, end - PAGE_SIZE), end), [
|
|
152
|
+
props.bars,
|
|
153
|
+
end,
|
|
154
|
+
last
|
|
155
|
+
]);
|
|
156
|
+
const words = props.pages ?? RECORD_PAGES;
|
|
157
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
158
|
+
/* @__PURE__ */ jsx(TrendPage, {
|
|
159
|
+
...props,
|
|
160
|
+
bars
|
|
161
|
+
}, page),
|
|
162
|
+
props.limitNote !== void 0 && /* @__PURE__ */ jsx("p", {
|
|
163
|
+
className: "dd-tile-note",
|
|
164
|
+
children: props.limitNote
|
|
165
|
+
}),
|
|
166
|
+
last > 0 && /* @__PURE__ */ jsxs("div", {
|
|
167
|
+
className: "dd-record-pager",
|
|
168
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
169
|
+
type: "button",
|
|
170
|
+
"aria-disabled": page === 0,
|
|
171
|
+
onClick: () => {
|
|
172
|
+
setBack(last - Math.max(0, page - 1));
|
|
173
|
+
},
|
|
174
|
+
children: words.previous
|
|
175
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
176
|
+
type: "button",
|
|
177
|
+
"aria-disabled": page === last,
|
|
178
|
+
onClick: () => {
|
|
179
|
+
setBack(last - Math.min(last, page + 1));
|
|
180
|
+
},
|
|
181
|
+
children: words.next
|
|
182
|
+
})]
|
|
183
|
+
})
|
|
184
|
+
] });
|
|
185
|
+
}
|
|
186
|
+
export { Columns };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { DrillDrawer } from "./DrillDrawer.mjs";
|
|
1
3
|
import { DrillHostContext } from "./host.mjs";
|
|
2
4
|
import { DrillPanel } from "./lazy.mjs";
|
|
3
5
|
import { useMemo, useRef } from "react";
|
|
@@ -10,7 +12,7 @@ function documentOf(source) {
|
|
|
10
12
|
/**
|
|
11
13
|
* The dashboard's drill host: where a drill into each tile starts (this dashboard, the picks
|
|
12
14
|
* set, the document shown) and what a click does: tell the host (`onDrill`), then, unless it
|
|
13
|
-
* took the drill, open
|
|
15
|
+
* took the drill, open its drawer as a step Back undoes. Null when drilling is off.
|
|
14
16
|
*/
|
|
15
17
|
function useDrillHost(dashboardId, board, props) {
|
|
16
18
|
const latest = useRef({
|
|
@@ -54,18 +56,26 @@ function useDrillHost(dashboardId, board, props) {
|
|
|
54
56
|
props.drill
|
|
55
57
|
]);
|
|
56
58
|
}
|
|
57
|
-
/**
|
|
59
|
+
/** Open details over the board so the originating chart keeps its scale and position. */
|
|
58
60
|
function DrillSide({ board, props }) {
|
|
61
|
+
const { messages } = useDashboards();
|
|
59
62
|
const { drill } = board.view;
|
|
60
63
|
if (drill === void 0 || drill.origin.kind !== "dashboard") return null;
|
|
61
|
-
const
|
|
62
|
-
return /* @__PURE__ */ jsx(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
const title = (board.shown?.doc.widgets[drill.origin.widgetId])?.title ?? messages.drillTitle;
|
|
65
|
+
return /* @__PURE__ */ jsx(DrillDrawer, {
|
|
66
|
+
widgetId: drill.origin.widgetId,
|
|
67
|
+
title,
|
|
68
|
+
close: () => {
|
|
69
|
+
board.view.setDrill(void 0, "push");
|
|
70
|
+
},
|
|
71
|
+
children: /* @__PURE__ */ jsx(DrillPanel, {
|
|
72
|
+
...props,
|
|
73
|
+
state: drill,
|
|
74
|
+
title,
|
|
75
|
+
onStateChange: (next, history) => {
|
|
76
|
+
board.view.setDrill(next, history);
|
|
77
|
+
}
|
|
78
|
+
})
|
|
69
79
|
});
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
@@ -82,7 +92,7 @@ function DrillScope(props) {
|
|
|
82
92
|
children: /* @__PURE__ */ jsx("div", {
|
|
83
93
|
className: "dd-dashboard",
|
|
84
94
|
"data-editing": board.edit.draft !== void 0,
|
|
85
|
-
"data-panel": panel !== void 0
|
|
95
|
+
"data-panel": panel !== void 0,
|
|
86
96
|
"data-drill": panel === void 0 && drilling,
|
|
87
97
|
children: props.children
|
|
88
98
|
})
|
|
@@ -11,34 +11,66 @@ const columnShape = (c) => ({
|
|
|
11
11
|
* One value as a list shows it, labelled so a row reads on its own: a time as "Created Nov 9" in
|
|
12
12
|
* the dashboard's zone, a number with its unit and label, a true field by its name.
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
15
|
-
if (
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
return typeof cell === "string" ? text : `${column.label} ${text}`;
|
|
14
|
+
function fieldMeta(cell, column, value, format) {
|
|
15
|
+
if (typeof cell === "boolean") return column.label;
|
|
16
|
+
if (typeof cell !== "string") return `${column.label} ${value}`;
|
|
17
|
+
if (column.type !== "time") return value;
|
|
18
|
+
return `${column.label} ${formatInstantAt(cell, "day", format.locale, format.timeZone)}`;
|
|
20
19
|
}
|
|
21
20
|
/** An item's own name when no field names it: its id when its key is shown, else its place. */
|
|
22
21
|
const untitled = (item, n, noun, format) => format.messages.drillUntitled(item.key === void 0 ? n : item.id, noun);
|
|
23
|
-
|
|
24
|
-
function itemParts(view, item, row, format) {
|
|
25
|
-
const text = (c) => valueText(item.values[c.member] ?? null, c, format);
|
|
26
|
-
const titled = view.columns.find((c) => c.member === view.title);
|
|
22
|
+
function itemTitle(titled, item, row, format) {
|
|
27
23
|
const named = titled === void 0 ? null : item.values[titled.member] ?? null;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
24
|
+
return titled === void 0 || named === null || named === "" ? untitled(item, row.n, row.noun, format) : formatCell(named, columnShape(titled), format);
|
|
25
|
+
}
|
|
26
|
+
/** The measure is the most informative field. The remaining fields follow the Records column order. */
|
|
27
|
+
function detailColumns(view, date) {
|
|
28
|
+
const excluded = /* @__PURE__ */ new Set([
|
|
29
|
+
view.title,
|
|
30
|
+
view.badge?.member,
|
|
31
|
+
view.numerator?.flag,
|
|
32
|
+
date,
|
|
33
|
+
...view.fixed ?? []
|
|
34
|
+
]);
|
|
35
|
+
return view.columns.filter((column) => !excluded.has(column.member)).toSorted((a, b) => Number(b.member === view.value) - Number(a.member === view.value));
|
|
36
|
+
}
|
|
37
|
+
/** The compact record list compares the same field on every row, including where it is missing. */
|
|
38
|
+
function recordField(view) {
|
|
39
|
+
return detailColumns(view, sortDate(view)?.member)[0];
|
|
40
|
+
}
|
|
41
|
+
function recordParts(view, item, row, format) {
|
|
42
|
+
const titled = view.columns.find((c) => c.member === view.title);
|
|
43
|
+
const title = itemTitle(titled, item, row, format);
|
|
44
|
+
const badge = badgeOf(view, item, view.columns.find((c) => c.member === view.badge?.member));
|
|
45
|
+
return {
|
|
34
46
|
title,
|
|
47
|
+
...badge ? { badge } : {},
|
|
48
|
+
...dateOf(row.date, titled, item, format)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Additional values for hosts that supply their own record renderer. */
|
|
52
|
+
function itemParts(view, item, row, format) {
|
|
53
|
+
const meta = detailColumns(view).flatMap((c) => {
|
|
54
|
+
const cell = item.values[c.member];
|
|
55
|
+
if (cell === null || cell === void 0 || cell === "" || cell === false) return [];
|
|
56
|
+
return [fieldMeta(cell, c, formatCell(cell, columnShape(c), format), format)];
|
|
57
|
+
}).slice(0, 3);
|
|
58
|
+
return {
|
|
59
|
+
...recordParts(view, item, row, format),
|
|
35
60
|
meta
|
|
36
|
-
} : {
|
|
37
|
-
title,
|
|
38
|
-
meta,
|
|
39
|
-
badge
|
|
40
61
|
};
|
|
41
62
|
}
|
|
63
|
+
/** Only a visible time field can supply the date alongside a record name. */
|
|
64
|
+
function sortDate(view) {
|
|
65
|
+
const sorted = view.sorted;
|
|
66
|
+
if (sorted?.time !== true || sorted.member === view.title) return;
|
|
67
|
+
return view.columns.find((c) => c.member === sorted.member && c.type === "time");
|
|
68
|
+
}
|
|
69
|
+
/** The sort date beside a record title, unless the title already gives it. */
|
|
70
|
+
function dateOf(member, titled, item, format) {
|
|
71
|
+
const value = member === void 0 || member === titled?.member ? void 0 : item.values[member];
|
|
72
|
+
return typeof value === "string" ? { value: formatCell(value, { type: "time" }, format) } : {};
|
|
73
|
+
}
|
|
42
74
|
/** A ratio's numerator name, on a row its numerator counts. */
|
|
43
75
|
function numeratorBadge(view, item) {
|
|
44
76
|
const { numerator } = view;
|
|
@@ -60,18 +92,4 @@ function badgeOf(view, item, column) {
|
|
|
60
92
|
...tone === void 0 ? {} : { tone }
|
|
61
93
|
};
|
|
62
94
|
}
|
|
63
|
-
|
|
64
|
-
/** The viewer's own choice of list or table for a source, kept in this browser only. */
|
|
65
|
-
function readMode(source) {
|
|
66
|
-
try {
|
|
67
|
-
return globalThis.localStorage?.getItem(`${MODE_KEY}${source}`) === "table" ? "table" : "list";
|
|
68
|
-
} catch {
|
|
69
|
-
return "list";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function writeMode(source, mode) {
|
|
73
|
-
try {
|
|
74
|
-
globalThis.localStorage?.setItem(`${MODE_KEY}${source}`, mode);
|
|
75
|
-
} catch {}
|
|
76
|
-
}
|
|
77
|
-
export { columnShape, itemParts, readMode, writeMode };
|
|
95
|
+
export { columnShape, itemParts, itemTitle, recordField, recordParts, sortDate };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../index.mjs";
|
|
1
|
+
import { Item } from "../index.mjs";
|
|
2
2
|
import { Cell, DrillItem, Primitive } from "derive-dashboards/core";
|
|
3
3
|
/** A source's key as an item carries it: one value per key column. */
|
|
4
4
|
type KeyOf<D> = D extends {
|
|
@@ -23,4 +23,4 @@ export type ItemFor<S> = S extends {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
} ? { [K in keyof Ss & string]: SourceItem<K, Ss[K]>; }[keyof Ss & string] : DrillItem;
|
|
26
|
-
export {};
|
|
26
|
+
export type { Item };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { DrillPanelProps } from "./DrillPanel.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* The drill panel (`DrillPanel` in `./DrillPanel`), loaded on first use: every export of the
|
|
4
|
-
* React entry reaches the panel through here, so no bundler pulls it in with the dashboard.
|
|
5
|
-
*/
|
|
2
|
+
/** An unopened dashboard leaves the drill chunk unloaded, including during server rendering. */
|
|
6
3
|
export declare function DrillPanel(props: DrillPanelProps): import("react").JSX.Element | null;
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
// src/drill/lazy.tsx
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
let loaded = null;
|
|
5
|
+
let pending;
|
|
6
|
+
const snapshot = () => loaded;
|
|
7
|
+
const serverSnapshot = () => null;
|
|
8
|
+
async function load() {
|
|
9
|
+
try {
|
|
10
|
+
loaded = await import("./DrillPanel.mjs");
|
|
11
|
+
} catch (error) {
|
|
12
|
+
loaded = { error };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Start the chunk on first open. Each mounted panel hears when the shared import settles. */
|
|
16
|
+
function subscribe(notify) {
|
|
17
|
+
let listener = notify;
|
|
18
|
+
pending ??= load();
|
|
19
|
+
pending.then(() => listener?.());
|
|
20
|
+
return () => {
|
|
21
|
+
listener = void 0;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function OpenPanel(props) {
|
|
25
|
+
const module = useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
26
|
+
if (!module) return null;
|
|
27
|
+
if ("error" in module) throw module.error;
|
|
28
|
+
return /* @__PURE__ */ jsx(module.DrillPanel, { ...props });
|
|
29
|
+
}
|
|
30
|
+
/** An unopened dashboard leaves the drill chunk unloaded, including during server rendering. */
|
|
10
31
|
function DrillPanel(props) {
|
|
11
32
|
if ((props.controller?.state ?? props.state) === void 0) return null;
|
|
12
|
-
return /* @__PURE__ */ jsx(
|
|
13
|
-
fallback: null,
|
|
14
|
-
children: /* @__PURE__ */ jsx(Loaded, { ...props })
|
|
15
|
-
});
|
|
33
|
+
return /* @__PURE__ */ jsx(OpenPanel, { ...props });
|
|
16
34
|
}
|
|
17
35
|
export { DrillPanel };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InDrillDrawer } from "./drawer-context.mjs";
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
2
3
|
// src/drill/panel-focus.ts
|
|
4
|
+
/** A standalone panel is a named landmark. An embedded panel belongs to the named dialog. */
|
|
5
|
+
function usePanelLandmark(title) {
|
|
6
|
+
return useContext(InDrillDrawer) ? { role: "presentation" } : { "aria-label": title };
|
|
7
|
+
}
|
|
3
8
|
/** A phone-sized screen, where the drill is a page of its own. */
|
|
4
9
|
const PHONE = "(max-width: 640px)";
|
|
5
10
|
const onPhone = () => typeof globalThis.matchMedia === "function" && globalThis.matchMedia(PHONE).matches;
|
|
@@ -20,10 +25,11 @@ function returnTarget(back, widgetId) {
|
|
|
20
25
|
* the page scrolls back to the tile instead of its top. A close that moved focus elsewhere on
|
|
21
26
|
* purpose keeps it there.
|
|
22
27
|
*/
|
|
23
|
-
function useFocusReturn(panel, widgetId) {
|
|
28
|
+
function useFocusReturn(panel, widgetId, embedded = false) {
|
|
24
29
|
const opener = useRef(null);
|
|
25
30
|
if (opener.current === null && typeof document !== "undefined") opener.current = document.activeElement;
|
|
26
31
|
useEffect(() => {
|
|
32
|
+
if (embedded) return;
|
|
27
33
|
const tile = tileOf(widgetId);
|
|
28
34
|
if (tile) tile.dataset.drilling = "";
|
|
29
35
|
const inside = panel.current;
|
|
@@ -36,16 +42,21 @@ function useFocusReturn(panel, widgetId) {
|
|
|
36
42
|
(tileOf(widgetId) ?? target)?.scrollIntoView({ block: "center" });
|
|
37
43
|
});
|
|
38
44
|
};
|
|
39
|
-
}, [
|
|
45
|
+
}, [
|
|
46
|
+
panel,
|
|
47
|
+
widgetId,
|
|
48
|
+
embedded
|
|
49
|
+
]);
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* On a phone, a tap first shows the value and a button to see the rows (Rules: no hover there),
|
|
43
53
|
* then the full page. Elsewhere the panel opens whole.
|
|
44
54
|
*/
|
|
45
|
-
function usePeek() {
|
|
46
|
-
const
|
|
47
|
-
|
|
55
|
+
function usePeek(wide, explicitRecords) {
|
|
56
|
+
const startFull = wide || explicitRecords;
|
|
57
|
+
const [peek, setPeek] = useState(() => !startFull && onPhone());
|
|
58
|
+
return [peek && !startFull, () => {
|
|
48
59
|
setPeek(false);
|
|
49
60
|
}];
|
|
50
61
|
}
|
|
51
|
-
export { useFocusReturn, usePeek };
|
|
62
|
+
export { useFocusReturn, usePanelLandmark, usePeek };
|
|
@@ -19,7 +19,13 @@ export type DrillMarkProps = {
|
|
|
19
19
|
*/
|
|
20
20
|
export type TileDrill = {
|
|
21
21
|
props: (row: number | readonly ResultCell[], entry?: string) => DrillMarkProps | undefined;
|
|
22
|
+
/** Open every measure of a group together, if the server sealed the row. */
|
|
23
|
+
compare?: (row: Row, view: Extract<DrillView, {
|
|
24
|
+
by: "comparison";
|
|
25
|
+
}>) => (() => void) | undefined;
|
|
22
26
|
open: (row: number | readonly ResultCell[] | undefined, entry?: string) => void;
|
|
23
27
|
/** The whole tile, as its Rows button opens it: on Items unless another view is named. */
|
|
24
28
|
openAll: (entry?: string, view?: DrillView) => void;
|
|
25
|
-
};
|
|
29
|
+
};
|
|
30
|
+
type Row = number | readonly ResultCell[];
|
|
31
|
+
export {};
|