@rebasepro/admin 0.13.0 → 0.13.1-canary.g18cfeb7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/{CollectionEditorDialog-CjXkWZ64.js → CollectionEditorDialog-CUFXevVg.js} +3 -3
  2. package/dist/{CollectionEditorDialog-CjXkWZ64.js.map → CollectionEditorDialog-CUFXevVg.js.map} +1 -1
  3. package/dist/{PropertyEditView-W8I3YV89.js → PropertyEditView-DDUC7giL.js} +2 -2
  4. package/dist/{PropertyEditView-W8I3YV89.js.map → PropertyEditView-DDUC7giL.js.map} +1 -1
  5. package/dist/{RouterCollectionsStudioView-BsLTNoqX.js → RouterCollectionsStudioView-vzS848Gf.js} +9 -13
  6. package/dist/RouterCollectionsStudioView-vzS848Gf.js.map +1 -0
  7. package/dist/collection_editor/serializable_types.d.ts +1 -0
  8. package/dist/collection_editor_ui.js +4 -4
  9. package/dist/components/AdditionalFieldValue.d.ts +25 -0
  10. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +16 -0
  11. package/dist/components/CollectionViewBinding/SlotValue.d.ts +63 -0
  12. package/dist/components/CollectionViewBinding/SplitListCloseButton.d.ts +17 -4
  13. package/dist/components/CollectionViewBinding/SplitListShowButton.d.ts +12 -0
  14. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +55 -5
  15. package/dist/components/DetailViewBinding.d.ts +15 -0
  16. package/dist/components/DrawerNavigationGroup.d.ts +9 -6
  17. package/dist/components/DrawerNavigationItem.d.ts +16 -6
  18. package/dist/components/EditViewBinding.d.ts +30 -1
  19. package/dist/components/EntityDisplayHeader.d.ts +53 -0
  20. package/dist/components/EntityIdentityBar.d.ts +43 -1
  21. package/dist/components/EntityViewBinding.d.ts +60 -6
  22. package/dist/components/RebaseLayout.d.ts +1 -1
  23. package/dist/components/RebaseShell.d.ts +1 -1
  24. package/dist/components/RelationSelector.d.ts +8 -1
  25. package/dist/components/UserSelector.d.ts +8 -1
  26. package/dist/components/app/Scaffold.d.ts +9 -3
  27. package/dist/components/index.d.ts +2 -0
  28. package/dist/{export-J79rMoNj.js → export-5bl2EoSs.js} +2 -2
  29. package/dist/{export-J79rMoNj.js.map → export-5bl2EoSs.js.map} +1 -1
  30. package/dist/form/components/FieldBlock.d.ts +58 -4
  31. package/dist/form/components/FormRail.d.ts +13 -0
  32. package/dist/form/components/FormSections.d.ts +15 -1
  33. package/dist/form/components/useRailVisible.d.ts +5 -4
  34. package/dist/form/form_utils.d.ts +38 -1
  35. package/dist/{history-D7L_JlLO.js → history-BuKKAhoY.js} +4 -4
  36. package/dist/{history-D7L_JlLO.js.map → history-BuKKAhoY.js.map} +1 -1
  37. package/dist/hooks/useEntityDisplay.d.ts +102 -0
  38. package/dist/hooks/useEntityDisplayTitle.d.ts +18 -9
  39. package/dist/{import-BvYl--U4.js → import-BhdWs34H.js} +3 -3
  40. package/dist/{import-BvYl--U4.js.map → import-BhdWs34H.js.map} +1 -1
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js +152 -57
  43. package/dist/index.js.map +1 -1
  44. package/dist/preview/compact_text.d.ts +23 -0
  45. package/dist/preview/components/BooleanPreview.d.ts +3 -1
  46. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  47. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  48. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  49. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  50. package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
  51. package/dist/routes/RebaseRoute.d.ts +1 -1
  52. package/dist/types/components/PropertyPreviewProps.d.ts +19 -0
  53. package/dist/util/number_format.d.ts +14 -0
  54. package/dist/util/previews.d.ts +9 -2
  55. package/dist/{util-GiwPgxnL.js → util-DNG7iK0w.js} +3756 -2300
  56. package/dist/util-DNG7iK0w.js.map +1 -0
  57. package/package.json +9 -9
  58. package/src/collection_editor/serializable_types.ts +1 -0
  59. package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +9 -11
  60. package/src/components/AdditionalFieldValue.tsx +68 -0
  61. package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +7 -8
  62. package/src/components/CollectionTableBinding/PropertyTableCell.tsx +2 -2
  63. package/src/components/CollectionTableBinding/column_utils.tsx +15 -6
  64. package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +2 -2
  65. package/src/components/CollectionViewBinding/BoardCardBinding.tsx +26 -27
  66. package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +723 -348
  67. package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
  68. package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +38 -8
  69. package/src/components/CollectionViewBinding/EntityCardBinding.tsx +23 -36
  70. package/src/components/CollectionViewBinding/SlotValue.tsx +156 -0
  71. package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +23 -7
  72. package/src/components/CollectionViewBinding/SplitListShowButton.tsx +28 -0
  73. package/src/components/CollectionViewBinding/SplitListView.tsx +33 -2
  74. package/src/components/CollectionViewBinding/useBoardDataController.tsx +12 -3
  75. package/src/components/CollectionViewBinding/usePreviewSlots.ts +183 -64
  76. package/src/components/CollectionViewBinding/utils.ts +7 -4
  77. package/src/components/DefaultDrawer.tsx +19 -23
  78. package/src/components/DetailViewBinding.tsx +93 -56
  79. package/src/components/DrawerNavigationGroup.tsx +16 -39
  80. package/src/components/DrawerNavigationItem.tsx +44 -16
  81. package/src/components/EditViewBinding.tsx +215 -42
  82. package/src/components/EntityDisplayHeader.tsx +170 -0
  83. package/src/components/EntityIdentityBar.tsx +163 -23
  84. package/src/components/EntityInspector.tsx +24 -6
  85. package/src/components/EntityPreviewBinding.tsx +58 -18
  86. package/src/components/EntityViewBinding.tsx +342 -41
  87. package/src/components/InlineEntityPreview.tsx +10 -10
  88. package/src/components/RebaseLayout.tsx +2 -2
  89. package/src/components/RebaseShell.tsx +2 -2
  90. package/src/components/ReferenceTable/SelectionTableBinding.tsx +4 -2
  91. package/src/components/RelationSelector.tsx +15 -4
  92. package/src/components/SideDialogs.tsx +15 -3
  93. package/src/components/SidePanelBinding.tsx +122 -66
  94. package/src/components/UserSelector.tsx +15 -4
  95. package/src/components/app/Scaffold.tsx +112 -10
  96. package/src/components/history/LastEditedByIndicator.tsx +7 -12
  97. package/src/components/index.ts +3 -0
  98. package/src/data_import/utils/data.ts +9 -1
  99. package/src/form/EntityForm.tsx +64 -52
  100. package/src/form/EntityFormBinding.tsx +24 -11
  101. package/src/form/PropertyFieldBinding.tsx +2 -2
  102. package/src/form/components/FieldBlock.tsx +80 -10
  103. package/src/form/components/FormRail.tsx +19 -2
  104. package/src/form/components/FormSections.tsx +32 -5
  105. package/src/form/components/StorageUploadProgress.tsx +9 -3
  106. package/src/form/components/useRailVisible.tsx +5 -4
  107. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -2
  108. package/src/form/field_bindings/BinaryFieldBinding.tsx +10 -5
  109. package/src/form/field_bindings/BlockFieldBinding.tsx +3 -3
  110. package/src/form/field_bindings/GeopointFieldBinding.tsx +23 -16
  111. package/src/form/field_bindings/MapFieldBinding.tsx +2 -2
  112. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +13 -7
  113. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +7 -1
  114. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +7 -1
  115. package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
  116. package/src/form/field_bindings/RelationFieldBinding.tsx +5 -2
  117. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
  118. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -2
  119. package/src/form/field_bindings/UserSelectFieldBinding.tsx +4 -1
  120. package/src/form/field_bindings/VectorFieldBinding.tsx +6 -4
  121. package/src/form/form_utils.ts +78 -0
  122. package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +29 -5
  123. package/src/hooks/useEntityDisplay.tsx +262 -0
  124. package/src/hooks/useEntityDisplayTitle.tsx +27 -38
  125. package/src/index.ts +9 -1
  126. package/src/preview/PropertyPreview.tsx +25 -5
  127. package/src/preview/compact_text.ts +68 -0
  128. package/src/preview/components/BooleanPreview.tsx +5 -2
  129. package/src/preview/components/StorageThumbnail.tsx +5 -2
  130. package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +6 -3
  131. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +26 -1
  132. package/src/preview/property_previews/ArrayOneOfPreview.tsx +10 -1
  133. package/src/preview/property_previews/ArrayPropertyPreview.tsx +10 -1
  134. package/src/preview/property_previews/MapPropertyPreview.tsx +52 -1
  135. package/src/preview/property_previews/NumberPropertyPreview.tsx +9 -1
  136. package/src/preview/property_previews/StringPropertyPreview.tsx +8 -5
  137. package/src/routes/RebaseRoute.tsx +62 -4
  138. package/src/types/components/PropertyPreviewProps.tsx +21 -0
  139. package/src/util/number_format.ts +46 -0
  140. package/src/util/previews.ts +8 -55
  141. package/src/util/property_utils.tsx +6 -1
  142. package/dist/RouterCollectionsStudioView-BsLTNoqX.js.map +0 -1
  143. package/dist/util-GiwPgxnL.js.map +0 -1
@@ -9,7 +9,7 @@ import { EditViewBinding } from "./EditViewBinding";
9
9
  import { DetailViewBinding } from "./DetailViewBinding";
10
10
  import { useSideDialogContext } from "./SideDialogs";
11
11
  import { useNavigate } from "react-router";
12
- import { saveEntityToMemoryCache, useComponentOverride } from "@rebasepro/app";
12
+ import { useComponentOverride } from "@rebasepro/app";
13
13
  import { useCollectionRegistryController } from "../hooks/navigation/contexts/CollectionRegistryContext";
14
14
  import { useSidePanel } from "../hooks/useSidePanel";
15
15
  import { useUrlController } from "../hooks/navigation/contexts/UrlContext";
@@ -49,21 +49,60 @@ export function SidePanelBinding(props: SidePanelBindingProps) {
49
49
  const sideDialogsController = useSideDialogContext();
50
50
  const urlController = useUrlController();
51
51
 
52
+ /**
53
+ * The X in the identity bar.
54
+ *
55
+ * Unforced, so it stops at the same unsaved-changes prompt that Escape and
56
+ * a click outside already do. It used to clear `blocked` and force the
57
+ * close, which made the one control actually labelled "close" the only way
58
+ * out of the panel that dropped an edit without asking.
59
+ *
60
+ * `props.onClose` is not called here: the panel carries the same callback
61
+ * (see `propsToSidePanel`) and {@link SideDialogs} fires it once the panel
62
+ * really closes — which is after the prompt, not before it.
63
+ */
52
64
  const onClose = () => {
53
- if (props.onClose) {
54
- props.onClose();
55
- }
65
+ close();
66
+ }
56
67
 
68
+ /**
69
+ * Closing because the record was just saved, which is the one case that has
70
+ * to force. `blocked` is driven by an effect on the form's dirty flag and is
71
+ * still true for a tick after a save; prompting about unsaved changes here
72
+ * would be asking about values that are already on the server.
73
+ */
74
+ const closeAfterSave = () => {
57
75
  setBlocked(false);
58
76
  close(true);
59
77
  }
60
78
 
79
+ /**
80
+ * The panel's response to a save, and the one place it decides where the
81
+ * panel goes next.
82
+ *
83
+ * Exactly **one** panel navigation is raised here. These branches used to
84
+ * run independently — a `replace` onto the saved record's address *and* a
85
+ * close — and because the last navigation is the one that survives, which
86
+ * of them the user got was settled by statement order rather than by
87
+ * intent. Closing wins by construction now: moving a panel to a new address
88
+ * it is about to leave is work whose only effect is to fight the close.
89
+ *
90
+ * `props.onUpdate` runs last for the same reason. It belongs to whoever
91
+ * opened the panel and it is free to navigate — the reference picker's
92
+ * selects the record and closes the picker — so the opener's intent should
93
+ * be the final word, not something this panel overwrites on its way out.
94
+ */
61
95
  const onUpdate = (params: OnUpdateParams) => {
62
- if (props.onUpdate) {
63
- props.onUpdate(params);
64
- }
65
96
  setEditInDialog(false);
66
- if (params.status !== "existing") {
97
+
98
+ // Either "save and close" was clicked, or the opener asked for it when
99
+ // it opened the panel.
100
+ const closeRequested = sideDialogsController.pendingClose || props.closeOnSave;
101
+
102
+ if (closeRequested) {
103
+ sideDialogsController.setPendingClose(false);
104
+ closeAfterSave();
105
+ } else if (params.status !== "existing") {
67
106
  // A newly created entity replaces the panel with its own address,
68
107
  // which already leaves the edit view behind.
69
108
  sidePanelController.replace({
@@ -77,11 +116,7 @@ export function SidePanelBinding(props: SidePanelBindingProps) {
77
116
  closeEditView();
78
117
  }
79
118
 
80
- if (sideDialogsController.pendingClose) {
81
- sideDialogsController.setPendingClose(false);
82
- onClose();
83
- }
84
-
119
+ props.onUpdate?.(params);
85
120
  }
86
121
 
87
122
  const parentCollectionSlugs = useMemo(() => {
@@ -181,6 +216,43 @@ entityId }
181
216
  return <div className={"w-full"}/>;
182
217
  }
183
218
 
219
+ const closeButton = (
220
+ <IconButton
221
+ className="self-center"
222
+ size={"small"}
223
+ onClick={onClose}>
224
+ <XIcon/>
225
+ </IconButton>
226
+ );
227
+
228
+ /**
229
+ * Where the panel's own two controls sit, which is not the same question in
230
+ * the two layouts that have them.
231
+ *
232
+ * A **side panel** slides in over the list from the right, and its leading
233
+ * edge is the seam between the two. Close belongs on that seam — it points
234
+ * back at the thing still visible behind it — and it is where the eye
235
+ * already is, because the breadcrumb starts there.
236
+ *
237
+ * A **dialog** has no seam and nothing behind it to point at. It is a box
238
+ * centred on a dimmed screen, and every box like it on every platform is
239
+ * dismissed from its top-right corner. Close was sitting at the far left
240
+ * of the bar, a full dialog's width from the expand button it belongs
241
+ * beside, in the one corner that means "back" in a layout with no back.
242
+ *
243
+ * So in a dialog the two travel together at the trailing edge, expand then
244
+ * close: the window controls, after the record's actions and its overflow
245
+ * menu, in the corner a dialog is closed from.
246
+ */
247
+ const barActionsStart = isDialogMode ? undefined : closeButton;
248
+
249
+ const windowControls = (expandButton: React.ReactNode) => (
250
+ <div className="flex gap-1 items-center">
251
+ {expandButton}
252
+ {isDialogMode && closeButton}
253
+ </div>
254
+ );
255
+
184
256
  return (
185
257
  <>
186
258
  <ErrorBoundary>
@@ -193,31 +265,20 @@ entityId }
193
265
  parentCollectionSlugs={parentCollectionSlugs}
194
266
  parentEntityIds={parentEntityIds}
195
267
  onEditClick={openEditView}
196
- barActionsStart={
197
- // At the bar's leading edge, where the breadcrumb
198
- // starts: the corner of the panel it closes.
199
- <IconButton
268
+ barActionsStart={barActionsStart}
269
+ barActions={() => windowControls(
270
+ allowFullScreen && <IconButton
200
271
  className="self-center"
201
272
  size={"small"}
202
- onClick={onClose}>
203
- <XIcon/>
204
- </IconButton>}
205
- barActions={({
206
- status,
207
- values
208
- }) => <div className="flex gap-1">
209
- {allowFullScreen && <IconButton
210
- className="self-center"
211
- size={"small"}
212
- onClick={() => {
213
- if (entityId) {
214
- const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
215
- navigate(fullScreenUrl, { state: null });
216
- }
217
- }}>
218
- <Maximize2Icon/>
219
- </IconButton>}
220
- </div>}
273
+ onClick={() => {
274
+ if (entityId) {
275
+ const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
276
+ navigate(fullScreenUrl, { state: null });
277
+ }
278
+ }}>
279
+ <Maximize2Icon/>
280
+ </IconButton>
281
+ )}
221
282
  onTabChange={({
222
283
  entityId: tabEntityId,
223
284
  selectedTab,
@@ -245,38 +306,33 @@ entityId }
245
306
  onValuesModified={onValuesModified}
246
307
  onSaved={onUpdate}
247
308
  navigateBack={closeEditView}
248
- barActionsStart={
249
- // At the bar's leading edge, where the breadcrumb
250
- // starts: the corner of the panel it closes.
251
- <IconButton
309
+ barActionsStart={barActionsStart}
310
+ barActions={({ carryEdit }) => windowControls(
311
+ allowFullScreen && <IconButton
252
312
  className="self-center"
253
313
  size={"small"}
254
- onClick={onClose}>
255
- <XIcon/>
256
- </IconButton>}
257
- barActions={({
258
- status,
259
- values
260
- }) => <div className="flex gap-1">
261
- {allowFullScreen && <IconButton
262
- className="self-center"
263
- size={"small"}
264
- onClick={() => {
265
- const key = (status === "new" || status === "copy") ? path + "#new" : path + "/" + entityId;
266
- saveEntityToMemoryCache(key, values);
267
- setBlocked(false);
268
- setBlockedNavigationMessage(undefined);
269
- if (entityId) {
270
- const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
271
- navigate(fullScreenUrl, { state: null });
272
- } else {
273
- const fullScreenUrl = urlController.buildUrlCollectionPath(path);
274
- navigate(fullScreenUrl + "#new", { state: null });
275
- }
276
- }}>
277
- <Maximize2Icon/>
278
- </IconButton>}
279
- </div>}
314
+ onClick={() => {
315
+ // The form's own handoff, rather than a second
316
+ // copy of the rules for it here: only an edit in
317
+ // progress is worth carrying (a clean record
318
+ // stashed anyway arrived announcing unsaved
319
+ // changes to someone who had only looked at it),
320
+ // and only the fields that were edited (carrying
321
+ // the whole record marked every field touched).
322
+ carryEdit?.();
323
+ setBlocked(false);
324
+ setBlockedNavigationMessage(undefined);
325
+ if (entityId) {
326
+ const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
327
+ navigate(fullScreenUrl, { state: null });
328
+ } else {
329
+ const fullScreenUrl = urlController.buildUrlCollectionPath(path);
330
+ navigate(fullScreenUrl + "#new", { state: null });
331
+ }
332
+ }}>
333
+ <Maximize2Icon/>
334
+ </IconButton>
335
+ )}
280
336
  onTabChange={({
281
337
  entityId: tabEntityId,
282
338
  selectedTab,
@@ -128,7 +128,14 @@ export interface UserSelectorProps {
128
128
  value?: string | null;
129
129
  onValueChange?: (userId: string | null) => void;
130
130
  placeholder?: React.ReactNode;
131
- size?: "small" | "medium";
131
+ /**
132
+ * `large` is the form's size and is on the shared 28/32/40/48 control
133
+ * scale, so a user picker lines up with the text field beside it.
134
+ *
135
+ * `small` and `medium` predate that scale (42 and 56) and are kept as they
136
+ * are because the table cells and the filter row are built around them.
137
+ */
138
+ size?: "small" | "medium" | "large";
132
139
  disabled?: boolean;
133
140
  invisible?: boolean;
134
141
  clearable?: boolean;
@@ -317,9 +324,13 @@ export const UserSelector = React.forwardRef<
317
324
  className={cls(
318
325
  {
319
326
  "min-h-[42px] py-1 px-2": size === "small",
320
- "min-h-[56px] py-2 px-4": size === "medium"
327
+ "min-h-[56px] py-2 px-4": size === "medium",
328
+ "min-h-[48px] py-1 px-4": size === "large"
321
329
  },
322
- "w-full select-none rounded-md text-sm relative flex items-center",
330
+ // `rounded-lg` like every other field box —
331
+ // `rounded-md` made this the one control in a
332
+ // row with a different corner.
333
+ "w-full select-none rounded-lg text-sm relative flex items-center",
323
334
  invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
324
335
  disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
325
336
  className
@@ -345,7 +356,7 @@ export const UserSelector = React.forwardRef<
345
356
  </IconButton>
346
357
  )}
347
358
  <ChevronDownIcon
348
- size={size === "medium" ? iconSize.medium : iconSize.small}
359
+ size={size === "small" ? iconSize.small : iconSize.medium}
349
360
  className={cls("transition", isPopoverOpen ? "rotate-180" : "")}
350
361
  />
351
362
  </div>
@@ -4,17 +4,48 @@ import { ChevronLeftIcon, ErrorBoundary, MenuIcon } from "@rebasepro/ui";
4
4
  import { deepEqual as equal } from "fast-equals"
5
5
 
6
6
  import { useLargeLayout, useAdminModeController, useTranslation } from "@rebasepro/app";
7
+ import { useUrlController } from "../../hooks/navigation/contexts/UrlContext";
7
8
  import { AppContext } from "./useApp";
8
9
 
9
10
  export const DRAWER_WIDTH = 280;
10
11
 
12
+ /**
13
+ * Namespaced by base path: two admins served from one origin are two different
14
+ * navigations, and a single key would have them overwrite each other's drawer.
15
+ */
16
+ export function drawerOpenStorageKey(basePath: string | undefined) {
17
+ return `rebase-drawer-open:${basePath || "/"}`;
18
+ }
19
+
20
+ /** `null` when the user has never toggled the drawer, or storage is unavailable. */
21
+ function readStoredDrawerOpen(key: string): boolean | null {
22
+ if (typeof window === "undefined") return null;
23
+ try {
24
+ const stored = window.localStorage.getItem(key);
25
+ return stored === null ? null : stored === "true";
26
+ } catch (e) {
27
+ // Storage can be blocked: private mode, sandboxed iframe, cookie policy.
28
+ return null;
29
+ }
30
+ }
31
+
32
+ function writeStoredDrawerOpen(key: string, open: boolean) {
33
+ if (typeof window === "undefined") return;
34
+ try {
35
+ window.localStorage.setItem(key, String(open));
36
+ } catch (e) {
37
+ // Same as above: a drawer that forgets is better than a crash.
38
+ }
39
+ }
40
+
11
41
  /**
12
42
  * @group Core
13
43
  */
14
44
  export interface ScaffoldProps {
15
45
 
16
46
  /**
17
- * Open the drawer on hover
47
+ * Expand the collapsed drawer while the pointer is over it. On by default —
48
+ * pass `false` to keep the rail a rail until the user clicks the toggle.
18
49
  */
19
50
  autoOpenDrawer?: boolean;
20
51
 
@@ -22,8 +53,8 @@ export interface ScaffoldProps {
22
53
  * Start with the drawer expanded rather than collapsed to icons.
23
54
  *
24
55
  * Distinct from {@link autoOpenDrawer}, which is a hover behaviour: this one
25
- * only seeds the initial state, so the user's own toggle still wins for the
26
- * rest of the session.
56
+ * only seeds the very first visit. Once the user toggles the drawer, that
57
+ * choice is stored in `localStorage` and wins over this prop on every load.
27
58
  *
28
59
  * Ignored on small layouts, where an expanded drawer covers the content it is
29
60
  * meant to navigate.
@@ -62,7 +93,7 @@ export const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(
62
93
 
63
94
  const {
64
95
  children,
65
- autoOpenDrawer,
96
+ autoOpenDrawer = true,
66
97
  defaultDrawerOpen = false,
67
98
  logo,
68
99
  className,
@@ -83,25 +114,96 @@ export const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(
83
114
  const includeDrawer = drawerChildren.length > 0;
84
115
  const largeLayout = useLargeLayout();
85
116
 
117
+ const storageKey = drawerOpenStorageKey(useUrlController().basePath);
118
+
86
119
  // Seeded once, deliberately: a `useEffect` syncing this to the prop would
87
120
  // re-expand the drawer under a user who had just collapsed it.
88
- const [drawerOpen, setDrawerOpen] = React.useState(defaultDrawerOpen && largeLayout);
121
+ const [drawerOpen, setDrawerOpenState] = React.useState(defaultDrawerOpen && largeLayout);
89
122
  const [onHover, setOnHover] = React.useState(false);
90
123
 
91
- const setOnHoverTrue = useCallback(() => setOnHover(true), []);
124
+ // The stored choice is a client-only fact, so it is applied after the first
125
+ // render rather than seeded into it: reading storage while rendering would
126
+ // make the client disagree with server-rendered HTML. A layout effect runs
127
+ // before paint, so the drawer still arrives in its remembered state.
128
+ // `defaultDrawerOpen` seeds the very first visit and is ignored after that.
129
+ React.useLayoutEffect(() => {
130
+ const stored = readStoredDrawerOpen(storageKey);
131
+ if (stored === null) return;
132
+ setDrawerOpenState(stored && largeLayout);
133
+ // Deliberately not re-run on `largeLayout`: crossing the breakpoint is
134
+ // the effect below, and re-running here would undo a user's toggle.
135
+ // eslint-disable-next-line react-hooks/exhaustive-deps
136
+ }, [storageKey]);
137
+
138
+ // One piece of state drives two different things: the expanded rail on
139
+ // large layouts, and the modal sheet on small ones. Carrying an expanded
140
+ // rail across the breakpoint would drop that sheet, overlay and all, over
141
+ // the content — so the crossing resets it, and widening again restores
142
+ // whatever the user last chose.
143
+ const wasLargeLayout = React.useRef(largeLayout);
144
+ React.useEffect(() => {
145
+ if (wasLargeLayout.current === largeLayout) return;
146
+ wasLargeLayout.current = largeLayout;
147
+ setDrawerOpenState(largeLayout ? (readStoredDrawerOpen(storageKey) ?? defaultDrawerOpen) : false);
148
+ }, [largeLayout, defaultDrawerOpen, storageKey]);
149
+
150
+ const setDrawerOpen = useCallback((open: boolean) => {
151
+ setDrawerOpenState(open);
152
+ // Small layouts render the drawer as a modal sheet. Remembering that
153
+ // one would greet the next load with an overlay over the content.
154
+ if (!largeLayout) return;
155
+ writeStoredDrawerOpen(storageKey, open);
156
+ }, [largeLayout, storageKey]);
157
+
158
+ // The pointer has left, but a popover the drawer opened is still up, so the
159
+ // collapse is owed rather than cancelled. See `setOnHoverFalse`.
160
+ const collapseWhenPopoverCloses = React.useRef(false);
161
+
162
+ const setOnHoverTrue = useCallback(() => {
163
+ // Hover expansion is the default; `autoOpenDrawer={false}` opts out for
164
+ // admins that want the rail to stay a rail until the toggle is clicked.
165
+ if (!autoOpenDrawer) return;
166
+ collapseWhenPopoverCloses.current = false;
167
+ setOnHover(true);
168
+ }, [autoOpenDrawer]);
92
169
  const setOnHoverFalse = useCallback(() => {
93
- // Don't collapse the drawer while a popover/dropdown is open
94
- if (document.querySelector("[data-radix-popper-content-wrapper]")) return;
170
+ // Don't collapse the drawer out from under an open popover/dropdown
171
+ // its content is portalled outside the drawer, so reaching for it reads
172
+ // as a mouseleave. The collapse is owed until that popover closes.
173
+ if (document.querySelector("[data-radix-popper-content-wrapper]")) {
174
+ collapseWhenPopoverCloses.current = true;
175
+ return;
176
+ }
177
+ collapseWhenPopoverCloses.current = false;
95
178
  setOnHover(false);
96
179
  }, []);
97
180
 
181
+ // Nothing fires a second mouseleave when the popover finally closes, so the
182
+ // owed collapse has to be noticed rather than waited for. Only mounted
183
+ // while the drawer is actually floating open.
184
+ React.useEffect(() => {
185
+ if (!onHover) return;
186
+ const collapseIfOwed = () => {
187
+ if (!collapseWhenPopoverCloses.current) return;
188
+ if (document.querySelector("[data-radix-popper-content-wrapper]")) return;
189
+ collapseWhenPopoverCloses.current = false;
190
+ setOnHover(false);
191
+ };
192
+ const observer = new MutationObserver(collapseIfOwed);
193
+ observer.observe(document.body, {
194
+ childList: true,
195
+ subtree: true
196
+ });
197
+ return () => observer.disconnect();
198
+ }, [onHover]);
199
+
98
200
  const handleDrawerOpen = useCallback(() => {
99
201
  setDrawerOpen(true);
100
- }, []);
202
+ }, [setDrawerOpen]);
101
203
 
102
204
  const handleDrawerClose = useCallback(() => {
103
205
  setDrawerOpen(false);
104
- }, []);
206
+ }, [setDrawerOpen]);
105
207
 
106
208
  const computedDrawerOpen: boolean = drawerOpen;
107
209
  const computedDrawerHovered = Boolean(largeLayout && onHover);
@@ -3,22 +3,17 @@ import React, { useEffect, useState, useCallback } from "react";
3
3
  ;
4
4
  import { useApiBase, useApiConfig } from "@rebasepro/app";
5
5
  import { useAuthController } from "@rebasepro/app";
6
+ import { formatRelativeTime } from "@rebasepro/utils";
6
7
  import { HistoryEntryData } from "../../hooks";
7
8
  import type { AdminCollection } from "@rebasepro/admin-types";
8
9
 
9
- function getRelativeTimeString(date: Date): string {
10
- const now = new Date();
11
- const diffMs = now.getTime() - date.getTime();
12
- const diffSeconds = Math.floor(diffMs / 1000);
13
- const diffMinutes = Math.floor(diffSeconds / 60);
14
- const diffHours = Math.floor(diffMinutes / 60);
15
- const diffDays = Math.floor(diffHours / 24);
10
+ const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
16
11
 
17
- if (diffSeconds < 60) return "just now";
18
- if (diffMinutes < 60) return `${diffMinutes}m ago`;
19
- if (diffHours < 24) return `${diffHours}h ago`;
20
- if (diffDays < 30) return `${diffDays}d ago`;
21
- return date.toLocaleDateString();
12
+ function getRelativeTimeString(date: Date): string {
13
+ // An edit is in the past, but the timestamp comes from the server and the
14
+ // phrase is rendered against the browser's clock — a few seconds of skew
15
+ // used to be enough to make a fresh edit read as the wrong thing entirely.
16
+ return formatRelativeTime(date, { maxMs: THIRTY_DAYS_MS }) ?? date.toLocaleDateString();
22
17
  }
23
18
 
24
19
  /**
@@ -1,6 +1,9 @@
1
1
  export type { EntityViewBindingProps } from "./EntityViewBinding";
2
2
  export { EntityViewBinding } from "./EntityViewBinding";
3
3
 
4
+ export type { EntityDisplayHeaderProps } from "./EntityDisplayHeader";
5
+ export { EntityDisplayHeader, HEADER_DISPLAY_ROLES } from "./EntityDisplayHeader";
6
+
4
7
  export * from "./DetailViewBinding";
5
8
 
6
9
  export type { SelectionProps } from "./ReferenceTable/SelectionTableBinding";
@@ -100,7 +100,15 @@ export function processValueMapping(authController: AuthController, value: any,
100
100
  if (from === "array" && to === "array" && Array.isArray(value) && usedProperty.of && !Array.isArray(usedProperty.of) && !isPropertyBuilder(usedProperty.of)) {
101
101
  return value.map(v => processValueMapping(authController, v, navigation, usedProperty.of as Property));
102
102
  } else if (from === "string" && to === "number" && typeof value === "string") {
103
- return Number(value);
103
+ // `Number("")` is 0, so a blank cell used to import as a real zero — a
104
+ // price of nothing rather than a price nobody filled in — and `Number`
105
+ // of anything unreadable imported as NaN. Both are absent values, and
106
+ // saying so lets the importer's own validation see them. The `vector`
107
+ // branch above already draws the same distinction.
108
+ const trimmed = value.trim();
109
+ if (trimmed === "") return null;
110
+ const num = Number(trimmed);
111
+ return Number.isNaN(num) ? null : num;
104
112
  } else if (from === "string" && to === "array" && typeof value === "string" && usedProperty.of && !Array.isArray(usedProperty.of) && !isPropertyBuilder(usedProperty.of)) {
105
113
  return value.split(",").map((v: string) => processValueMapping(authController, v, navigation, usedProperty.of as Property));
106
114
  } else if (from === "string" && to === "boolean") {