@rebasepro/admin 0.13.0 → 0.13.1-canary.g06dbe5b

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 (188) hide show
  1. package/dist/{CollectionEditorDialog-CjXkWZ64.js → CollectionEditorDialog-C3DbFNqp.js} +3 -3
  2. package/dist/{CollectionEditorDialog-CjXkWZ64.js.map → CollectionEditorDialog-C3DbFNqp.js.map} +1 -1
  3. package/dist/{PropertyEditView-W8I3YV89.js → PropertyEditView-DFH8rXRN.js} +5 -5
  4. package/dist/PropertyEditView-DFH8rXRN.js.map +1 -0
  5. package/dist/{RouterCollectionsStudioView-BsLTNoqX.js → RouterCollectionsStudioView-DiUDOu4b.js} +9 -13
  6. package/dist/RouterCollectionsStudioView-DiUDOu4b.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/ClearFilterSortButton.d.ts +7 -1
  11. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +16 -0
  12. package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +3 -1
  13. package/dist/components/CollectionViewBinding/SearchExplanation.d.ts +48 -0
  14. package/dist/components/CollectionViewBinding/SearchHighlight.d.ts +101 -0
  15. package/dist/components/CollectionViewBinding/SlotValue.d.ts +63 -0
  16. package/dist/components/CollectionViewBinding/SortButton.d.ts +7 -1
  17. package/dist/components/CollectionViewBinding/SplitListCloseButton.d.ts +17 -4
  18. package/dist/components/CollectionViewBinding/SplitListShowButton.d.ts +12 -0
  19. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +55 -5
  20. package/dist/components/DetailViewBinding.d.ts +15 -0
  21. package/dist/components/DrawerNavigationGroup.d.ts +9 -6
  22. package/dist/components/DrawerNavigationItem.d.ts +16 -6
  23. package/dist/components/EditViewBinding.d.ts +30 -1
  24. package/dist/components/EntityDisplayHeader.d.ts +53 -0
  25. package/dist/components/EntityIdentityBar.d.ts +43 -1
  26. package/dist/components/EntityViewBinding.d.ts +60 -6
  27. package/dist/components/RebaseLayout.d.ts +1 -1
  28. package/dist/components/RebaseShell.d.ts +1 -1
  29. package/dist/components/RelationSelector.d.ts +8 -1
  30. package/dist/components/UserSelector.d.ts +8 -1
  31. package/dist/components/app/Scaffold.d.ts +9 -3
  32. package/dist/components/index.d.ts +2 -0
  33. package/dist/data_export/export/export.d.ts +7 -0
  34. package/dist/data_export/export/fetch_export_data.d.ts +48 -0
  35. package/dist/data_export/export/index.d.ts +1 -0
  36. package/dist/data_import/utils/csv.d.ts +30 -0
  37. package/dist/data_import/utils/index.d.ts +2 -0
  38. package/dist/data_import/utils/save_entities.d.ts +38 -0
  39. package/dist/data_import/utils/transforms.d.ts +9 -0
  40. package/dist/{export-J79rMoNj.js → export-Bd5i6Uvm.js} +175 -39
  41. package/dist/export-Bd5i6Uvm.js.map +1 -0
  42. package/dist/form/components/FieldBlock.d.ts +58 -4
  43. package/dist/form/components/FormRail.d.ts +13 -0
  44. package/dist/form/components/FormSections.d.ts +15 -1
  45. package/dist/form/components/useRailVisible.d.ts +5 -4
  46. package/dist/form/form_utils.d.ts +38 -1
  47. package/dist/{history-D7L_JlLO.js → history-D9R6LUrH.js} +4 -4
  48. package/dist/{history-D7L_JlLO.js.map → history-D9R6LUrH.js.map} +1 -1
  49. package/dist/hooks/useEntityDisplay.d.ts +102 -0
  50. package/dist/hooks/useEntityDisplayTitle.d.ts +18 -9
  51. package/dist/{import-BvYl--U4.js → import-pt_j-0G3.js} +6 -5
  52. package/dist/import-pt_j-0G3.js.map +1 -0
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.js +158 -60
  55. package/dist/index.js.map +1 -1
  56. package/dist/preview/compact_text.d.ts +23 -0
  57. package/dist/preview/components/BooleanPreview.d.ts +3 -1
  58. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  59. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  60. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  61. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  62. package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
  63. package/dist/routes/RebaseRoute.d.ts +1 -1
  64. package/dist/types/components/PropertyPreviewProps.d.ts +19 -0
  65. package/dist/util/number_format.d.ts +14 -0
  66. package/dist/util/previews.d.ts +9 -2
  67. package/dist/util/view_constants.d.ts +24 -0
  68. package/dist/util/view_mode.d.ts +18 -0
  69. package/dist/{util-GiwPgxnL.js → util-nX_-JRuF.js} +3984 -1774
  70. package/dist/util-nX_-JRuF.js.map +1 -0
  71. package/package.json +10 -9
  72. package/src/collection_editor/serializable_types.ts +1 -0
  73. package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +9 -11
  74. package/src/collection_editor/ui/collection_editor/properties/MapPropertyField.tsx +1 -1
  75. package/src/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +5 -2
  76. package/src/collection_editor/useLocalCollectionsConfigController.tsx +10 -3
  77. package/src/components/AdditionalFieldValue.tsx +68 -0
  78. package/src/components/ClearFilterSortButton.tsx +16 -7
  79. package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +7 -8
  80. package/src/components/CollectionTableBinding/PropertyTableCell.tsx +2 -2
  81. package/src/components/CollectionTableBinding/column_utils.tsx +15 -6
  82. package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +2 -2
  83. package/src/components/CollectionTableBinding/table_bindings.tsx +7 -1
  84. package/src/components/CollectionViewBinding/BoardCardBinding.tsx +26 -27
  85. package/src/components/CollectionViewBinding/CollectionBoardViewBinding.tsx +13 -7
  86. package/src/components/CollectionViewBinding/CollectionCardViewBinding.tsx +2 -1
  87. package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +822 -354
  88. package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
  89. package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +51 -12
  90. package/src/components/CollectionViewBinding/CollectionViewStartActions.tsx +9 -0
  91. package/src/components/CollectionViewBinding/EntityCardBinding.tsx +51 -39
  92. package/src/components/CollectionViewBinding/SearchExplanation.tsx +106 -0
  93. package/src/components/CollectionViewBinding/SearchHighlight.tsx +311 -0
  94. package/src/components/CollectionViewBinding/SlotValue.tsx +156 -0
  95. package/src/components/CollectionViewBinding/SortButton.tsx +16 -4
  96. package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +23 -7
  97. package/src/components/CollectionViewBinding/SplitListShowButton.tsx +28 -0
  98. package/src/components/CollectionViewBinding/SplitListView.tsx +47 -7
  99. package/src/components/CollectionViewBinding/ViewModeToggle.tsx +10 -5
  100. package/src/components/CollectionViewBinding/useBoardDataController.tsx +23 -6
  101. package/src/components/CollectionViewBinding/usePreviewSlots.ts +183 -64
  102. package/src/components/CollectionViewBinding/utils.ts +7 -4
  103. package/src/components/DefaultDrawer.tsx +19 -23
  104. package/src/components/DetailViewBinding.tsx +109 -62
  105. package/src/components/DrawerNavigationGroup.tsx +16 -39
  106. package/src/components/DrawerNavigationItem.tsx +44 -16
  107. package/src/components/EditViewBinding.tsx +233 -50
  108. package/src/components/EntityDisplayHeader.tsx +170 -0
  109. package/src/components/EntityIdentityBar.tsx +163 -23
  110. package/src/components/EntityInspector.tsx +24 -6
  111. package/src/components/EntityPreviewBinding.tsx +58 -18
  112. package/src/components/EntityViewBinding.tsx +344 -41
  113. package/src/components/InlineEntityPreview.tsx +10 -10
  114. package/src/components/RebaseLayout.tsx +2 -2
  115. package/src/components/RebaseShell.tsx +2 -2
  116. package/src/components/ReferenceTable/SelectionTableBinding.tsx +4 -2
  117. package/src/components/RelationSelector.tsx +35 -10
  118. package/src/components/SideDialogs.tsx +15 -3
  119. package/src/components/SidePanelBinding.tsx +122 -66
  120. package/src/components/UserSelector.tsx +67 -13
  121. package/src/components/app/Scaffold.tsx +112 -10
  122. package/src/components/history/LastEditedByIndicator.tsx +7 -12
  123. package/src/components/index.ts +3 -0
  124. package/src/data_export/export/ExportCollectionAction.tsx +101 -48
  125. package/src/data_export/export/export.ts +63 -16
  126. package/src/data_export/export/fetch_export_data.ts +90 -0
  127. package/src/data_export/export/index.ts +1 -0
  128. package/src/data_import/components/ImportSaveInProgress.tsx +35 -36
  129. package/src/data_import/import/ImportCollectionAction.tsx +13 -2
  130. package/src/data_import/utils/csv.ts +153 -0
  131. package/src/data_import/utils/data.ts +16 -2
  132. package/src/data_import/utils/file_to_json.ts +51 -5
  133. package/src/data_import/utils/index.ts +2 -0
  134. package/src/data_import/utils/save_entities.ts +138 -0
  135. package/src/data_import/utils/transforms.ts +23 -0
  136. package/src/form/EntityForm.tsx +74 -53
  137. package/src/form/EntityFormBinding.tsx +24 -11
  138. package/src/form/PropertyFieldBinding.tsx +2 -2
  139. package/src/form/components/FieldBlock.tsx +80 -10
  140. package/src/form/components/FormRail.tsx +19 -2
  141. package/src/form/components/FormSections.tsx +32 -5
  142. package/src/form/components/StorageUploadProgress.tsx +9 -3
  143. package/src/form/components/useRailVisible.tsx +5 -4
  144. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -2
  145. package/src/form/field_bindings/BinaryFieldBinding.tsx +10 -5
  146. package/src/form/field_bindings/BlockFieldBinding.tsx +3 -3
  147. package/src/form/field_bindings/GeopointFieldBinding.tsx +23 -16
  148. package/src/form/field_bindings/MapFieldBinding.tsx +2 -2
  149. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +13 -7
  150. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +7 -1
  151. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +21 -2
  152. package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
  153. package/src/form/field_bindings/RelationFieldBinding.tsx +5 -2
  154. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
  155. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -2
  156. package/src/form/field_bindings/UserSelectFieldBinding.tsx +4 -1
  157. package/src/form/field_bindings/VectorFieldBinding.tsx +6 -4
  158. package/src/form/form_utils.ts +78 -0
  159. package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +29 -5
  160. package/src/hooks/useEntityDisplay.tsx +262 -0
  161. package/src/hooks/useEntityDisplayTitle.tsx +27 -38
  162. package/src/index.ts +9 -1
  163. package/src/preview/PropertyPreview.tsx +25 -5
  164. package/src/preview/compact_text.ts +68 -0
  165. package/src/preview/components/BooleanPreview.tsx +5 -2
  166. package/src/preview/components/ReferencePreview.tsx +5 -8
  167. package/src/preview/components/RelationPreview.tsx +8 -7
  168. package/src/preview/components/StorageThumbnail.tsx +5 -2
  169. package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +6 -3
  170. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +26 -1
  171. package/src/preview/property_previews/ArrayOneOfPreview.tsx +10 -1
  172. package/src/preview/property_previews/ArrayPropertyPreview.tsx +10 -1
  173. package/src/preview/property_previews/MapPropertyPreview.tsx +52 -1
  174. package/src/preview/property_previews/NumberPropertyPreview.tsx +9 -1
  175. package/src/preview/property_previews/StringPropertyPreview.tsx +8 -5
  176. package/src/routes/RebaseRoute.tsx +62 -4
  177. package/src/types/components/PropertyPreviewProps.tsx +21 -0
  178. package/src/util/navigation_utils.ts +4 -2
  179. package/src/util/number_format.ts +46 -0
  180. package/src/util/previews.ts +8 -55
  181. package/src/util/property_utils.tsx +6 -1
  182. package/src/util/view_constants.ts +27 -0
  183. package/src/util/view_mode.ts +36 -0
  184. package/dist/PropertyEditView-W8I3YV89.js.map +0 -1
  185. package/dist/RouterCollectionsStudioView-BsLTNoqX.js.map +0 -1
  186. package/dist/export-J79rMoNj.js.map +0 -1
  187. package/dist/import-BvYl--U4.js.map +0 -1
  188. package/dist/util-GiwPgxnL.js.map +0 -1
@@ -0,0 +1,311 @@
1
+ import React, { useMemo } from "react";
2
+ import type { SearchMatch } from "@rebasepro/types";
3
+
4
+ /**
5
+ * Showing a searcher *why* a row is in their results.
6
+ *
7
+ * A ranked list answers "which rows" and never "why this one". When the term is
8
+ * in the title that is self-evident; when it is in a field the list does not
9
+ * show — a certification, a nested answer, a note — the row looks arbitrary and
10
+ * the only way to find out is to open it. That is the whole reason this exists.
11
+ *
12
+ * Two jobs, and they are deliberately separate:
13
+ *
14
+ * 1. {@link Highlighted} marks the term inside a value the list already shows.
15
+ * 2. {@link offSlotMatch} finds a match in a field that has no slot, so the
16
+ * caller can put it where the subtitle would have gone.
17
+ */
18
+
19
+ /** `<mark>` is Postgres's delimiter, and what `ts_headline` emits. */
20
+ const MARK = /(<mark>.*?<\/mark>)/g;
21
+
22
+ /**
23
+ * Render a `ts_headline` snippet: text with `<mark>` around each hit.
24
+ *
25
+ * Split-and-render rather than `dangerouslySetInnerHTML`. The text around the
26
+ * marks is whatever a user typed into their own record, and the only markup it
27
+ * is allowed to carry is the highlight Postgres put there. Anything else stays
28
+ * inert text.
29
+ */
30
+ /**
31
+ * Context kept before and after a hit, in characters.
32
+ *
33
+ * Asymmetric on purpose. The snippet renders on one truncated line, so anything
34
+ * before the hit competes with the hit itself for the width available — with a
35
+ * generous lead-in the mark is pushed off the right edge and the reader sees a
36
+ * fragment with nothing highlighted in it, which is worse than no snippet at
37
+ * all. Lead with just enough to not start abruptly, then run on.
38
+ */
39
+ const SNIPPET_LEAD = 16;
40
+ const SNIPPET_TRAIL = 90;
41
+
42
+ /**
43
+ * Pull the first mark near the front of the snippet.
44
+ *
45
+ * The snippet renders on one truncated line whose width is not knowable here —
46
+ * a list column is wide, the same list beside an open record is not. Whatever
47
+ * precedes the mark competes with it for that width, and when the mark loses
48
+ * the reader gets a fragment of their record with nothing highlighted in it,
49
+ * which reads as the feature being broken rather than as a narrow column.
50
+ *
51
+ * `ts_headline` centres its fragment on the match, so roughly half the window
52
+ * is lead-in; that is the right shape for a paragraph and the wrong one for a
53
+ * line. Trimming here rather than asking Postgres for a smaller window keeps
54
+ * the trailing context, which is what actually explains the hit — and applies
55
+ * the same shape to the snippets built in the browser, so a row looks the same
56
+ * whichever path produced it.
57
+ */
58
+ export function trimSnippetLead(text: string, lead: number = SNIPPET_LEAD): string {
59
+ const at = text.indexOf("<mark>");
60
+ if (at < 0 || at <= lead) return text;
61
+ // Trim the lead-in only. Running the word-boundary strip over the whole
62
+ // remainder eats the mark itself when the lead is short enough that the
63
+ // slice opens on `<mark>`, which has no space in it to stop at.
64
+ const head = text.slice(at - lead, at).replace(/^\S*\s/, "");
65
+ return "…" + head + text.slice(at);
66
+ }
67
+
68
+ export function Snippet({ text, className }: { text: string; className?: string }) {
69
+ const parts = useMemo(() => trimSnippetLead(text).split(MARK), [text]);
70
+ return (
71
+ <span className={className}>
72
+ {parts.map((part, i) =>
73
+ part.startsWith("<mark>")
74
+ ? (
75
+ <mark
76
+ key={i}
77
+ className="bg-amber-200/70 dark:bg-amber-400/30 text-inherit rounded-[3px] px-[1px]"
78
+ >
79
+ {part.slice(6, -7)}
80
+ </mark>
81
+ )
82
+ : <React.Fragment key={i}>{part}</React.Fragment>
83
+ )}
84
+ </span>
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Mark every occurrence of the searched terms inside a plain value.
90
+ *
91
+ * Used for values the list already renders, where the server's snippet would be
92
+ * the wrong thing to show: the snippet is truncated to a fragment and folded to
93
+ * the indexed form, while the cell should keep the record's real text. So the
94
+ * terms are re-matched here, on the display value.
95
+ *
96
+ * Deliberately dumber than the server's matching, and it has to be: this cannot
97
+ * stem or unaccent without reimplementing the text search configuration in the
98
+ * browser and getting it subtly different. It marks what it can find as a
99
+ * prefix, case- and accent-insensitively, and marks nothing when it cannot —
100
+ * a highlight that is merely absent reads as "no hit in this field", which is
101
+ * the honest answer for a stem the browser cannot reproduce.
102
+ */
103
+ export function Highlighted({ text, terms, className }: { text: string; terms: string[]; className?: string }) {
104
+ const segments = useMemo(() => splitOnTerms(text, terms), [text, terms]);
105
+ if (segments.length <= 1) return <span className={className}>{text}</span>;
106
+ return (
107
+ <span className={className}>
108
+ {segments.map((seg, i) =>
109
+ seg.hit
110
+ ? (
111
+ <mark
112
+ key={i}
113
+ className="bg-amber-200/70 dark:bg-amber-400/30 text-inherit rounded-[3px] px-[1px]"
114
+ >
115
+ {seg.text}
116
+ </mark>
117
+ )
118
+ : <React.Fragment key={i}>{seg.text}</React.Fragment>
119
+ )}
120
+ </span>
121
+ );
122
+ }
123
+
124
+ /** Strip diacritics so `gestion` marks `gestión`, mirroring the index's unaccent. */
125
+ const fold = (value: string): string =>
126
+ value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
127
+
128
+ interface Segment { text: string; hit: boolean }
129
+
130
+ /**
131
+ * Split `text` into hit / non-hit runs.
132
+ *
133
+ * Matches on the *folded* form but slices the original, so the marked text
134
+ * keeps its accents and case — `Gestión`, not `gestion`. Folding is
135
+ * length-preserving for the diacritics this handles, which is what makes the
136
+ * indices transferable; a fold that changed length would misalign the slices.
137
+ */
138
+ export function splitOnTerms(text: string, terms: string[]): Segment[] {
139
+ const haystack = fold(text);
140
+ const needles = terms.map(fold).filter(t => t.length >= 2);
141
+ if (needles.length === 0) return [{ text, hit: false }];
142
+
143
+ // Word-start matches only. A search for "iso" marking the "iso" inside
144
+ // "revisor" is noise, and reads as a bug rather than a feature.
145
+ const bounds: [number, number][] = [];
146
+ for (const needle of needles) {
147
+ let from = 0;
148
+ for (;;) {
149
+ const at = haystack.indexOf(needle, from);
150
+ if (at === -1) break;
151
+ const before = at === 0 ? " " : haystack[at - 1];
152
+ if (!/[\p{L}\p{N}]/u.test(before)) bounds.push([at, at + needle.length]);
153
+ from = at + needle.length;
154
+ }
155
+ }
156
+ if (bounds.length === 0) return [{ text, hit: false }];
157
+
158
+ // Merge overlaps so two terms hitting the same run mark it once.
159
+ bounds.sort((a, b) => a[0] - b[0]);
160
+ const merged: [number, number][] = [];
161
+ for (const [start, end] of bounds) {
162
+ const last = merged[merged.length - 1];
163
+ if (last && start <= last[1]) last[1] = Math.max(last[1], end);
164
+ else merged.push([start, end]);
165
+ }
166
+
167
+ const segments: Segment[] = [];
168
+ let cursor = 0;
169
+ for (const [start, end] of merged) {
170
+ if (start > cursor) segments.push({ text: text.slice(cursor, start), hit: false });
171
+ segments.push({ text: text.slice(start, end), hit: true });
172
+ cursor = end;
173
+ }
174
+ if (cursor < text.length) segments.push({ text: text.slice(cursor), hit: false });
175
+ return segments;
176
+ }
177
+
178
+ /**
179
+ * The terms a searcher typed, as things to look for in a rendered value.
180
+ *
181
+ * Quoted phrases stay whole; `-excluded` terms are dropped, since marking a
182
+ * word the user asked *not* to see would be actively wrong. `websearch_to_tsquery`
183
+ * reads the same syntax on the server.
184
+ */
185
+ export function searchTerms(searchString: string | undefined): string[] {
186
+ if (!searchString) return [];
187
+ const terms: string[] = [];
188
+ for (const [, phrase, bare] of searchString.matchAll(/"([^"]+)"|(\S+)/g)) {
189
+ const term = phrase ?? bare;
190
+ if (!term || term.startsWith("-")) continue;
191
+ if (/^(or|and)$/i.test(term)) continue;
192
+ terms.push(term);
193
+ }
194
+ return terms;
195
+ }
196
+
197
+ /**
198
+ * The best match to show when the term is nowhere the list already displays.
199
+ *
200
+ * `shownKeys` are the property paths the row is already rendering, so a match
201
+ * there needs no explaining — {@link Highlighted} marks it in place and the
202
+ * subtitle keeps its own job. Anything else is invisible, and one of those is
203
+ * what the subtitle slot gets replaced with.
204
+ *
205
+ * The first such match wins, and the server returns them in the order the
206
+ * collection declared its `search` fields — so the field an author put first is
207
+ * the one a reader sees, rather than whichever the database aggregated first.
208
+ */
209
+ export function offSlotMatch(
210
+ matches: SearchMatch[] | undefined,
211
+ shownKeys: (string | undefined)[]
212
+ ): SearchMatch | undefined {
213
+ if (!matches || matches.length === 0) return undefined;
214
+ const shown = new Set(shownKeys.filter((k): k is string => Boolean(k)));
215
+ return matches.find(m => !shown.has(m.field));
216
+ }
217
+
218
+ // ── Finding the match locally ───────────────────────────────────────────────
219
+
220
+ /**
221
+ * Where a search term appears in a row, computed from the row itself.
222
+ *
223
+ * The server can say this too — `_matches`, from `ts_headline` — and its answer
224
+ * is better, because it knows the stemming the index used. This exists because
225
+ * the admin cannot rely on getting it: rows reach the panel over three
226
+ * different transports (REST, the realtime socket, the offline cache) and only
227
+ * one of them carries query metadata. A feature that explains a result on some
228
+ * loads and not others is worse than one that always gives a slightly simpler
229
+ * answer.
230
+ *
231
+ * So: use the server's when it is there, fall back to this. Both produce the
232
+ * same `{ field, snippet }` shape, and this one marks with the same `<mark>`.
233
+ */
234
+ export function localRowMatch(
235
+ values: Record<string, unknown> | undefined,
236
+ properties: Record<string, unknown> | undefined,
237
+ terms: string[],
238
+ shownKeys: (string | undefined)[]
239
+ ): SearchMatch | undefined {
240
+ if (!values || !properties || terms.length === 0) return undefined;
241
+ const shown = new Set(shownKeys.filter((k): k is string => Boolean(k)));
242
+
243
+ // Declared order, so the field an author put first wins — the same rule the
244
+ // server's `_matches` follows.
245
+ for (const [key, property] of Object.entries(properties)) {
246
+ if (shown.has(key)) continue;
247
+ const found = findInValue(values[key], terms, key, property as { type?: string });
248
+ if (found) return found;
249
+ }
250
+ return undefined;
251
+ }
252
+
253
+ function findInValue(
254
+ value: unknown,
255
+ terms: string[],
256
+ path: string,
257
+ property: { type?: string } | undefined
258
+ ): SearchMatch | undefined {
259
+ // An enum renders as a chip from a fixed vocabulary; marking inside one
260
+ // reads as noise, and `where` is the right tool for those anyway.
261
+ if (property && "enum" in property && property.enum) return undefined;
262
+
263
+ if (typeof value === "string") {
264
+ const snippet = snippetAround(value, terms);
265
+ return snippet ? { field: path, snippet } : undefined;
266
+ }
267
+ if (Array.isArray(value)) {
268
+ for (const item of value) {
269
+ const found = findInValue(item, terms, path, undefined);
270
+ if (found) return found;
271
+ }
272
+ return undefined;
273
+ }
274
+ if (value && typeof value === "object") {
275
+ // Nested maps: report the path the author would recognise, which is the
276
+ // dotted one the `search` block uses.
277
+ for (const [key, nested] of Object.entries(value as Record<string, unknown>)) {
278
+ const found = findInValue(nested, terms, `${path}.${key}`, undefined);
279
+ if (found) return found;
280
+ }
281
+ }
282
+ return undefined;
283
+ }
284
+
285
+ /**
286
+ * The text around the first hit, with every hit in view marked.
287
+ *
288
+ * Trimmed to a readable window rather than the whole field: a match in a long
289
+ * body should show the sentence it is in, not the first line of the document,
290
+ * and certainly not the document.
291
+ */
292
+ export function snippetAround(text: string, terms: string[]): string | undefined {
293
+ const segments = splitOnTerms(text, terms);
294
+ const firstHit = segments.findIndex(s => s.hit);
295
+ if (firstHit === -1) return undefined;
296
+
297
+ const before = segments.slice(0, firstHit).map(s => s.text).join("");
298
+ const head = before.length > SNIPPET_LEAD
299
+ // Start at a word boundary so the snippet does not open mid-word.
300
+ ? "…" + before.slice(before.length - SNIPPET_LEAD).replace(/^\S*\s/, "")
301
+ : before;
302
+
303
+ let out = head;
304
+ for (let i = firstHit; i < segments.length; i++) {
305
+ const seg = segments[i];
306
+ out += seg.hit ? `<mark>${seg.text}</mark>` : seg.text;
307
+ // Enough context after the hit to read it, then stop.
308
+ if (out.length > head.length + SNIPPET_TRAIL) { out += "…"; break; }
309
+ }
310
+ return out.trim();
311
+ }
@@ -0,0 +1,156 @@
1
+ import React from "react";
2
+ import type { PreviewSize } from "../../types/components/PropertyPreviewProps";
3
+ import { PropertyPreview } from "../../preview";
4
+ import { StorageThumbnail } from "../../preview/components/StorageThumbnail";
5
+ import { UrlComponentPreview } from "../../preview/components/UrlComponentPreview";
6
+ import { Chip } from "@rebasepro/ui";
7
+ import type { PreviewSlot } from "./usePreviewSlots";
8
+
9
+ export interface SlotValueProps {
10
+ slot: PreviewSlot | undefined;
11
+ size: PreviewSize;
12
+ /**
13
+ * Relations and references render as one line of linked text rather than as
14
+ * a card. Defaults to true: a slot is a line in a row or a card, and a
15
+ * relation that renders its own bordered card there — with its own id line
16
+ * and its own side-panel button — is a card inside a card.
17
+ *
18
+ * Pass `false` only for a slot with room for one, which in practice is
19
+ * none of them.
20
+ */
21
+ textOnly?: boolean;
22
+ /** Images only: fill the container rather than fitting inside it. */
23
+ fill?: boolean;
24
+ }
25
+
26
+ /**
27
+ * One display slot, rendered.
28
+ *
29
+ * A slot's value arrives one of two ways and they cannot be rendered the same:
30
+ *
31
+ * - **From a property** — render it with that property's own preview, so an
32
+ * enum status keeps its colour, a date keeps its format and a storage path
33
+ * becomes a thumbnail. This is why a declared path beats a resolver whenever
34
+ * the value is actually on the record.
35
+ * - **From a resolver** — there is no property, because the value was computed
36
+ * or fetched. All that can be said about it is that it is text.
37
+ *
38
+ * The branch lives here, once, rather than at each of the fourteen places the
39
+ * list row, the card and the board card render a slot. That count is the reason:
40
+ * the last time a rule like this was inlined per call site, it drifted into
41
+ * seven versions.
42
+ */
43
+ export function SlotValue({ slot, size, textOnly = true, fill }: SlotValueProps) {
44
+
45
+ if (!slot || slot.value === undefined || slot.value === null) return null;
46
+
47
+ if (!slot.property || !slot.propertyKey) {
48
+ // A computed image is still an image. "There is no property, so all that
49
+ // can be said about it is that it is text" holds for a title and fails
50
+ // here: `display.image` accepts "a storage path or a URL … so a resolver
51
+ // may return either", and both used to be printed as their own string
52
+ // inside the image frame.
53
+ if (slot.role === "image" && typeof slot.value === "string" && slot.value.trim()) {
54
+ return <ComputedImage value={slot.value.trim()} size={size} fill={fill}/>;
55
+ }
56
+
57
+ // Computed. Arrays (a `tags` resolver) join rather than rendering as
58
+ // "[object Object]" via String().
59
+ const text = Array.isArray(slot.value)
60
+ ? slot.value.map(item => String(item)).join(", ")
61
+ : String(slot.value);
62
+ return <>{text}</>;
63
+ }
64
+
65
+ return <PropertyPreview
66
+ propertyKey={slot.propertyKey}
67
+ value={slot.value as never}
68
+ property={slot.property}
69
+ size={size}
70
+ textOnly={textOnly}
71
+ fill={fill}/>;
72
+ }
73
+
74
+ /**
75
+ * The `tags` slot, as chips beside the status.
76
+ *
77
+ * Honours both arms the same way the rest of the file does. A declared **path**
78
+ * goes through {@link SlotValue}, so an array of enum values keeps its own
79
+ * colours — that is the stated advantage of naming a property. A **resolver**
80
+ * returns bare strings with no property to render them as, so they become plain
81
+ * chips; a single string is accepted as one tag, which the role's type documents.
82
+ *
83
+ * Lives here rather than in the list, the card and the board card because that is
84
+ * three copies of the same decision, and this file exists to hold exactly one.
85
+ */
86
+ export function TagChips({ slot, max = 4 }: { slot: PreviewSlot, max?: number }) {
87
+
88
+ if (slot.property && slot.propertyKey) {
89
+ return <SlotValue slot={slot} size="small"/>;
90
+ }
91
+
92
+ const values = (Array.isArray(slot.value) ? slot.value : [slot.value])
93
+ .filter(item => item !== undefined && item !== null && String(item).trim() !== "")
94
+ .map(item => String(item));
95
+
96
+ if (values.length === 0) return null;
97
+
98
+ const shown = values.slice(0, max);
99
+ const hidden = values.length - shown.length;
100
+
101
+ return <>
102
+ {shown.map(value => (
103
+ <Chip key={value}
104
+ size="smallest"
105
+ className="!text-[10px] !leading-tight !py-0 shrink-0 max-w-[100px] truncate">
106
+ {value}
107
+ </Chip>
108
+ ))}
109
+ {hidden > 0 && (
110
+ <span className="text-[10px] text-surface-400 dark:text-surface-500 shrink-0">+{hidden}</span>
111
+ )}
112
+ </>;
113
+ }
114
+
115
+ /**
116
+ * Whether a computed image string can be fetched as-is, or has to be resolved
117
+ * through storage first.
118
+ *
119
+ * Exported because it is the whole decision: rendering either branch needs a
120
+ * provider (a storage source, a DOM), and the thing worth pinning is which
121
+ * branch a given string takes. `//host/x` is protocol-relative and equally
122
+ * fetchable; `data:` and `blob:` are already the bytes.
123
+ */
124
+ export function isFetchableImageUrl(value: string): boolean {
125
+ return /^(https?:)?\/\//i.test(value) || /^(data|blob):/i.test(value);
126
+ }
127
+
128
+ /**
129
+ * A string a resolver returned for the `image` role, rendered as a picture.
130
+ *
131
+ * Two things can arrive here and they need different handling, which is the whole
132
+ * reason a property-path image is preferable: a storage property knows which
133
+ * backend holds it, and a bare string does not.
134
+ *
135
+ * - An **absolute URL** is already fetchable. Rendering it through the storage
136
+ * layer would ask a bucket to sign a path that was never in it.
137
+ * - Anything else is read as a **storage path** on the default source, which is
138
+ * the only source a value with no property can be attributed to. A resolver
139
+ * pointing at a named source should name the property instead.
140
+ */
141
+ function ComputedImage({ value, size, fill }: { value: string, size: PreviewSize, fill?: boolean }) {
142
+ const isAbsolute = isFetchableImageUrl(value);
143
+
144
+ if (isAbsolute) {
145
+ return <UrlComponentPreview previewType="image"
146
+ url={value}
147
+ size={size}
148
+ fill={fill}
149
+ hint={value}/>;
150
+ }
151
+
152
+ return <StorageThumbnail storagePathOrDownloadUrl={value}
153
+ storeUrl={false}
154
+ size={size}
155
+ fill={fill}/>;
156
+ }
@@ -24,6 +24,12 @@ export type SortButtonProps<M extends Record<string, unknown>> = {
24
24
  * the options offered.
25
25
  */
26
26
  properties: Properties;
27
+ /**
28
+ * Toolbar showing icon-only controls (split view, or a layout too narrow
29
+ * for the filters button's label). Only decides the icon size, which
30
+ * follows that button — see `CollectionViewStartActions`.
31
+ */
32
+ compact?: boolean;
27
33
  };
28
34
 
29
35
  /**
@@ -40,7 +46,8 @@ export type SortButtonProps<M extends Record<string, unknown>> = {
40
46
  */
41
47
  export function SortButton<M extends Record<string, unknown>>({
42
48
  tableController,
43
- properties
49
+ properties,
50
+ compact
44
51
  }: SortButtonProps<M>) {
45
52
 
46
53
  const { t } = useTranslation();
@@ -97,6 +104,8 @@ export function SortButton<M extends Record<string, unknown>>({
97
104
  // `asChild` — is what toggles it. A handler of our own would toggle it a
98
105
  // second time in the same click and the popover would never open; a
99
106
  // `Tooltip` in between would swallow the trigger's ref.
107
+ const arrowSize = compact ? iconSize.smallest : iconSize.small;
108
+
100
109
  const trigger = (
101
110
  <IconButton
102
111
  size={"small"}
@@ -104,11 +113,14 @@ export function SortButton<M extends Record<string, unknown>>({
104
113
  title={label}
105
114
  className={cls(activeOption && "text-primary")}
106
115
  >
116
+ {/* Same icon size as the filter controls it sits between: 16 in the
117
+ split view's narrow toolbar, 20 everywhere else. It was a flat
118
+ 16, which read as a smaller button next to them. */}
107
119
  {activeDirection === "desc"
108
- ? <ArrowDownIcon size={iconSize.smallest}/>
120
+ ? <ArrowDownIcon size={arrowSize}/>
109
121
  : activeDirection === "asc"
110
- ? <ArrowUpIcon size={iconSize.smallest}/>
111
- : <ArrowUpDownIcon size={iconSize.smallest}/>}
122
+ ? <ArrowUpIcon size={arrowSize}/>
123
+ : <ArrowUpDownIcon size={arrowSize}/>}
112
124
  </IconButton>
113
125
  );
114
126
 
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
 
3
- import { IconButton, iconSize, Tooltip, XIcon } from "@rebasepro/ui";
3
+ import { IconButton, iconSize, PanelLeftCloseIcon, Tooltip } from "@rebasepro/ui";
4
4
  import { useTranslation } from "@rebasepro/app";
5
5
 
6
6
  import { useSplitView } from "./SplitViewContext";
@@ -9,11 +9,24 @@ import { useSplitView } from "./SplitViewContext";
9
9
  * Closes the list of a split view, leaving the open record on its own.
10
10
  *
11
11
  * It leads the record's own app bar, where the breadcrumb starts — this is the
12
- * entity pane's old "Open full screen" button, moved to that edge and wearing an
13
- * X: closing the list and opening the record full screen are the same thing, so
14
- * there is one control and one route (`#full`) rather than two.
12
+ * entity pane's old "Open full screen" button, moved to that edge: closing the
13
+ * list and opening the record full screen are the same thing, so there is one
14
+ * control and one route (`#full`) rather than two. Full screen carries the
15
+ * mirrored icon to bring the list back.
16
+ *
17
+ * A pane glyph rather than the double chevron it wore first. Now that the bar
18
+ * ends in a ✕ that dismisses the record, an arrow pointing off the left edge of
19
+ * the record's own bar was the other thing on it that read as "close me" — and
20
+ * it is the one control here that does not act on the record at all.
15
21
  */
16
- export function SplitListCloseButton() {
22
+ export function SplitListCloseButton({ onBeforeHide }: {
23
+ /**
24
+ * Run before the layout changes, while this form is still mounted: the edit
25
+ * view uses it to hand its edit in progress to the full-screen form that is
26
+ * about to show the same record.
27
+ */
28
+ onBeforeHide?: () => void;
29
+ } = {}) {
17
30
 
18
31
  const { t } = useTranslation();
19
32
  const splitView = useSplitView();
@@ -24,9 +37,12 @@ export function SplitListCloseButton() {
24
37
  <Tooltip title={t("hide_list")}>
25
38
  <IconButton
26
39
  size="small"
27
- onClick={splitView.openFullScreen}
40
+ onClick={() => {
41
+ onBeforeHide?.();
42
+ splitView.openFullScreen();
43
+ }}
28
44
  aria-label={t("hide_list")}>
29
- <XIcon size={iconSize.smallest}/>
45
+ <PanelLeftCloseIcon size={iconSize.smallest}/>
30
46
  </IconButton>
31
47
  </Tooltip>
32
48
  );
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+
3
+ import { IconButton, iconSize, PanelLeftOpenIcon, Tooltip } from "@rebasepro/ui";
4
+ import { useTranslation } from "@rebasepro/app";
5
+
6
+ /**
7
+ * Brings the list back beside a record that was opened full screen.
8
+ *
9
+ * The mirror of {@link SplitListCloseButton}: the same edge of the same bar,
10
+ * the same pane glyph opening rather than closing, and the same single route —
11
+ * showing the list is dropping the `#full` hash. It replaces the back arrow
12
+ * where it applies, because the list it unfolds already holds the record.
13
+ */
14
+ export function SplitListShowButton({ onClick }: { onClick: () => void }) {
15
+
16
+ const { t } = useTranslation();
17
+
18
+ return (
19
+ <Tooltip title={t("show_list")}>
20
+ <IconButton
21
+ size="small"
22
+ onClick={onClick}
23
+ aria-label={t("show_list")}>
24
+ <PanelLeftOpenIcon size={iconSize.smallest}/>
25
+ </IconButton>
26
+ </Tooltip>
27
+ );
28
+ }