@protobase/ui 0.15.4 → 0.16.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/account/two-factor-setup.js +6 -5
- package/dist/app/app.js +2 -1
- package/dist/app/create/create-page.js +1 -0
- package/dist/app/create/create-record-form.js +2 -1
- package/dist/app/displays/custom-display.js +1 -1
- package/dist/app/displays/map-display.js +50 -34
- package/dist/app/displays/map-groups.js +12 -3
- package/dist/app/displays/measured-heights.js +23 -0
- package/dist/app/displays/record-card.js +2 -2
- package/dist/app/displays/virtual-cards.js +12 -14
- package/dist/app/field-editor.js +9 -1
- package/dist/app/index.html +2 -2
- package/dist/app/list-page.js +2 -2
- package/dist/app/map/approximate-position.js +76 -0
- package/dist/app/map/area-features.js +80 -0
- package/dist/app/map/maplibre.js +11 -0
- package/dist/app/map/position-areas.js +78 -0
- package/dist/app/map/record-map.js +2 -7
- package/dist/app/map/record-position.js +5 -4
- package/dist/app/map/records-map.js +24 -7
- package/dist/app/map/theme-color.js +23 -0
- package/dist/app/meta-gate.js +1 -1
- package/dist/app/nav-recent.js +1 -1
- package/dist/app/pages/blocks/card-frame.js +2 -2
- package/dist/app/pages/blocks/grid.js +10 -2
- package/dist/app/pages/blocks/link.js +1 -1
- package/dist/app/pages/blocks/page-block.js +1 -1
- package/dist/app/pages/blocks/stat.js +9 -5
- package/dist/app/pages/field-value.js +1 -1
- package/dist/app/record-page.js +8 -4
- package/dist/app/router.js +7 -8
- package/dist/app/saved/saved-records.js +1 -1
- package/dist/app/search/search-model.js +1 -1
- package/dist/app/searches/use-save-search.js +4 -3
- package/dist/app/source-notice.js +2 -2
- package/dist/app/use-record-editor.js +5 -3
- package/dist/app-shell/app-shell.d.ts +1 -0
- package/dist/app-shell/app-shell.js +6 -4
- package/dist/app-shell/page-scroll.js +21 -4
- package/dist/app-shell/sidebar.d.ts +1 -0
- package/dist/app-shell/sidebar.js +4 -4
- package/dist/app-shell/top-bar.js +4 -4
- package/dist/auth/auth-gate.js +18 -9
- package/dist/auth/auth-provider.js +1 -0
- package/dist/auth/code-form.js +77 -0
- package/dist/auth/email-code-form.js +18 -77
- package/dist/auth/forgot-password-form.js +10 -10
- package/dist/auth/forgot-password-page.js +2 -2
- package/dist/auth/resend-code-button.js +29 -0
- package/dist/auth/sign-in-form.js +7 -8
- package/dist/auth/sign-in-page.js +3 -3
- package/dist/auth/sign-in-prompt.js +13 -9
- package/dist/auth/sign-up-code-form.js +22 -0
- package/dist/auth/sign-up-details-form.js +81 -111
- package/dist/auth/sign-up-page.js +17 -8
- package/dist/auth/two-factor-form.js +3 -3
- package/dist/auth/use-sign-in-address.js +21 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/lib/flip-guard.js +43 -0
- package/dist/lib/page-scroll-lock.js +20 -0
- package/dist/lib/use-focus-trap.js +4 -4
- package/dist/organizations/invitation-page.js +7 -6
- package/dist/package.js +1 -1
- package/dist/primitives/otp-input.d.ts +21 -0
- package/dist/primitives/otp-input.js +117 -0
- package/dist/primitives/otp-value.js +23 -0
- package/dist/primitives/route-link.d.ts +1 -0
- package/dist/primitives/route-link.js +20 -0
- package/dist/primitives/textarea.js +36 -0
- package/dist/record-view/field.js +56 -53
- package/dist/shell/assets/app-DJAZP1yB.js +66 -0
- package/dist/shell/assets/index-C5pYkUfv.css +2 -0
- package/dist/shell/assets/{index-CrtAqGCx.js → index-LBhMBiK4.js} +1 -1
- package/dist/shell/assets/maplibre-Dy0ZTnFZ.js +814 -0
- package/dist/shell/assets/record-map-BiWSbqqT.js +1 -0
- package/dist/shell/assets/records-map-DabYc3ad.js +1 -0
- package/dist/shell/assets/shared-protobase-ui-BURelnPG.js +1 -0
- package/dist/shell/index.html +6 -6
- package/dist/shell/protobase.shell.json +1 -1
- package/dist/styles.css +15 -0
- package/dist/toasts/toast.js +22 -6
- package/package.json +4 -4
- package/dist/auth/code-input.js +0 -17
- package/dist/auth/sign-in-address.js +0 -47
- package/dist/shell/assets/app-CpFoFNtG.js +0 -66
- package/dist/shell/assets/index-ibaHR5wQ.css +0 -2
- package/dist/shell/assets/maplibre-gl-B_TZ9n3D.js +0 -1
- package/dist/shell/assets/record-map-B2mkMEcE.js +0 -814
- package/dist/shell/assets/records-map-CAj21Al1.js +0 -1
- package/dist/shell/assets/shared-protobase-ui-D942ARkw.js +0 -1
- /package/dist/shell/assets/{record-map-DBE96hFo.css → maplibre-DBE96hFo.css} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { areaFeatures, fadeIn } from "./area-features.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Layer, Source } from "react-map-gl/maplibre";
|
|
4
|
+
//#region src/app/map/position-areas.tsx
|
|
5
|
+
const polygons = [
|
|
6
|
+
"==",
|
|
7
|
+
["get", "kind"],
|
|
8
|
+
"polygon"
|
|
9
|
+
];
|
|
10
|
+
const lines = [
|
|
11
|
+
"==",
|
|
12
|
+
["get", "kind"],
|
|
13
|
+
"line"
|
|
14
|
+
];
|
|
15
|
+
const chosen = (yes, no) => [
|
|
16
|
+
"case",
|
|
17
|
+
["get", "chosen"],
|
|
18
|
+
yes,
|
|
19
|
+
no
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* The areas around the approximate positions among `points`, drawn under the markers in the markers' colour: a polygon
|
|
23
|
+
* filled faintly within a dashed outline, a line such as a street as a wide stroke. Each fades in as the map zooms close
|
|
24
|
+
* enough for it to be larger than a marker, and the chosen records' areas are drawn darker. Nothing without areas.
|
|
25
|
+
*/
|
|
26
|
+
const PositionAreas = ({ points, selected, colors }) => {
|
|
27
|
+
const data = areaFeatures(points, selected);
|
|
28
|
+
if (data.features.length === 0) return null;
|
|
29
|
+
const color = [
|
|
30
|
+
"case",
|
|
31
|
+
["get", "chosen"],
|
|
32
|
+
colors.chosen,
|
|
33
|
+
colors.area
|
|
34
|
+
];
|
|
35
|
+
return /* @__PURE__ */ jsxs(Source, {
|
|
36
|
+
id: "position-areas",
|
|
37
|
+
type: "geojson",
|
|
38
|
+
data,
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx(Layer, {
|
|
41
|
+
id: "position-area-fills",
|
|
42
|
+
type: "fill",
|
|
43
|
+
filter: polygons,
|
|
44
|
+
paint: {
|
|
45
|
+
"fill-color": color,
|
|
46
|
+
"fill-opacity": fadeIn(chosen(.15, .1))
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
/* @__PURE__ */ jsx(Layer, {
|
|
50
|
+
id: "position-area-outlines",
|
|
51
|
+
type: "line",
|
|
52
|
+
filter: polygons,
|
|
53
|
+
paint: {
|
|
54
|
+
"line-color": color,
|
|
55
|
+
"line-width": 1.5,
|
|
56
|
+
"line-dasharray": [3, 2],
|
|
57
|
+
"line-opacity": fadeIn(.8)
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx(Layer, {
|
|
61
|
+
id: "position-area-lines",
|
|
62
|
+
type: "line",
|
|
63
|
+
filter: lines,
|
|
64
|
+
layout: {
|
|
65
|
+
"line-cap": "round",
|
|
66
|
+
"line-join": "round"
|
|
67
|
+
},
|
|
68
|
+
paint: {
|
|
69
|
+
"line-color": color,
|
|
70
|
+
"line-width": 6,
|
|
71
|
+
"line-opacity": fadeIn(chosen(.6, .35))
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { PositionAreas };
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
+
import { mapLib } from "./maplibre.js";
|
|
1
2
|
import { MapPin } from "lucide-react";
|
|
2
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import * as maplibre from "maplibre-gl";
|
|
4
|
-
import workerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";
|
|
5
|
-
import "maplibre-gl/dist/maplibre-gl.css";
|
|
6
|
-
import { Protocol } from "pmtiles";
|
|
7
4
|
import { Map as Map$1, Marker, NavigationControl } from "react-map-gl/maplibre";
|
|
8
5
|
//#region src/app/map/record-map.tsx
|
|
9
|
-
maplibre.setWorkerUrl(workerUrl);
|
|
10
|
-
maplibre.addProtocol("pmtiles", new Protocol().tile);
|
|
11
6
|
/**
|
|
12
7
|
* A map of `style` centred on `position` at `zoom`, with a pin on it. It pans and zooms with two fingers on a phone and
|
|
13
8
|
* with Ctrl or Cmd and the wheel, so scrolling the page past it does not move it.
|
|
14
9
|
*/
|
|
15
10
|
const RecordMap = ({ style, position, zoom }) => /* @__PURE__ */ jsxs(Map$1, {
|
|
16
|
-
mapLib
|
|
11
|
+
mapLib,
|
|
17
12
|
mapStyle: style,
|
|
18
13
|
initialViewState: {
|
|
19
14
|
...position,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
//#region src/app/map/record-position.ts
|
|
2
|
-
|
|
2
|
+
/** A number field's value: it comes as a number, or as text for a decimal or bigint; anything else, or an empty value, is none. */
|
|
3
|
+
const numeric = (value) => {
|
|
3
4
|
if (typeof value === "number") return value;
|
|
4
5
|
if (typeof value !== "string" || value.trim() === "") return void 0;
|
|
5
6
|
return Number(value);
|
|
6
7
|
};
|
|
7
8
|
/** The record's position from its two fields, when both hold degrees on the globe; none otherwise, so no map is drawn. */
|
|
8
9
|
const recordPosition = (record, fields) => {
|
|
9
|
-
const latitude =
|
|
10
|
-
const longitude =
|
|
10
|
+
const latitude = numeric(record[fields.latitude]);
|
|
11
|
+
const longitude = numeric(record[fields.longitude]);
|
|
11
12
|
if (latitude === void 0 || longitude === void 0) return void 0;
|
|
12
13
|
if (!(Math.abs(latitude) <= 90 && Math.abs(longitude) <= 180)) return void 0;
|
|
13
14
|
return {
|
|
@@ -16,4 +17,4 @@ const recordPosition = (record, fields) => {
|
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
19
|
//#endregion
|
|
19
|
-
export { recordPosition };
|
|
20
|
+
export { numeric, recordPosition };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { cn } from "../../lib/cn.js";
|
|
2
2
|
import { groupPoints } from "../displays/map-groups.js";
|
|
3
|
+
import { mapLib } from "./maplibre.js";
|
|
4
|
+
import { PositionAreas } from "./position-areas.js";
|
|
5
|
+
import { themeColor } from "./theme-color.js";
|
|
3
6
|
import { useEffect, useRef, useState } from "react";
|
|
4
7
|
import { MapPin } from "lucide-react";
|
|
5
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import * as maplibre from "maplibre-gl";
|
|
7
9
|
import { Map as Map$1, Marker, NavigationControl } from "react-map-gl/maplibre";
|
|
8
10
|
//#region src/app/map/records-map.tsx
|
|
9
11
|
const groupRadius = 28;
|
|
@@ -25,13 +27,15 @@ const compact = new Intl.NumberFormat("en-IE", {
|
|
|
25
27
|
const corners = (bounds) => [[bounds.west, bounds.south], [bounds.east, bounds.north]];
|
|
26
28
|
/**
|
|
27
29
|
* A map of `style` with a marker for each group of records that lie close together at the zoom, showing how many it
|
|
28
|
-
* stands for, and a circle with the count of each bucket, which zooms in on its records when chosen.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* stands for, and a circle with the count of each bucket, which zooms in on its records when chosen. A marker whose
|
|
31
|
+
* records' positions are all approximate is drawn hollow with a dashed edge, over the areas around them. Choosing a
|
|
32
|
+
* marker selects its records; choosing the map elsewhere clears the selection. A chosen marker the covered bottom would
|
|
33
|
+
* hide moves up into the open part of the map.
|
|
31
34
|
*/
|
|
32
35
|
const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, selected, covered, onSelect, onClear, markerLabel, bucketLabel }) => {
|
|
33
36
|
const ref = useRef(null);
|
|
34
37
|
const [groups, setGroups] = useState([]);
|
|
38
|
+
const [colors, setColors] = useState();
|
|
35
39
|
const byKey = new globalThis.Map(points.map((point) => [point.key, point]));
|
|
36
40
|
const pointKeys = points.map((point) => point.key).join(",");
|
|
37
41
|
const fitKey = fit && JSON.stringify(fit);
|
|
@@ -87,7 +91,7 @@ const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, se
|
|
|
87
91
|
}, [chosenAt, covered]);
|
|
88
92
|
return /* @__PURE__ */ jsxs(Map$1, {
|
|
89
93
|
ref,
|
|
90
|
-
mapLib
|
|
94
|
+
mapLib,
|
|
91
95
|
mapStyle: style,
|
|
92
96
|
initialViewState: initial ?? {
|
|
93
97
|
latitude: 0,
|
|
@@ -99,6 +103,11 @@ const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, se
|
|
|
99
103
|
height: "100%"
|
|
100
104
|
},
|
|
101
105
|
onLoad: () => {
|
|
106
|
+
const container = ref.current.getMap().getContainer();
|
|
107
|
+
setColors({
|
|
108
|
+
area: themeColor(container, "--primary"),
|
|
109
|
+
chosen: themeColor(container, "--foreground")
|
|
110
|
+
});
|
|
102
111
|
regroup();
|
|
103
112
|
if (fit) fitNow();
|
|
104
113
|
else report();
|
|
@@ -108,6 +117,11 @@ const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, se
|
|
|
108
117
|
onClick: onClear,
|
|
109
118
|
children: [
|
|
110
119
|
/* @__PURE__ */ jsx(NavigationControl, { showCompass: false }),
|
|
120
|
+
colors && /* @__PURE__ */ jsx(PositionAreas, {
|
|
121
|
+
points,
|
|
122
|
+
selected,
|
|
123
|
+
colors
|
|
124
|
+
}),
|
|
111
125
|
buckets.map((bucket) => /* @__PURE__ */ jsx(Marker, {
|
|
112
126
|
latitude: bucket.latitude,
|
|
113
127
|
longitude: bucket.longitude,
|
|
@@ -127,6 +141,7 @@ const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, se
|
|
|
127
141
|
const at = byKey.get(group.at);
|
|
128
142
|
if (!at) return null;
|
|
129
143
|
const chosen = selected !== void 0 && group.keys.some((key) => selected.includes(key));
|
|
144
|
+
const approximate = group.keys.every((key) => byKey.get(key)?.approximate);
|
|
130
145
|
return /* @__PURE__ */ jsx(Marker, {
|
|
131
146
|
latitude: at.latitude,
|
|
132
147
|
longitude: at.longitude,
|
|
@@ -143,8 +158,10 @@ const RecordsMap = ({ style, initial, points, buckets, fit, onFitted, onMove, se
|
|
|
143
158
|
},
|
|
144
159
|
children: [/* @__PURE__ */ jsx(MapPin, {
|
|
145
160
|
"aria-hidden": true,
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
"data-approximate": approximate || void 0,
|
|
162
|
+
className: cn("size-8 drop-shadow", approximate ? chosen ? "fill-background text-foreground" : "fill-background text-primary" : chosen ? "fill-foreground text-background" : "fill-primary text-primary-foreground"),
|
|
163
|
+
strokeWidth: approximate ? 2 : 1.5,
|
|
164
|
+
strokeDasharray: approximate ? "3 2" : void 0
|
|
148
165
|
}), group.keys.length > 1 && /* @__PURE__ */ jsx("span", {
|
|
149
166
|
className: "absolute -right-2 -top-1 min-w-5 rounded-full border border-background bg-foreground px-1 text-center text-[11px] font-medium leading-4 text-background tabular-nums",
|
|
150
167
|
children: group.keys.length
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/app/map/theme-color.ts
|
|
2
|
+
/**
|
|
3
|
+
* The colour a theme token such as `--primary` holds where `element` is, as `rgba()`, which MapLibre's paint reads
|
|
4
|
+
* whatever the theme writes it in: the browser resolves the token, and a pixel painted with it gives its channels.
|
|
5
|
+
*/
|
|
6
|
+
const themeColor = (element, token) => {
|
|
7
|
+
const probe = document.createElement("span");
|
|
8
|
+
probe.style.color = `var(${token})`;
|
|
9
|
+
element.append(probe);
|
|
10
|
+
const resolved = getComputedStyle(probe).color;
|
|
11
|
+
probe.remove();
|
|
12
|
+
const canvas = document.createElement("canvas");
|
|
13
|
+
canvas.width = 1;
|
|
14
|
+
canvas.height = 1;
|
|
15
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
16
|
+
if (!context) return resolved;
|
|
17
|
+
context.fillStyle = resolved;
|
|
18
|
+
context.fillRect(0, 0, 1, 1);
|
|
19
|
+
const [red, green, blue, alpha] = context.getImageData(0, 0, 1, 1).data;
|
|
20
|
+
return `rgba(${red}, ${green}, ${blue}, ${alpha / 255})`;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { themeColor };
|
package/dist/app/meta-gate.js
CHANGED
|
@@ -15,7 +15,7 @@ const useAdminMeta = () => {
|
|
|
15
15
|
return meta;
|
|
16
16
|
};
|
|
17
17
|
const Notice = ({ title, children }) => /* @__PURE__ */ jsx("div", {
|
|
18
|
-
className: "flex h-full min-h-48 items-center justify-center p-8",
|
|
18
|
+
className: "flex h-full min-h-48 flex-1 items-center justify-center p-8",
|
|
19
19
|
children: /* @__PURE__ */ jsxs("div", {
|
|
20
20
|
className: "max-w-md text-center",
|
|
21
21
|
children: [/* @__PURE__ */ jsx("h1", {
|
package/dist/app/nav-recent.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { recordKey, recordTitle, recordTitleField } from "../live/model-helpers.js";
|
|
2
2
|
import { defaultOrderBy } from "./list-order.js";
|
|
3
|
-
import { defaultRecentLimit, encodeKey } from "@protobase/schema/internal";
|
|
4
3
|
import { appPath, enumLabel } from "@protobase/schema";
|
|
4
|
+
import { defaultRecentLimit, encodeKey } from "@protobase/schema/internal";
|
|
5
5
|
//#region src/app/nav-recent.ts
|
|
6
6
|
/** The list request behind a sidebar group: its filter, order (the list's sort when unset), size, and only the fields it shows. */
|
|
7
7
|
const recentRequest = (model, view, recent) => ({
|
|
@@ -2,7 +2,7 @@ import { cn } from "../../../lib/cn.js";
|
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
//#region src/app/pages/blocks/card-frame.tsx
|
|
4
4
|
/** The card every block that shows a box uses: title, description and header actions over the body. */
|
|
5
|
-
const CardFrame = ({ title, description, actions, className, children }) => /* @__PURE__ */ jsxs("section", {
|
|
5
|
+
const CardFrame = ({ title, description, actions, className, bodyClassName, children }) => /* @__PURE__ */ jsxs("section", {
|
|
6
6
|
className: cn("flex min-w-0 flex-col rounded-lg border border-border bg-background", className),
|
|
7
7
|
"aria-label": title,
|
|
8
8
|
children: [(title || description || actions) && /* @__PURE__ */ jsxs("header", {
|
|
@@ -21,7 +21,7 @@ const CardFrame = ({ title, description, actions, className, children }) => /* @
|
|
|
21
21
|
children: actions
|
|
22
22
|
})]
|
|
23
23
|
}), /* @__PURE__ */ jsx("div", {
|
|
24
|
-
className: "min-w-0 flex-1 p-4 text-[13px]",
|
|
24
|
+
className: cn("min-w-0 flex-1 p-4 text-[13px]", bodyClassName),
|
|
25
25
|
children
|
|
26
26
|
})]
|
|
27
27
|
});
|
|
@@ -8,18 +8,26 @@ const columns = {
|
|
|
8
8
|
3: "md:grid-cols-2 xl:grid-cols-3",
|
|
9
9
|
4: "sm:grid-cols-2 xl:grid-cols-4"
|
|
10
10
|
};
|
|
11
|
+
const statColumns = {
|
|
12
|
+
1: "",
|
|
13
|
+
2: "grid-cols-2",
|
|
14
|
+
3: "grid-cols-2 xl:grid-cols-3",
|
|
15
|
+
4: "grid-cols-2 xl:grid-cols-4"
|
|
16
|
+
};
|
|
11
17
|
const spans = {
|
|
12
18
|
1: "",
|
|
13
19
|
2: "md:col-span-2",
|
|
14
20
|
3: "md:col-span-2 xl:col-span-3",
|
|
15
21
|
4: "sm:col-span-2 md:col-span-2 xl:col-span-4"
|
|
16
22
|
};
|
|
17
|
-
|
|
23
|
+
const isStat = (child) => typeof child === "object" && !child.custom && child.type === "Stat";
|
|
24
|
+
/** Columns that collapse to one on a phone, or two when it holds only `Stat`s; a child's `span` makes it wider. */
|
|
18
25
|
const GridBlock = ({ node, children }) => {
|
|
19
26
|
const { columns: count = 2 } = propsOf(node);
|
|
20
27
|
const childNodes = node.children;
|
|
28
|
+
const stats = childNodes.length > 0 && childNodes.every(isStat);
|
|
21
29
|
return /* @__PURE__ */ jsx("div", {
|
|
22
|
-
className: cn("grid grid-cols-1 gap-4", columns[count]),
|
|
30
|
+
className: cn("grid grid-cols-1 gap-4", stats ? statColumns[count] : columns[count]),
|
|
23
31
|
children: children.map((child, index) => {
|
|
24
32
|
const element = childNodes[index];
|
|
25
33
|
const span = typeof element === "object" ? element.props.span : void 0;
|
|
@@ -2,8 +2,8 @@ import { AppLink } from "../../use-app-address.js";
|
|
|
2
2
|
import { useLayoutRecord } from "../record-scope.js";
|
|
3
3
|
import { propsOf } from "./block-props.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { fillAddress } from "@protobase/schema/internal";
|
|
6
5
|
import { appPath } from "@protobase/schema";
|
|
6
|
+
import { fillAddress } from "@protobase/schema/internal";
|
|
7
7
|
//#region src/app/pages/blocks/link.tsx
|
|
8
8
|
const style = "font-medium text-primary-text hover:underline";
|
|
9
9
|
/**
|
|
@@ -5,7 +5,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
const PageBlock = ({ node, children, slots }) => {
|
|
6
6
|
const { title, description } = propsOf(node);
|
|
7
7
|
return /* @__PURE__ */ jsx("div", {
|
|
8
|
-
className: "
|
|
8
|
+
className: "flex-1",
|
|
9
9
|
children: /* @__PURE__ */ jsxs("div", {
|
|
10
10
|
className: "mx-auto flex max-w-[1200px] flex-col gap-6 px-4 pb-16 pt-6 md:px-10 md:py-8",
|
|
11
11
|
children: [/* @__PURE__ */ jsx(PageHeader, {
|
|
@@ -23,7 +23,7 @@ const Count = ({ model, filter }) => {
|
|
|
23
23
|
resource: model.name,
|
|
24
24
|
filter
|
|
25
25
|
},
|
|
26
|
-
className: `${big} hover:text-primary-text`,
|
|
26
|
+
className: `${big} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,
|
|
27
27
|
children: count.data.toLocaleString("en-IE")
|
|
28
28
|
});
|
|
29
29
|
};
|
|
@@ -41,20 +41,24 @@ const RecordValue = ({ field, format }) => {
|
|
|
41
41
|
})
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* One number or value with a label: fixed, a count of matching records (linking to them from anywhere on the card), or
|
|
46
|
+
* a field of the record. A label that wraps pushes nothing out of line: the value sits at the card's bottom.
|
|
47
|
+
*/
|
|
45
48
|
const StatBlock = ({ node }) => {
|
|
46
49
|
const { label, value, resource, filter, field, format, description } = propsOf(node);
|
|
47
50
|
const { resources } = useAdminMeta();
|
|
48
51
|
const model = resource === void 0 ? void 0 : resources[resource];
|
|
49
52
|
return /* @__PURE__ */ jsxs(CardFrame, {
|
|
50
|
-
className: "h-full",
|
|
53
|
+
className: "relative h-full",
|
|
54
|
+
bodyClassName: "flex flex-col",
|
|
51
55
|
children: [
|
|
52
56
|
/* @__PURE__ */ jsx("p", {
|
|
53
|
-
className: "text-[13px] text-muted-foreground",
|
|
57
|
+
className: "text-[13px] text-muted-foreground break-words",
|
|
54
58
|
children: label
|
|
55
59
|
}),
|
|
56
60
|
/* @__PURE__ */ jsxs("div", {
|
|
57
|
-
className: "mt-1",
|
|
61
|
+
className: "mt-auto pt-1",
|
|
58
62
|
children: [
|
|
59
63
|
value !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
60
64
|
className: big,
|
|
@@ -77,7 +77,7 @@ const BuiltInValue = ({ model, field, value, format, relationLabel }) => {
|
|
|
77
77
|
children: text
|
|
78
78
|
});
|
|
79
79
|
return /* @__PURE__ */ jsx("span", {
|
|
80
|
-
className: cn(hints.format === "code" && "font-mono text-xs", (field.type === "decimal" || field.type === "integer") && "tabular-nums"),
|
|
80
|
+
className: cn(hints.format === "code" && "font-mono text-xs", (field.type === "decimal" || field.type === "integer") && "tabular-nums", hints.multiline && "whitespace-pre-line break-words"),
|
|
81
81
|
children: text
|
|
82
82
|
});
|
|
83
83
|
};
|
package/dist/app/record-page.js
CHANGED
|
@@ -144,6 +144,7 @@ const LoadedRecord = ({ model, recordKey, stored }) => {
|
|
|
144
144
|
label: hint(name)?.label ?? humanize(name),
|
|
145
145
|
help: hint(name)?.help,
|
|
146
146
|
error: editor.errors[name],
|
|
147
|
+
wide: Boolean(hint(name)?.multiline),
|
|
147
148
|
conflict: conflict === void 0 ? void 0 : {
|
|
148
149
|
user: {
|
|
149
150
|
name: "Someone else",
|
|
@@ -181,7 +182,10 @@ const LoadedRecord = ({ model, recordKey, stored }) => {
|
|
|
181
182
|
value: stored.record[name],
|
|
182
183
|
hints: hint(name),
|
|
183
184
|
children: text
|
|
184
|
-
}) : /* @__PURE__ */ jsx("strong", {
|
|
185
|
+
}) : /* @__PURE__ */ jsx("strong", {
|
|
186
|
+
className: hint(name)?.multiline ? "whitespace-pre-line break-words" : void 0,
|
|
187
|
+
children: text
|
|
188
|
+
});
|
|
185
189
|
const shown = shownWidget(fieldTypes, field, hint(name));
|
|
186
190
|
return [{
|
|
187
191
|
label: hint(name)?.label ?? humanize(name),
|
|
@@ -234,11 +238,11 @@ const LoadedRecord = ({ model, recordKey, stored }) => {
|
|
|
234
238
|
})
|
|
235
239
|
] });
|
|
236
240
|
return /* @__PURE__ */ jsxs("div", {
|
|
237
|
-
className: "flex
|
|
241
|
+
className: "flex flex-1 flex-col",
|
|
238
242
|
children: [
|
|
239
243
|
remove.dialogs,
|
|
240
244
|
/* @__PURE__ */ jsx("div", {
|
|
241
|
-
className: "
|
|
245
|
+
className: "flex-1",
|
|
242
246
|
children: /* @__PURE__ */ jsxs("div", {
|
|
243
247
|
className: "mx-auto max-w-[1100px] px-4 pb-8 pt-6 md:px-10 md:py-8",
|
|
244
248
|
children: [
|
|
@@ -364,7 +368,7 @@ const LoadedRecord = ({ model, recordKey, stored }) => {
|
|
|
364
368
|
})
|
|
365
369
|
}),
|
|
366
370
|
(editor.dirty || canDelete || canUpdate) && /* @__PURE__ */ jsx("div", {
|
|
367
|
-
className: "flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden",
|
|
371
|
+
className: "sticky bottom-[var(--pb-sticky-bottom,0px)] z-20 flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden",
|
|
368
372
|
children: saveControls
|
|
369
373
|
})
|
|
370
374
|
]
|
package/dist/app/router.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteLink } from "../primitives/route-link.js";
|
|
1
2
|
import { Button } from "../primitives/button.js";
|
|
2
3
|
import { Dialog } from "../primitives/dialog.js";
|
|
3
4
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -112,15 +113,13 @@ const Router = ({ basePath = "", initialUrl, children }) => {
|
|
|
112
113
|
})]
|
|
113
114
|
});
|
|
114
115
|
};
|
|
115
|
-
|
|
116
|
+
/** A link to a path below the base path, as `appPath` writes it, that the router follows without reloading the page. */
|
|
117
|
+
const Link = ({ to, replace, ...rest }) => {
|
|
116
118
|
const { navigate, basePath } = useRouter();
|
|
117
|
-
return /* @__PURE__ */ jsx(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.button !== 0) return;
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
navigate(to);
|
|
119
|
+
return /* @__PURE__ */ jsx(RouteLink, {
|
|
120
|
+
to: {
|
|
121
|
+
href: `${basePath}${to}`,
|
|
122
|
+
onFollow: () => navigate(to, { replace })
|
|
124
123
|
},
|
|
125
124
|
...rest
|
|
126
125
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { recordKey } from "../../live/model-helpers.js";
|
|
2
|
-
import { encodeKey } from "@protobase/schema/internal";
|
|
3
2
|
import { createWhere } from "@protobase/schema";
|
|
3
|
+
import { encodeKey } from "@protobase/schema/internal";
|
|
4
4
|
//#region src/app/saved/saved-records.ts
|
|
5
5
|
const where = createWhere();
|
|
6
6
|
const relationValue = (value) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { recordKey, recordTitleField } from "../../live/model-helpers.js";
|
|
2
2
|
import { humanize } from "../../live/naming.js";
|
|
3
|
-
import { encodeKey, matchedSearchField } from "@protobase/schema/internal";
|
|
4
3
|
import { appPath, createWhere, enumLabel, printFilter } from "@protobase/schema";
|
|
4
|
+
import { encodeKey, matchedSearchField } from "@protobase/schema/internal";
|
|
5
5
|
//#region src/app/search/search-model.ts
|
|
6
6
|
const where = createWhere();
|
|
7
7
|
const searchTargets = (meta) => Object.values(meta.resources).flatMap((model) => {
|
|
@@ -20,7 +20,7 @@ const useSaveSearch = (search, filter, name) => {
|
|
|
20
20
|
const client = useClient();
|
|
21
21
|
const toast = useToast();
|
|
22
22
|
const refresh = useRefreshResource();
|
|
23
|
-
const {
|
|
23
|
+
const { href, open } = useAppAddress();
|
|
24
24
|
const { resource } = search;
|
|
25
25
|
const model = meta.resources[resource];
|
|
26
26
|
const of = meta.views[resource]?.searchesOf;
|
|
@@ -44,10 +44,11 @@ const useSaveSearch = (search, filter, name) => {
|
|
|
44
44
|
title: "Search saved",
|
|
45
45
|
action: {
|
|
46
46
|
label: `Open ${plural.toLowerCase()}`,
|
|
47
|
-
|
|
47
|
+
href: href({
|
|
48
48
|
kind: "list",
|
|
49
49
|
resource
|
|
50
|
-
})
|
|
50
|
+
}),
|
|
51
|
+
onNavigate: open
|
|
51
52
|
}
|
|
52
53
|
});
|
|
53
54
|
},
|
|
@@ -14,7 +14,7 @@ const reason = (error) => {
|
|
|
14
14
|
const SourceNotice = ({ status }) => {
|
|
15
15
|
const queryClient = useQueryClient();
|
|
16
16
|
if (status.state !== "error") return /* @__PURE__ */ jsxs("div", {
|
|
17
|
-
className: "flex h-full min-h-48 items-center justify-center gap-2 text-[13px] text-muted-foreground",
|
|
17
|
+
className: "flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-[13px] text-muted-foreground",
|
|
18
18
|
children: [
|
|
19
19
|
/* @__PURE__ */ jsx(Spinner, {}),
|
|
20
20
|
" Loading from ",
|
|
@@ -22,7 +22,7 @@ const SourceNotice = ({ status }) => {
|
|
|
22
22
|
]
|
|
23
23
|
});
|
|
24
24
|
return /* @__PURE__ */ jsx("div", {
|
|
25
|
-
className: "flex h-full min-h-48 items-center justify-center p-8",
|
|
25
|
+
className: "flex h-full min-h-48 flex-1 items-center justify-center p-8",
|
|
26
26
|
children: /* @__PURE__ */ jsxs("div", {
|
|
27
27
|
className: "max-w-md text-center",
|
|
28
28
|
children: [
|
|
@@ -27,7 +27,8 @@ const useRecordEditor = ({ model, stored, recordKey, mode, subject, draftKey, li
|
|
|
27
27
|
const [linesConflict, setLinesConflict] = useState(false);
|
|
28
28
|
const [conflicts, setConflicts] = useState({});
|
|
29
29
|
const [errors, setErrors] = useState({});
|
|
30
|
-
const
|
|
30
|
+
const changed = Object.entries(draft).filter(([name, entry]) => differs(model.fields[name], entry, stored.record[name]));
|
|
31
|
+
const fieldsDirty = changed.length > 0;
|
|
31
32
|
const dirty = fieldsDirty || Boolean(lines?.dirty);
|
|
32
33
|
useEffect(() => {
|
|
33
34
|
if (restored?.order) lines?.setOrder(restored.order);
|
|
@@ -52,7 +53,8 @@ const useRecordEditor = ({ model, stored, recordKey, mode, subject, draftKey, li
|
|
|
52
53
|
const value = (name) => name in draft ? draft[name] : ["boolean", "file"].includes(model.fields[name].type) ? stored.record[name] : toDraft(stored.record[name]);
|
|
53
54
|
const change = (name, next) => {
|
|
54
55
|
setErrors((current) => without(current, name));
|
|
55
|
-
|
|
56
|
+
const typed = typeof next === "string" ? next !== toDraft(stored.record[name]) : differs(model.fields[name], next, stored.record[name]);
|
|
57
|
+
setDraft((current) => typed ? {
|
|
56
58
|
...current,
|
|
57
59
|
[name]: next
|
|
58
60
|
} : without(current, name));
|
|
@@ -71,7 +73,7 @@ const useRecordEditor = ({ model, stored, recordKey, mode, subject, draftKey, li
|
|
|
71
73
|
setDraft(keep);
|
|
72
74
|
setConflicts(theirs);
|
|
73
75
|
};
|
|
74
|
-
const patchOf = () => Object.fromEntries(
|
|
76
|
+
const patchOf = () => Object.fromEntries(changed.map(([name, entry]) => [name, toPatchValue(model.fields[name], entry)]));
|
|
75
77
|
const fieldErrors = (error) => isApiError(error) ? Object.fromEntries(error.errors.flatMap((entry) => entry.field ? [[entry.field, entry.message]] : [])) : {};
|
|
76
78
|
const saveRecordOnly = async () => {
|
|
77
79
|
try {
|
|
@@ -2,24 +2,26 @@ import { cn } from "../lib/cn.js";
|
|
|
2
2
|
import { useIsDesktop } from "../lib/use-media-query.js";
|
|
3
3
|
import { BottomBar } from "./bottom-bar.js";
|
|
4
4
|
import { Drawer } from "./drawer.js";
|
|
5
|
-
import { PageScrollContext, usePageInsets } from "./page-scroll.js";
|
|
5
|
+
import { PageScrollContext, usePageGutter, usePageInsets } from "./page-scroll.js";
|
|
6
6
|
import { Sidebar } from "./sidebar.js";
|
|
7
7
|
import { TopBar } from "./top-bar.js";
|
|
8
8
|
import { useEffect, useRef, useState } from "react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
//#region src/app-shell/app-shell.tsx
|
|
11
11
|
const drawerId = "app-drawer";
|
|
12
|
-
const AppShell = ({ sidebarMode, activeItem, breadcrumb, user, workspace, actions, rightPanel, forceExpanded, profileMenuOpen, navGroups, userMenu, bottomBar, onNavigate, onSignOut,
|
|
12
|
+
const AppShell = ({ sidebarMode, activeItem, breadcrumb, user, workspace, actions, rightPanel, forceExpanded, profileMenuOpen, navGroups, userMenu, bottomBar, onNavigate, onSignOut, signIn, organizations, roles, theme, search, pageScroll: scrollsByDefault = false, className, children }) => {
|
|
13
13
|
const desktop = useIsDesktop();
|
|
14
14
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
if (desktop) setDrawerOpen(false);
|
|
17
17
|
}, [desktop]);
|
|
18
18
|
const tabs = !desktop && bottomBar && bottomBar.length > 0 ? bottomBar : void 0;
|
|
19
|
-
const [
|
|
19
|
+
const [chosen, setPageScroll] = useState();
|
|
20
|
+
const pageScroll = chosen ?? scrollsByDefault;
|
|
20
21
|
const topBarRef = useRef(null);
|
|
21
22
|
const bottomBarRef = useRef(null);
|
|
22
23
|
usePageInsets(pageScroll, topBarRef, bottomBarRef, Boolean(tabs));
|
|
24
|
+
usePageGutter(pageScroll);
|
|
23
25
|
const sidebar = (mode, sticky = false) => /* @__PURE__ */ jsx(Sidebar, {
|
|
24
26
|
mode,
|
|
25
27
|
sticky,
|
|
@@ -32,7 +34,7 @@ const AppShell = ({ sidebarMode, activeItem, breadcrumb, user, workspace, action
|
|
|
32
34
|
userMenu,
|
|
33
35
|
onNavigate,
|
|
34
36
|
onSignOut,
|
|
35
|
-
|
|
37
|
+
signIn,
|
|
36
38
|
organizations,
|
|
37
39
|
roles,
|
|
38
40
|
theme
|
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import { createContext, useContext, useLayoutEffect } from "react";
|
|
2
2
|
//#region src/app-shell/page-scroll.ts
|
|
3
|
-
/** Turns the shell's page scrolling on or off
|
|
3
|
+
/** Turns the shell's page scrolling on or off, or back to its `pageScroll` with `undefined`; pages use `usePageScroll`. */
|
|
4
4
|
const PageScrollContext = createContext(() => {});
|
|
5
5
|
/**
|
|
6
6
|
* While the calling page is shown and `on`, the document scrolls instead of a box of the screen's height: the top and
|
|
7
7
|
* bottom bars and the sidebar stick, and the page grows with its content, so the browser's own scrolling applies
|
|
8
8
|
* throughout, scrolling to the top included, as tapping the status bar on an iPhone does. Sticky content in the page
|
|
9
|
-
* stays clear of the bars with `--pb-sticky-top` and `--pb-sticky-bottom`.
|
|
9
|
+
* stays clear of the bars with `--pb-sticky-top` and `--pb-sticky-bottom`. Not `on`, the page fills the box instead,
|
|
10
|
+
* as a map does. Once the page is gone the shell's `pageScroll` applies again.
|
|
10
11
|
*/
|
|
11
12
|
const usePageScroll = (on) => {
|
|
12
13
|
const set = useContext(PageScrollContext);
|
|
13
14
|
useLayoutEffect(() => {
|
|
14
15
|
set(on);
|
|
15
|
-
return () => set(
|
|
16
|
+
return () => set(void 0);
|
|
16
17
|
}, [set, on]);
|
|
17
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* While the page scrolls, keeps room for its scrollbar whether or not the page overflows, where scrollbars take room
|
|
21
|
+
* (Windows, Linux, or a Mac set to always show them). Otherwise a page whose height follows its width, such as the
|
|
22
|
+
* cards, can be just too tall with the width without a scrollbar and short enough with the width beside one: the
|
|
23
|
+
* scrollbar narrows the cards, they get shorter, the page fits, the scrollbar goes, they widen again, every frame.
|
|
24
|
+
*/
|
|
25
|
+
const usePageGutter = (on) => {
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
if (!on) return;
|
|
28
|
+
const root = document.documentElement;
|
|
29
|
+
root.style.setProperty("scrollbar-gutter", "stable");
|
|
30
|
+
return () => {
|
|
31
|
+
root.style.removeProperty("scrollbar-gutter");
|
|
32
|
+
};
|
|
33
|
+
}, [on]);
|
|
34
|
+
};
|
|
18
35
|
const properties = [
|
|
19
36
|
"--pb-sticky-top",
|
|
20
37
|
"--pb-sticky-bottom",
|
|
@@ -53,4 +70,4 @@ const usePageInsets = (on, top, bottom, bottomShown) => {
|
|
|
53
70
|
]);
|
|
54
71
|
};
|
|
55
72
|
//#endregion
|
|
56
|
-
export { PageScrollContext, usePageInsets, usePageScroll };
|
|
73
|
+
export { PageScrollContext, usePageGutter, usePageInsets, usePageScroll };
|