derive-dashboards 0.1.1 → 0.3.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/README.md +5 -3
- package/dist/cache.mjs +2 -1
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +162 -0
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- package/dist/core/document/display.d.mts +63 -0
- package/dist/core/document/display.mjs +139 -0
- package/dist/core/document/layout.mjs +1 -1
- package/dist/core/document/view-layout.d.mts +14 -0
- package/dist/core/document/view-layout.mjs +157 -0
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +1 -1
- package/dist/core/engine/version.d.mts +5 -4
- package/dist/core/engine/version.mjs +5 -4
- package/dist/core/error/codes.d.mts +4 -1
- package/dist/core/error/codes.mjs +4 -1
- package/dist/core/index.d.mts +12 -8
- package/dist/core/index.mjs +11 -7
- package/dist/core/model/member.mjs +5 -2
- package/dist/core/model/types.d.mts +13 -13
- package/dist/core/model/validate/drill.mjs +6 -15
- package/dist/core/model/validate/fields.mjs +130 -0
- package/dist/core/model/validate/index.mjs +11 -3
- package/dist/core/model/validate/known-members.mjs +133 -0
- package/dist/core/model/validate/known-nested.mjs +85 -0
- package/dist/core/model/validate/known.mjs +94 -0
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/model/validate/source.mjs +8 -1
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- package/dist/core/query/alias.mjs +11 -1
- package/dist/core/query/drill/selection.d.mts +7 -2
- package/dist/core/query/drill/selection.mjs +18 -15
- package/dist/core/query/filter.d.mts +6 -0
- package/dist/core/query/picks.d.mts +8 -2
- package/dist/core/query/picks.mjs +11 -4
- package/dist/core/query/segments.mjs +2 -1
- package/dist/core/result/columns.d.mts +10 -1
- package/dist/core/result/columns.mjs +27 -5
- package/dist/core/result/time-axis.d.mts +23 -0
- package/dist/core/result/time-axis.mjs +72 -0
- package/dist/core/result/types.d.mts +36 -1
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answer-parts.mjs +23 -1
- package/dist/core/schema/answers.d.mts +204 -0
- package/dist/core/schema/answers.mjs +2 -0
- package/dist/core/schema/index.d.mts +3 -2
- package/dist/core/schema/index.mjs +3 -2
- package/dist/core/schema/query.d.mts +81 -0
- package/dist/core/schema/query.mjs +9 -5
- package/dist/core/schema/tools.d.mts +2 -0
- package/dist/core/schema/tools.mjs +27 -1
- package/dist/core/time/bucket.mjs +8 -2
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/dashboards.mjs +4 -0
- package/dist/drill-change.mjs +1 -1
- package/dist/drill-seal.mjs +1 -0
- package/dist/editing.mjs +2 -2
- package/dist/endpoints/dashboards.mjs +17 -2
- package/dist/endpoints/index.d.mts +15 -2
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/execute.mjs +32 -17
- package/dist/handler.mjs +5 -1
- package/dist/index.mjs +6 -1
- package/dist/llms.txt +22 -0
- package/dist/mcp/format.mjs +42 -8
- package/dist/mcp/query.mjs +34 -4
- package/dist/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +4 -0
- package/dist/react/Dashboard.mjs +27 -4
- package/dist/react/DashboardList.mjs +22 -22
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +5 -2
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +7 -19
- package/dist/react/Header.mjs +1 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/ReadFailed.mjs +23 -0
- package/dist/react/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +2 -0
- package/dist/react/Tile.mjs +45 -10
- package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/react/arrange-steps.mjs +16 -13
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/Calcs.mjs +35 -11
- package/dist/react/builder/FilterEditor.mjs +196 -0
- package/dist/react/builder/Filters.mjs +172 -116
- package/dist/react/builder/Formula.mjs +82 -0
- package/dist/react/builder/Groups.mjs +1 -0
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/builder/RangeEditor.mjs +184 -0
- package/dist/react/builder/Sections.mjs +41 -6
- package/dist/react/builder/Time.mjs +138 -60
- package/dist/react/builder/Values.mjs +85 -0
- package/dist/react/builder/WidgetBuilder.mjs +50 -49
- package/dist/react/builder/base.d.mts +5 -0
- package/dist/react/builder/base.mjs +33 -8
- package/dist/react/builder/calc.mjs +15 -1
- package/dist/react/builder/escape.d.mts +1 -0
- package/dist/react/builder/escape.mjs +62 -0
- package/dist/react/builder/filter-tree.d.mts +9 -0
- package/dist/react/builder/filter-tree.mjs +186 -0
- package/dist/react/builder/formula-parse.d.mts +18 -0
- package/dist/react/builder/formula-parse.mjs +136 -0
- package/dist/react/builder/labels.d.mts +1 -1
- package/dist/react/builder/state.d.mts +2 -1
- package/dist/react/builder/state.mjs +23 -37
- package/dist/react/builder/useBuilder.d.mts +12 -1
- package/dist/react/builder/useBuilder.mjs +6 -3
- package/dist/react/builder/words.d.mts +59 -0
- package/dist/react/builder/words.mjs +73 -0
- package/dist/react/context.d.mts +15 -1
- package/dist/react/context.mjs +9 -3
- package/dist/react/drill/Bars.mjs +2 -2
- package/dist/react/drill/props.mjs +2 -1
- package/dist/react/drill/useDrill.d.mts +1 -1
- package/dist/react/drill/words.d.mts +3 -0
- package/dist/react/drill/words.mjs +2 -0
- package/dist/react/english.mjs +20 -5
- package/dist/react/filters/bar.d.mts +12 -0
- package/dist/react/filters/bar.mjs +135 -0
- package/dist/react/filters/calendar.mjs +193 -0
- package/dist/react/filters/chip.mjs +174 -0
- package/dist/react/filters/context.d.mts +22 -0
- package/dist/react/filters/context.mjs +78 -0
- package/dist/react/filters/dates.mjs +89 -0
- package/dist/react/filters/days.d.mts +36 -0
- package/dist/react/filters/days.mjs +87 -0
- package/dist/react/filters/field-step.mjs +81 -0
- package/dist/react/filters/hooks.d.mts +34 -0
- package/dist/react/filters/hooks.mjs +94 -0
- package/dist/react/filters/listbox.mjs +131 -0
- package/dist/react/filters/logic.d.mts +59 -0
- package/dist/react/filters/logic.mjs +109 -0
- package/dist/react/filters/menu-search.mjs +211 -0
- package/dist/react/filters/menu.mjs +85 -0
- package/dist/react/filters/number.mjs +127 -0
- package/dist/react/filters/numbers.d.mts +47 -0
- package/dist/react/filters/numbers.mjs +151 -0
- package/dist/react/filters/operator.mjs +104 -0
- package/dist/react/filters/phone.mjs +104 -0
- package/dist/react/filters/popover.d.mts +19 -0
- package/dist/react/filters/popover.mjs +153 -0
- package/dist/react/filters/rules.d.mts +8 -0
- package/dist/react/filters/rules.mjs +55 -0
- package/dist/react/filters/sheet.mjs +196 -0
- package/dist/react/filters/state.mjs +132 -0
- package/dist/react/filters/suggest.d.mts +47 -0
- package/dist/react/filters/suggest.mjs +97 -0
- package/dist/react/filters/values.mjs +166 -0
- package/dist/react/filters/words.d.mts +81 -0
- package/dist/react/filters/words.mjs +73 -0
- package/dist/react/format.mjs +11 -4
- package/dist/react/index.d.mts +15 -6
- package/dist/react/index.mjs +10 -4
- package/dist/react/messages.d.mts +34 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.d.mts +3 -21
- package/dist/react/renderers/index.mjs +68 -6
- package/dist/react/renderers/list.d.mts +2 -1
- package/dist/react/renderers/list.mjs +9 -12
- package/dist/react/renderers/props.d.mts +26 -0
- package/dist/react/scope.d.mts +4 -0
- package/dist/react/scope.mjs +19 -2
- package/dist/react/series-slots.d.mts +37 -0
- package/dist/react/series-slots.mjs +71 -0
- package/dist/react/series.d.mts +39 -9
- package/dist/react/series.mjs +144 -47
- package/dist/react/theme.css +930 -19
- package/dist/react/useBoard.d.mts +2 -0
- package/dist/react/useDashboard.d.mts +3 -0
- package/dist/react/useDashboard.mjs +6 -0
- package/dist/react/view-grid.mjs +16 -0
- package/dist/recharts/axes.mjs +28 -0
- package/dist/recharts/axis.mjs +84 -0
- package/dist/recharts/bar.d.mts +7 -0
- package/dist/recharts/bar.mjs +141 -0
- package/dist/recharts/charts.d.mts +4 -5
- package/dist/recharts/charts.mjs +2 -208
- package/dist/recharts/index.d.mts +3 -1
- package/dist/recharts/index.mjs +4 -1
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +112 -0
- package/dist/recharts/marks.mjs +47 -18
- package/dist/recharts/parts.mjs +103 -0
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +1 -1
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -0
- package/dist/store/apply.mjs +3 -1
- package/package.json +6 -2
- package/dist/react/FilterBar.mjs +0 -119
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDashboards } from "./context.mjs";
|
|
2
|
+
import { Row } from "./DashboardListRow.mjs";
|
|
2
3
|
import { useId, useState } from "react";
|
|
3
4
|
import useSWR from "swr";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -73,32 +74,31 @@ function Search(props) {
|
|
|
73
74
|
}) : null] });
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
|
-
* The dashboards, each
|
|
77
|
-
*
|
|
77
|
+
* The dashboards, each named for itself, its description and Draft as its description rather
|
|
78
|
+
* than its name. With `linkFor` each is a link and a published one has Copy link beside it.
|
|
78
79
|
*/
|
|
79
80
|
function Items({ items, current, onOpen, linkFor }) {
|
|
80
81
|
const { messages } = useDashboards();
|
|
81
82
|
const base = useId();
|
|
82
|
-
return /* @__PURE__ */ jsx("ul", { children: items.map((d, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
onOpen
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
children: d.title
|
|
93
|
-
}), d.unpublished === true ? /* @__PURE__ */ jsx("em", {
|
|
83
|
+
return /* @__PURE__ */ jsx("ul", { children: items.map((d, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
84
|
+
/* @__PURE__ */ jsx(Row, {
|
|
85
|
+
d,
|
|
86
|
+
href: linkFor?.(d.id),
|
|
87
|
+
current: d.id === current,
|
|
88
|
+
describedBy: `${base}-${String(i)}`,
|
|
89
|
+
onOpen
|
|
90
|
+
}),
|
|
91
|
+
/* @__PURE__ */ jsx("span", {
|
|
92
|
+
hidden: true,
|
|
94
93
|
id: `${base}-${String(i)}`,
|
|
95
|
-
children: messages.unpublished
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
children: [d.unpublished === true ? messages.unpublished : void 0, d.description].filter((part) => part !== void 0).join(". ")
|
|
95
|
+
}),
|
|
96
|
+
linkFor === void 0 || d.unpublished === true ? null : /* @__PURE__ */ jsx(CopyLink, {
|
|
97
|
+
id: d.id,
|
|
98
|
+
title: d.title,
|
|
99
|
+
linkFor
|
|
100
|
+
})
|
|
101
|
+
] }, d.id)) });
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* The built-in dashboards (`default:` ids) first, under a heading, then the ones made here, when
|
|
@@ -140,7 +140,7 @@ function DashboardList({ current, onOpen, linkFor }) {
|
|
|
140
140
|
const [search, setSearch] = useState("");
|
|
141
141
|
const all = list.data?.dashboards ?? [];
|
|
142
142
|
const words = search.trim().toLocaleLowerCase();
|
|
143
|
-
const shown = words === "" ? all : all.filter((d) => d.title.toLocaleLowerCase().includes(words));
|
|
143
|
+
const shown = words === "" ? all : all.filter((d) => `${d.title} ${d.description ?? ""}`.toLocaleLowerCase().includes(words));
|
|
144
144
|
const { making, error, create } = useCreate(onOpen, async () => {
|
|
145
145
|
await list.mutate();
|
|
146
146
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useDashboards } from "./context.mjs";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/DashboardListRow.tsx
|
|
4
|
+
/** A click a link would follow itself: a modified or middle click opens a new tab as usual. */
|
|
5
|
+
const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
6
|
+
/**
|
|
7
|
+
* One row: the dashboard's name, Draft for the viewer's unpublished one, and its description.
|
|
8
|
+
* With `href` it is a link, so Cmd-click and middle-click open a new tab while a plain click
|
|
9
|
+
* still goes to `onOpen`; without one it is a button. Draft and the description describe the
|
|
10
|
+
* row; its name stays the dashboard's.
|
|
11
|
+
*/
|
|
12
|
+
function Row(props) {
|
|
13
|
+
const { d, href, describedBy, onOpen } = props;
|
|
14
|
+
const { messages } = useDashboards();
|
|
15
|
+
const shared = {
|
|
16
|
+
className: "dd-list-open",
|
|
17
|
+
"aria-label": d.title,
|
|
18
|
+
"aria-describedby": d.unpublished === true || d.description !== void 0 ? describedBy : void 0,
|
|
19
|
+
"aria-current": props.current ? "page" : void 0
|
|
20
|
+
};
|
|
21
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("span", {
|
|
22
|
+
className: "dd-list-name",
|
|
23
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
24
|
+
className: "dd-list-title",
|
|
25
|
+
children: d.title
|
|
26
|
+
}), d.unpublished === true ? /* @__PURE__ */ jsx("em", { children: messages.unpublished }) : null]
|
|
27
|
+
}), d.description === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "dd-list-desc",
|
|
29
|
+
children: d.description
|
|
30
|
+
})] });
|
|
31
|
+
return href === void 0 ? /* @__PURE__ */ jsx("button", {
|
|
32
|
+
type: "button",
|
|
33
|
+
...shared,
|
|
34
|
+
onClick: () => {
|
|
35
|
+
onOpen(d.id);
|
|
36
|
+
},
|
|
37
|
+
children: body
|
|
38
|
+
}) : /* @__PURE__ */ jsx("a", {
|
|
39
|
+
href,
|
|
40
|
+
...shared,
|
|
41
|
+
onClick: (event) => {
|
|
42
|
+
if (event.defaultPrevented || !plainClick(event)) return;
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
onOpen(d.id);
|
|
45
|
+
},
|
|
46
|
+
children: body
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export { Row };
|
package/dist/react/Discard.mjs
CHANGED
|
@@ -21,15 +21,18 @@ function DiscardButton({ edit, isNew = false }) {
|
|
|
21
21
|
answered.current = !on;
|
|
22
22
|
setAsking(on);
|
|
23
23
|
};
|
|
24
|
+
const untouched = !isNew && (edit.draft?.changes.filter((c) => !isShifted(c)).length ?? 0) === 0;
|
|
24
25
|
if (!asking) return /* @__PURE__ */ jsx("button", {
|
|
25
26
|
ref: discard,
|
|
26
27
|
type: "button",
|
|
27
28
|
className: "dd-button dd-quiet",
|
|
28
29
|
"aria-disabled": edit.busy,
|
|
29
30
|
onClick: () => {
|
|
30
|
-
if (
|
|
31
|
+
if (edit.busy) return;
|
|
32
|
+
if (untouched) edit.discard();
|
|
33
|
+
else ask(true);
|
|
31
34
|
},
|
|
32
|
-
children: messages.discard
|
|
35
|
+
children: untouched ? messages.doneEditing : messages.discard
|
|
33
36
|
});
|
|
34
37
|
return /* @__PURE__ */ jsx(DiscardAsk, {
|
|
35
38
|
edit,
|
package/dist/react/Editing.mjs
CHANGED
|
@@ -81,14 +81,14 @@ function saveCommands(doc, tab, widget, widgetId) {
|
|
|
81
81
|
at: placeFor(tab, widget)
|
|
82
82
|
}];
|
|
83
83
|
const before = doc.widgets[widgetId];
|
|
84
|
-
const query = widget.queries
|
|
84
|
+
const query = widget.queries.main;
|
|
85
85
|
return [{
|
|
86
86
|
type: "widget.update",
|
|
87
87
|
id: widgetId,
|
|
88
88
|
title: widget.title,
|
|
89
89
|
kind: widget.kind,
|
|
90
90
|
...widget.display === void 0 ? {} : { display: widget.display }
|
|
91
|
-
}, ...query === void 0 || before?.queries
|
|
91
|
+
}, ...query === void 0 || before?.queries.main === query ? [] : [{
|
|
92
92
|
type: "widget.setQuery",
|
|
93
93
|
id: widgetId,
|
|
94
94
|
name: "main",
|
|
@@ -103,6 +103,22 @@ function BuildPage({ doc, tab, edit, widgetId, onDone }) {
|
|
|
103
103
|
const { messages } = useDashboards();
|
|
104
104
|
const [id] = useState(() => widgetId ?? `w${crypto.randomUUID().slice(0, 8)}`);
|
|
105
105
|
const initial = widgetId === void 0 ? void 0 : doc.widgets[widgetId];
|
|
106
|
+
const cancel = () => {
|
|
107
|
+
onDone();
|
|
108
|
+
};
|
|
109
|
+
if (initial !== void 0 && initial.queries["main"] === void 0) return /* @__PURE__ */ jsxs("div", {
|
|
110
|
+
className: "dd-builder",
|
|
111
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
112
|
+
type: "button",
|
|
113
|
+
className: "dd-back",
|
|
114
|
+
onClick: cancel,
|
|
115
|
+
children: ["‹ ", doc.meta.title]
|
|
116
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
117
|
+
className: "dd-builder-error",
|
|
118
|
+
role: "alert",
|
|
119
|
+
children: messages.noMainQuery(initial.title)
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
106
122
|
return /* @__PURE__ */ jsx(WidgetBuilder, {
|
|
107
123
|
...initial === void 0 ? {} : { initial },
|
|
108
124
|
backLabel: doc.meta.title,
|
|
@@ -110,9 +126,7 @@ function BuildPage({ doc, tab, edit, widgetId, onDone }) {
|
|
|
110
126
|
saveLabel: widgetId === void 0 ? messages.addToDashboard : messages.save,
|
|
111
127
|
saving: edit.busy,
|
|
112
128
|
...edit.error === void 0 ? {} : { error: edit.error },
|
|
113
|
-
onCancel:
|
|
114
|
-
onDone();
|
|
115
|
-
},
|
|
129
|
+
onCancel: cancel,
|
|
116
130
|
onSave: (widget) => {
|
|
117
131
|
const save = async () => {
|
|
118
132
|
if (await edit.apply(saveCommands(doc, tab, widget, id))) onDone(id);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export declare function FilterBar({ controls, picks, onChange }: Props): import("react").JSX.Element | null;
|
|
9
|
-
export {};
|
|
1
|
+
import { ENGLISH_FILTERS, FilterWords } from "./filters/words.mjs";
|
|
2
|
+
import { FilterBar } from "./filters/bar.mjs";
|
|
3
|
+
import { FilterBarOptions, FilterIcon } from "./filters/context.mjs";
|
|
4
|
+
import { FilterBarProps, fieldOf, useControlValues, useFilterFields } from "./filters/hooks.mjs";
|
|
5
|
+
import { Popover } from "./filters/popover.mjs";
|
|
6
|
+
import { rules_d_exports } from "./filters/rules.mjs";
|
|
7
|
+
export { ENGLISH_FILTERS, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, Popover, fieldOf, rules_d_exports as filterRules, useControlValues, useFilterFields };
|
package/dist/react/Grid.mjs
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
import { useArrange } from "./arrange.mjs";
|
|
2
2
|
import { Cell as Cell$1 } from "./Cell.mjs";
|
|
3
3
|
import { useDashboards } from "./context.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { Spaces } from "./Spaces.mjs";
|
|
4
|
+
import { Drop, Spaces } from "./Spaces.mjs";
|
|
6
5
|
import { useSameWidgets, useStable } from "./stable.mjs";
|
|
6
|
+
import { useViewGrid } from "./view-grid.mjs";
|
|
7
7
|
import { useMemo, useRef } from "react";
|
|
8
8
|
import { readingOrder, stepCommands } from "derive-dashboards/core";
|
|
9
|
-
import {
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// src/Grid.tsx
|
|
11
11
|
/** Each filter control's label by id, made once per set of controls rather than per tile. */
|
|
12
12
|
function useControlLabels(controls) {
|
|
13
13
|
return useMemo(() => new Map(controls.map((c) => [c.id, c.label])), [controls]);
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* The outline where a dragged tile will land, and where one moved by the keyboard is now, said
|
|
17
|
-
* to a screen reader (`arrange` writes it).
|
|
18
|
-
*/
|
|
19
|
-
function Drop({ at }) {
|
|
20
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
21
|
-
className: "dd-placed dd-sr",
|
|
22
|
-
role: "status"
|
|
23
|
-
}), at === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
24
|
-
className: "dd-drop",
|
|
25
|
-
"aria-hidden": "true",
|
|
26
|
-
style: placeOf(at)
|
|
27
|
-
})] });
|
|
28
|
-
}
|
|
29
15
|
/** Focuses the first of `selectors` that matches in a widget's cell, once it is drawn. */
|
|
30
16
|
function focusIn(widget, ...selectors) {
|
|
31
17
|
requestAnimationFrame(() => {
|
|
@@ -99,7 +85,8 @@ function Grid(props) {
|
|
|
99
85
|
const widgets = useSameWidgets(doc.widgets);
|
|
100
86
|
const { onEdit, onRemove, onStep } = useTileCalls(edit, props);
|
|
101
87
|
const editing = edit.draft !== void 0 && arrangeable;
|
|
102
|
-
const
|
|
88
|
+
const view = useViewGrid(props.tab.layout, widgets, props.results);
|
|
89
|
+
const cells = useReadingOrder(props.tab.layout, editing ? arrange.layout : view.layout);
|
|
103
90
|
return /* @__PURE__ */ jsxs("div", {
|
|
104
91
|
ref: arrange.gridRef,
|
|
105
92
|
className: "dd-grid",
|
|
@@ -131,7 +118,8 @@ function Grid(props) {
|
|
|
131
118
|
onRemove,
|
|
132
119
|
onStep,
|
|
133
120
|
first: cells[0]?.widget === item.widget,
|
|
134
|
-
last: cells.at(-1)?.widget === item.widget
|
|
121
|
+
last: cells.at(-1)?.widget === item.widget,
|
|
122
|
+
sharedSpan: view.sharedSpan
|
|
135
123
|
}, item.widget);
|
|
136
124
|
})
|
|
137
125
|
]
|
package/dist/react/Header.mjs
CHANGED
|
@@ -91,7 +91,7 @@ function Header(props) {
|
|
|
91
91
|
}), /* @__PURE__ */ jsxs("div", {
|
|
92
92
|
className: "dd-header-actions",
|
|
93
93
|
children: [
|
|
94
|
-
props.unpublished === true ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
|
|
94
|
+
props.unpublished === true || editing ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
|
|
95
95
|
editing || version === 0 ? null : /* @__PURE__ */ jsx("button", {
|
|
96
96
|
type: "button",
|
|
97
97
|
className: "dd-button dd-quiet",
|
package/dist/react/History.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { useDashboards } from "./context.mjs";
|
|
|
3
3
|
import { LIST_KEY } from "./DashboardList.mjs";
|
|
4
4
|
import { formatInstant } from "./format.mjs";
|
|
5
5
|
import { Panel } from "./Panel.mjs";
|
|
6
|
+
import { ReadFailed } from "./ReadFailed.mjs";
|
|
6
7
|
import { useState } from "react";
|
|
7
8
|
import { useSWRConfig } from "swr";
|
|
8
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -82,6 +83,10 @@ function HistoryPanel(props) {
|
|
|
82
83
|
className: "dd-tile-note",
|
|
83
84
|
children: messages.noHistory
|
|
84
85
|
}) : null,
|
|
86
|
+
/* @__PURE__ */ jsx(ReadFailed, {
|
|
87
|
+
error: history.error,
|
|
88
|
+
retry: () => void history.mutate()
|
|
89
|
+
}),
|
|
85
90
|
/* @__PURE__ */ jsx("ol", {
|
|
86
91
|
className: "dd-timeline",
|
|
87
92
|
children: entries.map((entry) => /* @__PURE__ */ jsx(Entry, {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useDashboards } from "./context.mjs";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/ReadFailed.tsx
|
|
4
|
+
/** A list that could not be read (the history, a page of it): said, with a way to try again. */
|
|
5
|
+
function ReadFailed({ error, retry }) {
|
|
6
|
+
const { messages } = useDashboards();
|
|
7
|
+
if (error === void 0) return null;
|
|
8
|
+
return /* @__PURE__ */ jsxs("p", {
|
|
9
|
+
className: "dd-tile-error",
|
|
10
|
+
role: "alert",
|
|
11
|
+
children: [
|
|
12
|
+
messages.readFailed,
|
|
13
|
+
" ",
|
|
14
|
+
/* @__PURE__ */ jsx("button", {
|
|
15
|
+
type: "button",
|
|
16
|
+
className: "dd-button dd-quiet",
|
|
17
|
+
onClick: retry,
|
|
18
|
+
children: messages.drillRetry
|
|
19
|
+
})
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { ReadFailed };
|
package/dist/react/Spaces.mjs
CHANGED
|
@@ -105,4 +105,18 @@ function Spaces(props) {
|
|
|
105
105
|
}) : null
|
|
106
106
|
}, `${gap.widget}-gap`))] });
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
/**
|
|
109
|
+
* The outline where a dragged tile will land, and where one moved by the keyboard is now, said
|
|
110
|
+
* to a screen reader (`arrange` writes it).
|
|
111
|
+
*/
|
|
112
|
+
function Drop({ at }) {
|
|
113
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
114
|
+
className: "dd-placed dd-sr",
|
|
115
|
+
role: "status"
|
|
116
|
+
}), at === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
117
|
+
className: "dd-drop",
|
|
118
|
+
"aria-hidden": "true",
|
|
119
|
+
style: placeOf(at)
|
|
120
|
+
})] });
|
|
121
|
+
}
|
|
122
|
+
export { Drop, Spaces, ghostPlaces };
|
package/dist/react/Tile.d.mts
CHANGED
|
@@ -11,6 +11,8 @@ type Props = {
|
|
|
11
11
|
actions?: ReactNode;
|
|
12
12
|
/** What changed about it, beside its title: New, Edited, Moved, or a preview's mark. */
|
|
13
13
|
badge?: ReactNode;
|
|
14
|
+
/** The span most tiles cover (`spanKey`), said once for the dashboard, not on each tile. */
|
|
15
|
+
sharedSpan?: string | undefined;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
|
package/dist/react/Tile.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useDashboards } from "./context.mjs";
|
|
2
2
|
import { useTileDrill } from "./drill/host.mjs";
|
|
3
3
|
import { formatInstantAt } from "./format.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
5
|
+
import { seriesSlots } from "./series-slots.mjs";
|
|
6
|
+
import { memo, useContext, useState } from "react";
|
|
7
|
+
import { sharedDisplay } from "derive-dashboards/core";
|
|
5
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
9
|
// src/Tile.tsx
|
|
7
10
|
/** Refusals that last only until the dashboard is read again, never shown as errors. */
|
|
@@ -40,22 +43,26 @@ const drawable = (result) => result !== void 0 && !("error" in result) && result
|
|
|
40
43
|
/** The answer drawn: a memo of its own, so a change to the tile's buttons or badge never draws the chart again. */
|
|
41
44
|
const Body = memo(function Body({ widget, result, loading, drill }) {
|
|
42
45
|
const { renderers, locale, messages, link } = useDashboards();
|
|
46
|
+
const shared = useContext(SeriesSlotsContext);
|
|
47
|
+
const [own] = useState(seriesSlots);
|
|
48
|
+
const slots = shared ?? own;
|
|
43
49
|
if (!drawable(result)) {
|
|
44
|
-
const empty = widget.display
|
|
50
|
+
const { empty } = sharedDisplay(widget.display);
|
|
45
51
|
return /* @__PURE__ */ jsx(TileState, {
|
|
46
52
|
result,
|
|
47
53
|
loading,
|
|
48
|
-
empty:
|
|
54
|
+
empty: empty ?? messages.noData
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
|
-
const Renderer = renderers[widget.kind] ?? renderers
|
|
57
|
+
const Renderer = renderers[widget.kind] ?? renderers.table;
|
|
52
58
|
return Renderer === void 0 ? null : /* @__PURE__ */ jsx(Renderer, {
|
|
53
59
|
answer: result,
|
|
54
60
|
widget,
|
|
55
61
|
messages,
|
|
56
62
|
...locale === void 0 ? {} : { locale },
|
|
57
63
|
...drill === void 0 ? {} : { drill },
|
|
58
|
-
...link === void 0 ? {} : { link }
|
|
64
|
+
...link === void 0 ? {} : { link },
|
|
65
|
+
slots
|
|
59
66
|
});
|
|
60
67
|
});
|
|
61
68
|
/** Notes under a tile: a viewer's filter that could not apply, or an answer cut at the row cap. */
|
|
@@ -80,12 +87,21 @@ function Notes({ result, controlLabels }) {
|
|
|
80
87
|
}
|
|
81
88
|
/** Whether a tile has rows behind it to show: an answer the viewer can read. */
|
|
82
89
|
const hasRows = (result) => result !== void 0 && !("error" in result) && result.unreadable !== true && result.rows.length > 0;
|
|
83
|
-
/** The time a tile's answer covers, as
|
|
84
|
-
|
|
90
|
+
/** The time a tile's answer covers, as a key two tiles share when they cover the same days. */
|
|
91
|
+
const spanKey = (result) => {
|
|
92
|
+
if (result === void 0 || "error" in result) return void 0;
|
|
93
|
+
const range = result.receipt.range;
|
|
94
|
+
return range === void 0 ? void 0 : `${range.from}|${range.to}`;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The time a tile's answer covers, as it read it ("Oct 15 to Nov 14"), so a reader knows its
|
|
98
|
+
* window. A tile covering the span most tiles do leaves it to the dashboard, which says it once.
|
|
99
|
+
*/
|
|
100
|
+
function Span({ result, shared }) {
|
|
85
101
|
const format = useDashboards();
|
|
86
102
|
if (result === void 0 || "error" in result) return null;
|
|
87
103
|
const range = result.receipt.range;
|
|
88
|
-
if (range === void 0) return null;
|
|
104
|
+
if (range === void 0 || shared !== void 0 && spanKey(result) === shared) return null;
|
|
89
105
|
const zone = result.receipt.calendar.timezone;
|
|
90
106
|
const day = (at) => formatInstantAt(at, "day", format.locale, zone);
|
|
91
107
|
return /* @__PURE__ */ jsx("p", {
|
|
@@ -94,6 +110,22 @@ function Span({ result }) {
|
|
|
94
110
|
});
|
|
95
111
|
}
|
|
96
112
|
/**
|
|
113
|
+
* The span most of the tiles cover, when at least two do and they are most of them: the
|
|
114
|
+
* dashboard says it once and those tiles leave it out. None when the tiles disagree.
|
|
115
|
+
*/
|
|
116
|
+
function sharedSpan(results) {
|
|
117
|
+
const counts = /* @__PURE__ */ new Map();
|
|
118
|
+
let spans = 0;
|
|
119
|
+
for (const result of results.values()) {
|
|
120
|
+
const key = spanKey(result);
|
|
121
|
+
if (key === void 0) continue;
|
|
122
|
+
spans += 1;
|
|
123
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
124
|
+
}
|
|
125
|
+
const [top] = [...counts].toSorted((a, b) => b[1] - a[1]);
|
|
126
|
+
return top !== void 0 && top[1] >= 2 && top[1] * 2 > spans ? top[0] : void 0;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
97
129
|
* One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
|
|
98
130
|
* on request (Rows opens its drill on Items). It draws again only when one of its props changes.
|
|
99
131
|
*/
|
|
@@ -130,7 +162,10 @@ const Tile = memo(function Tile(props) {
|
|
|
130
162
|
})
|
|
131
163
|
]
|
|
132
164
|
}),
|
|
133
|
-
/* @__PURE__ */ jsx(Span, {
|
|
165
|
+
/* @__PURE__ */ jsx(Span, {
|
|
166
|
+
result: props.result,
|
|
167
|
+
shared: props.sharedSpan
|
|
168
|
+
}),
|
|
134
169
|
/* @__PURE__ */ jsx("div", {
|
|
135
170
|
className: "dd-tile-body",
|
|
136
171
|
children: /* @__PURE__ */ jsx(Body, {
|
|
@@ -144,4 +179,4 @@ const Tile = memo(function Tile(props) {
|
|
|
144
179
|
]
|
|
145
180
|
});
|
|
146
181
|
});
|
|
147
|
-
export { Tile };
|
|
182
|
+
export { Span, Tile, sharedSpan, spanKey };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll };
|
|
@@ -39,41 +39,44 @@ function stepOf(grid) {
|
|
|
39
39
|
y: row + rowGap
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
/** The smallest a person can resize a tile to: room for its title, its buttons and a number. */
|
|
43
|
-
const SMALLEST = {
|
|
44
|
-
w: 2,
|
|
45
|
-
h: 2
|
|
46
|
-
};
|
|
47
42
|
/**
|
|
48
43
|
* The item moved or resized by whole cells: a move keeps the size; a resize keeps the top left,
|
|
49
|
-
* stops at the grid's edge, and never makes a tile smaller than
|
|
50
|
-
* smaller stays as it is).
|
|
44
|
+
* stops at the grid's edge, and never makes a tile smaller than its kind reads at (core's
|
|
45
|
+
* `smallestFor`; one already smaller stays as it is).
|
|
51
46
|
*/
|
|
52
|
-
function shifted(item,
|
|
47
|
+
function shifted(item, how, by) {
|
|
48
|
+
const { mode, least } = how;
|
|
49
|
+
const { dx, dy } = by;
|
|
53
50
|
return mode === "move" ? {
|
|
54
51
|
...item,
|
|
55
52
|
x: Math.max(0, item.x + dx),
|
|
56
53
|
y: Math.max(0, item.y + dy)
|
|
57
54
|
} : {
|
|
58
55
|
...item,
|
|
59
|
-
w: Math.min(Math.max(Math.min(
|
|
60
|
-
h: Math.max(Math.min(
|
|
56
|
+
w: Math.min(Math.max(Math.min(least.w, item.w), item.w + dx), GRID_COLUMNS - item.x),
|
|
57
|
+
h: Math.max(Math.min(least.h, item.h), item.h + dy)
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
60
|
/** Where a drag puts the item: whole cells from where the pointer went down. */
|
|
64
61
|
function dragged(d, event) {
|
|
65
62
|
const dx = Math.round((event.clientX - d.x0) / d.step.x);
|
|
66
63
|
const dy = Math.round((event.clientY - d.y0) / d.step.y);
|
|
67
|
-
return shifted(d.start, d
|
|
64
|
+
return shifted(d.start, d, {
|
|
65
|
+
dx,
|
|
66
|
+
dy
|
|
67
|
+
});
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* One arrow key's move: the nearest place in that direction where the layout really changes,
|
|
71
71
|
* so moving down past a tile takes one press, not as many as it is tall.
|
|
72
72
|
*/
|
|
73
|
-
function nextStep(tab, item,
|
|
73
|
+
function nextStep(tab, item, how, key) {
|
|
74
74
|
const before = JSON.stringify(placeItem(tab.layout, item));
|
|
75
75
|
for (let n = 1; n <= 48; n += 1) {
|
|
76
|
-
const next = shifted(item,
|
|
76
|
+
const next = shifted(item, how, {
|
|
77
|
+
dx: key.dx * n,
|
|
78
|
+
dy: key.dy * n
|
|
79
|
+
});
|
|
77
80
|
if (JSON.stringify(placeItem(tab.layout, next)) !== before) return next;
|
|
78
81
|
}
|
|
79
82
|
return item;
|
package/dist/react/arrange.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { KEYS, commit, dragged, follow, nextStep, same, stepOf } from "./arrange
|
|
|
2
2
|
import { useDashboards } from "./context.mjs";
|
|
3
3
|
import { useStable } from "./stable.mjs";
|
|
4
4
|
import { useMemo, useRef, useState } from "react";
|
|
5
|
-
import { placeItem } from "derive-dashboards/core";
|
|
5
|
+
import { placeItem, smallestFor } from "derive-dashboards/core";
|
|
6
6
|
// src/arrange.ts
|
|
7
7
|
/**
|
|
8
8
|
* A preview that only changes when its place does: a pointer moving inside one grid cell
|
|
@@ -25,12 +25,18 @@ function usePreview() {
|
|
|
25
25
|
show: useStable(show)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
/** The smallest the tile's kind reads at, from the draft's own widget. */
|
|
29
|
+
const leastOf = (a, item) => smallestFor(a.edit().draft?.doc.widgets[item.widget]?.kind);
|
|
28
30
|
/** An arrow key on a handle: a cell's move (or with Shift, a resize), then where the tile is now. */
|
|
29
31
|
const onKey = (a, send, item, mode) => (event) => {
|
|
30
32
|
const key = KEYS[event.key];
|
|
31
33
|
if (key === void 0 || a.edit().busy) return;
|
|
32
34
|
event.preventDefault();
|
|
33
|
-
const
|
|
35
|
+
const how = {
|
|
36
|
+
mode: event.shiftKey ? "resize" : mode,
|
|
37
|
+
least: leastOf(a, item)
|
|
38
|
+
};
|
|
39
|
+
const wanted = nextStep(a.tab(), item, how, key);
|
|
34
40
|
const said = async () => {
|
|
35
41
|
await send(wanted);
|
|
36
42
|
requestAnimationFrame(() => {
|
|
@@ -67,7 +73,8 @@ function handlers(a, drag, show) {
|
|
|
67
73
|
last: {
|
|
68
74
|
clientX: x0,
|
|
69
75
|
clientY: y0
|
|
70
|
-
}
|
|
76
|
+
},
|
|
77
|
+
least: leastOf(a, item)
|
|
71
78
|
};
|
|
72
79
|
show(item, mode === "move" ? item : void 0);
|
|
73
80
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { FormulaEditor } from "./Formula.mjs";
|
|
2
3
|
import { formulaText } from "./labels.mjs";
|
|
3
4
|
import { Chip, Entry, Section } from "./Sections.mjs";
|
|
4
5
|
import { useState } from "react";
|
|
@@ -43,14 +44,36 @@ function CalcEditor({ b, calc }) {
|
|
|
43
44
|
]
|
|
44
45
|
});
|
|
45
46
|
}
|
|
47
|
+
/** The presets that fit, and Formula, to add a calculation. */
|
|
48
|
+
function AddChips({ b, onFormula }) {
|
|
49
|
+
const { messages } = useDashboards();
|
|
50
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
51
|
+
className: "dd-chips",
|
|
52
|
+
children: [b.presets.map((p) => /* @__PURE__ */ jsx(Chip, {
|
|
53
|
+
add: true,
|
|
54
|
+
on: false,
|
|
55
|
+
label: messages.presets[p],
|
|
56
|
+
onClick: () => {
|
|
57
|
+
b.addCalc(p);
|
|
58
|
+
}
|
|
59
|
+
}, p)), /* @__PURE__ */ jsx(Chip, {
|
|
60
|
+
add: true,
|
|
61
|
+
on: false,
|
|
62
|
+
label: messages.formula,
|
|
63
|
+
onClick: onFormula
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
46
67
|
/** Calculations: the ones added, each editable in place, and the presets that fit. */
|
|
47
68
|
function CalcSection({ b }) {
|
|
48
69
|
const { messages } = useDashboards();
|
|
49
70
|
const [open, setOpen] = useState();
|
|
71
|
+
const [writing, setWriting] = useState(false);
|
|
50
72
|
const calcs = b.state.query?.calc ?? [];
|
|
51
73
|
if (b.state.query === void 0) return null;
|
|
52
74
|
return /* @__PURE__ */ jsxs(Section, {
|
|
53
75
|
title: messages.calculations,
|
|
76
|
+
summary: calcs.length === 0 ? messages.noCalculations : calcs.map((c) => c.label ?? c.id).join(", "),
|
|
54
77
|
children: [
|
|
55
78
|
calcs.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
56
79
|
className: "dd-muted",
|
|
@@ -70,17 +93,18 @@ function CalcSection({ b }) {
|
|
|
70
93
|
b,
|
|
71
94
|
calc: c
|
|
72
95
|
}) : null] }, c.id)),
|
|
73
|
-
/* @__PURE__ */ jsx(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
/* @__PURE__ */ jsx(AddChips, {
|
|
97
|
+
b,
|
|
98
|
+
onFormula: () => {
|
|
99
|
+
setWriting(true);
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
writing ? /* @__PURE__ */ jsx(FormulaEditor, {
|
|
103
|
+
b,
|
|
104
|
+
onDone: () => {
|
|
105
|
+
setWriting(false);
|
|
106
|
+
}
|
|
107
|
+
}) : null
|
|
84
108
|
]
|
|
85
109
|
});
|
|
86
110
|
}
|