@rebasepro/cms 0.28.2 → 0.29.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.
Files changed (339) hide show
  1. package/README.md +3 -3
  2. package/dist/collection_editor/_cms_internals.d.ts +0 -1
  3. package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
  4. package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
  5. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
  6. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
  7. package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
  8. package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
  9. package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
  10. package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
  11. package/dist/components/AdditionalFieldValue.d.ts +9 -3
  12. package/dist/components/AdditionalFieldValue.js +7 -4
  13. package/dist/components/AdditionalFieldValue.js.map +1 -1
  14. package/dist/components/CollectionPanel.d.ts +117 -18
  15. package/dist/components/CollectionPanel.js +115 -37
  16. package/dist/components/CollectionPanel.js.map +1 -1
  17. package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
  18. package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
  19. package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
  20. package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
  21. package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
  22. package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
  23. package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
  24. package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
  25. package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
  26. package/dist/components/CollectionTableBinding/column_utils.js +6 -3
  27. package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
  28. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
  29. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
  30. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
  31. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
  32. package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
  33. package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
  34. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
  35. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
  36. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
  37. package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
  38. package/dist/components/CollectionTableBinding/internal/common.js +88 -4
  39. package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
  40. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
  41. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
  42. package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
  43. package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
  44. package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
  45. package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
  46. package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
  47. package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
  48. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
  49. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
  50. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
  51. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
  52. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
  53. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
  54. package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
  55. package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
  56. package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
  57. package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
  58. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
  59. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
  60. package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
  61. package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
  62. package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
  63. package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
  64. package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
  65. package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
  66. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
  67. package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
  68. package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
  69. package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
  70. package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
  71. package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
  72. package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
  73. package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
  74. package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
  75. package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
  76. package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
  77. package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
  78. package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
  79. package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
  80. package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
  81. package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
  82. package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
  83. package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
  84. package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
  85. package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
  86. package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
  87. package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
  88. package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
  89. package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
  90. package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
  91. package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
  92. package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
  93. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
  94. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
  95. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
  96. package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
  97. package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
  98. package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
  99. package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
  100. package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
  101. package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
  102. package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
  103. package/dist/components/CollectionViewBinding/RowActions.js +60 -0
  104. package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
  105. package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
  106. package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
  107. package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
  108. package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
  109. package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
  110. package/dist/components/CollectionViewBinding/fields.js +47 -0
  111. package/dist/components/CollectionViewBinding/fields.js.map +1 -0
  112. package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
  113. package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
  114. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
  115. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
  116. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
  117. package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
  118. package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
  119. package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
  120. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
  121. package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
  122. package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
  123. package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
  124. package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
  125. package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
  126. package/dist/components/CollectionsProvider.d.ts +3 -3
  127. package/dist/components/CollectionsProvider.js +4 -4
  128. package/dist/components/CollectionsProvider.js.map +1 -1
  129. package/dist/components/CollectionsScopeContext.d.ts +1 -1
  130. package/dist/components/CollectionsScopeContext.js +1 -1
  131. package/dist/components/CollectionsScopeContext.js.map +1 -1
  132. package/dist/components/DeleteEntityDialog.d.ts +1 -1
  133. package/dist/components/DeleteEntityDialog.js +2 -2
  134. package/dist/components/DeleteEntityDialog.js.map +1 -1
  135. package/dist/components/DetailViewBinding.js +32 -68
  136. package/dist/components/DetailViewBinding.js.map +1 -1
  137. package/dist/components/EditFormActions.js +5 -4
  138. package/dist/components/EditFormActions.js.map +1 -1
  139. package/dist/components/EditViewBinding.d.ts +2 -2
  140. package/dist/components/EditViewBinding.js +25 -15
  141. package/dist/components/EditViewBinding.js.map +1 -1
  142. package/dist/components/EntityDisplayHeader.js +8 -5
  143. package/dist/components/EntityDisplayHeader.js.map +1 -1
  144. package/dist/components/EntityPreviewBinding.js +1 -1
  145. package/dist/components/EntityPreviewBinding.js.map +1 -1
  146. package/dist/components/EntityViewBinding.d.ts +8 -1
  147. package/dist/components/EntityViewBinding.js +43 -14
  148. package/dist/components/EntityViewBinding.js.map +1 -1
  149. package/dist/components/EntityViewBody.d.ts +40 -0
  150. package/dist/components/EntityViewBody.js +90 -0
  151. package/dist/components/EntityViewBody.js.map +1 -0
  152. package/dist/components/FieldValue.d.ts +50 -0
  153. package/dist/components/FieldValue.js +81 -0
  154. package/dist/components/FieldValue.js.map +1 -0
  155. package/dist/components/InlineEntityPreview.js +1 -1
  156. package/dist/components/InlineEntityPreview.js.map +1 -1
  157. package/dist/components/PanelNotFound.d.ts +5 -0
  158. package/dist/components/PanelNotFound.js +21 -0
  159. package/dist/components/PanelNotFound.js.map +1 -0
  160. package/dist/components/RebaseCMS.d.ts +1 -1
  161. package/dist/components/RebaseCMS.js +11 -3
  162. package/dist/components/RebaseCMS.js.map +1 -1
  163. package/dist/components/RebaseNavigation.js +9 -3
  164. package/dist/components/RebaseNavigation.js.map +1 -1
  165. package/dist/components/RebaseShell.js +10 -5
  166. package/dist/components/RebaseShell.js.map +1 -1
  167. package/dist/components/RecordDetail.d.ts +61 -0
  168. package/dist/components/RecordDetail.js +123 -0
  169. package/dist/components/RecordDetail.js.map +1 -0
  170. package/dist/components/RecordForm.d.ts +126 -0
  171. package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
  172. package/dist/components/RecordForm.js.map +1 -0
  173. package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
  174. package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
  175. package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
  176. package/dist/components/ReferenceWidget.d.ts +5 -3
  177. package/dist/components/ReferenceWidget.js +10 -7
  178. package/dist/components/ReferenceWidget.js.map +1 -1
  179. package/dist/components/RelationSelector.js +4 -4
  180. package/dist/components/RelationSelector.js.map +1 -1
  181. package/dist/components/SelectableTable/SelectableTable.js +2 -3
  182. package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
  183. package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
  184. package/dist/components/SelectableTable/SelectionStore.js +1 -1
  185. package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
  186. package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
  187. package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
  188. package/dist/components/SidePanelBinding.js +13 -12
  189. package/dist/components/SidePanelBinding.js.map +1 -1
  190. package/dist/components/collection_prop.d.ts +18 -0
  191. package/dist/components/collection_prop.js +23 -0
  192. package/dist/components/collection_prop.js.map +1 -0
  193. package/dist/components/common/default_entity_actions.js +54 -54
  194. package/dist/components/common/default_entity_actions.js.map +1 -1
  195. package/dist/components/history/EntityHistoryView.d.ts +4 -1
  196. package/dist/components/history/EntityHistoryView.js +1 -1
  197. package/dist/components/history/EntityHistoryView.js.map +1 -1
  198. package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
  199. package/dist/components/index.d.ts +4 -2
  200. package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
  201. package/dist/data_export/export/ExportCollectionAction.js +4 -3
  202. package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
  203. package/dist/data_export/export/additional_fields.d.ts +6 -3
  204. package/dist/data_export/export/additional_fields.js +8 -4
  205. package/dist/data_export/export/additional_fields.js.map +1 -1
  206. package/dist/data_import/import/ImportCollectionAction.js +2 -2
  207. package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
  208. package/dist/form/EntityForm.d.ts +1 -1
  209. package/dist/form/EntityForm.js +255 -150
  210. package/dist/form/EntityForm.js.map +1 -1
  211. package/dist/form/EntityFormActions.js +3 -2
  212. package/dist/form/EntityFormActions.js.map +1 -1
  213. package/dist/form/EntityFormBinding.d.ts +1 -1
  214. package/dist/form/EntityFormBinding.js +22 -11
  215. package/dist/form/EntityFormBinding.js.map +1 -1
  216. package/dist/form/FormField.d.ts +36 -0
  217. package/dist/form/FormField.js +41 -0
  218. package/dist/form/FormField.js.map +1 -0
  219. package/dist/form/FormFieldsContext.d.ts +69 -0
  220. package/dist/form/FormFieldsContext.js +143 -0
  221. package/dist/form/FormFieldsContext.js.map +1 -0
  222. package/dist/form/PropertyFieldBinding.js +4 -4
  223. package/dist/form/PropertyFieldBinding.js.map +1 -1
  224. package/dist/form/collection_showing.d.ts +8 -0
  225. package/dist/form/collection_showing.js +29 -0
  226. package/dist/form/collection_showing.js.map +1 -0
  227. package/dist/form/components/ErrorFocus.js +2 -1
  228. package/dist/form/components/ErrorFocus.js.map +1 -1
  229. package/dist/form/components/FieldBlock.js +3 -1
  230. package/dist/form/components/FieldBlock.js.map +1 -1
  231. package/dist/form/components/FormRail.d.ts +5 -1
  232. package/dist/form/components/FormRail.js +5 -1
  233. package/dist/form/components/FormRail.js.map +1 -1
  234. package/dist/form/components/FormSections.d.ts +5 -1
  235. package/dist/form/components/FormSections.js +11 -4
  236. package/dist/form/components/FormSections.js.map +1 -1
  237. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
  238. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
  239. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
  240. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
  241. package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
  242. package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
  243. package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
  244. package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
  245. package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
  246. package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
  247. package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
  248. package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
  249. package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
  250. package/dist/form/form_dom_ids.d.ts +25 -0
  251. package/dist/form/form_dom_ids.js +42 -0
  252. package/dist/form/form_dom_ids.js.map +1 -0
  253. package/dist/form/index.d.ts +3 -1
  254. package/dist/form/resolve_cell_property.d.ts +5 -0
  255. package/dist/form/resolve_cell_property.js +22 -1
  256. package/dist/form/resolve_cell_property.js.map +1 -1
  257. package/dist/hooks/index.d.ts +1 -1
  258. package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
  259. package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
  260. package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
  261. package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
  262. package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
  263. package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
  264. package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
  265. package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
  266. package/dist/hooks/useBuildSidePanel.js +9 -9
  267. package/dist/hooks/useBuildSidePanel.js.map +1 -1
  268. package/dist/hooks/useEntityDisplay.js +6 -4
  269. package/dist/hooks/useEntityDisplay.js.map +1 -1
  270. package/dist/hooks/useRecordActions.js +2 -2
  271. package/dist/hooks/useRecordActions.js.map +1 -1
  272. package/dist/hooks/useSelectionDialog.d.ts +20 -7
  273. package/dist/hooks/useSelectionDialog.js +29 -8
  274. package/dist/hooks/useSelectionDialog.js.map +1 -1
  275. package/dist/index.d.ts +8 -3
  276. package/dist/index.js +15 -9
  277. package/dist/mcp-view.d.ts +9 -0
  278. package/dist/mcp-view.js +2 -0
  279. package/dist/mcp_view/app_modules.d.ts +29 -0
  280. package/dist/mcp_view/app_modules.js +163 -0
  281. package/dist/mcp_view/app_modules.js.map +1 -0
  282. package/dist/mcp_view/bridge.d.ts +90 -0
  283. package/dist/mcp_view/bridge.js +205 -0
  284. package/dist/mcp_view/bridge.js.map +1 -0
  285. package/dist/mcp_view/code_app.d.ts +65 -0
  286. package/dist/mcp_view/code_app.js +139 -0
  287. package/dist/mcp_view/code_app.js.map +1 -0
  288. package/dist/mcp_view/index.d.ts +54 -0
  289. package/dist/mcp_view/index.js +262 -0
  290. package/dist/mcp_view/index.js.map +1 -0
  291. package/dist/mcp_view/payload.d.ts +78 -0
  292. package/dist/mcp_view/payload.js +155 -0
  293. package/dist/mcp_view/payload.js.map +1 -0
  294. package/dist/mcp_view/screen.d.ts +30 -0
  295. package/dist/mcp_view/screen.js +245 -0
  296. package/dist/mcp_view/screen.js.map +1 -0
  297. package/dist/mcp_view/storage_source.d.ts +14 -0
  298. package/dist/mcp_view/storage_source.js +29 -0
  299. package/dist/mcp_view/storage_source.js.map +1 -0
  300. package/dist/mcp_view/store.d.ts +9 -0
  301. package/dist/mcp_view/store.js +27 -0
  302. package/dist/mcp_view/store.js.map +1 -0
  303. package/dist/mcp_view/tool_driver.d.ts +160 -0
  304. package/dist/mcp_view/tool_driver.js +575 -0
  305. package/dist/mcp_view/tool_driver.js.map +1 -0
  306. package/dist/preview/components/DatePreview.d.ts +34 -1
  307. package/dist/preview/components/DatePreview.js +72 -37
  308. package/dist/preview/components/DatePreview.js.map +1 -1
  309. package/dist/routes/RebaseRoute.js +1 -1
  310. package/dist/routes/RebaseRoute.js.map +1 -1
  311. package/dist/selection/SelectionMenu.d.ts +5 -3
  312. package/dist/selection/SelectionMenu.js +16 -9
  313. package/dist/selection/SelectionMenu.js.map +1 -1
  314. package/dist/selection/index.d.ts +2 -1
  315. package/dist/selection/resolve_selection.d.ts +61 -7
  316. package/dist/selection/resolve_selection.js +93 -11
  317. package/dist/selection/resolve_selection.js.map +1 -1
  318. package/dist/types/components/EntityFormProps.d.ts +60 -10
  319. package/dist/types/fields.d.ts +2 -65
  320. package/dist/util/dataControllerAdapter.d.ts +8 -0
  321. package/dist/util/dataControllerAdapter.js +11 -0
  322. package/dist/util/dataControllerAdapter.js.map +1 -1
  323. package/dist/util/navigation_utils.d.ts +5 -4
  324. package/dist/util/navigation_utils.js +6 -6
  325. package/dist/util/navigation_utils.js.map +1 -1
  326. package/dist/util/propertyConfigMapper.d.ts +8 -0
  327. package/dist/util/propertyConfigMapper.js +16 -2
  328. package/dist/util/propertyConfigMapper.js.map +1 -1
  329. package/package.json +15 -9
  330. package/recipes/README.md +79 -26
  331. package/recipes/approval-queue.tsx +79 -0
  332. package/recipes/bulk-set-status.tsx +23 -17
  333. package/recipes/calendar-view.tsx +28 -23
  334. package/recipes/master-detail.tsx +75 -0
  335. package/recipes/my-preferences.tsx +3 -3
  336. package/recipes/orders-dashboard.tsx +58 -84
  337. package/recipes/site-settings.tsx +4 -4
  338. package/dist/components/EntityFormPanel.d.ts +0 -63
  339. package/dist/components/EntityFormPanel.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionTableBinding.js","names":[],"sources":["../../../src/components/ReferenceTable/SelectionTableBinding.tsx"],"sourcesContent":["\nimport React, { MouseEventHandler, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { Entity, FilterValues } from \"@rebasepro/types\";\nimport { CollectionSize, AdminCollection } from \"@rebasepro/cms-types\";\n\nimport {\n CollectionRowActions,\n CollectionTableBinding\n} from \"../CollectionTableBinding\";\nimport {\n CollectionScopeProvider,\n useAuthController,\n useCustomizationController,\n useData,\n useDataTableController,\n useLargeLayout,\n usePermissions,\n useTranslation\n} from \"@rebasepro/app\";\nimport { ErrorView } from \"@rebasepro/app\";\nimport { Button, DialogActions, PlusIcon, Typography } from \"@rebasepro/ui\";\nimport { IconForView } from \"@rebasepro/app\";\nimport { useSelectionController } from \"../CollectionViewBinding/useSelectionController\";\n\nimport { useColumnIds } from \"@rebasepro/app\";\nimport { useSideDialogContext } from \"../SideDialogs\";\nimport { useAnalyticsController } from \"@rebasepro/app\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { useSidePanel } from \"../../hooks/useSidePanel\";\nimport { findEntitiesByIds } from \"../../util/find_entities_by_ids\";\n\n/** Stable identity, so the effect that propagates the picks does not re-fire. */\nconst EMPTY_ENTITIES: Entity<any>[] = [];\n\n/**\n * @group Components\n */\nexport interface SelectionProps<M extends Record<string, unknown>> {\n\n /**\n * Allow multiple selection of values\n */\n multiselect?: boolean;\n\n /**\n * Entity collection config\n */\n collection?: AdminCollection<M>;\n\n /**\n * Absolute path of the collection.\n * May be not set if this hook is being used in a component and the path is\n * dynamic. If not set, the dialog won't open.\n */\n path: string;\n\n /**\n * If you are opening the dialog for the first time, you can select some\n * entity ids to be displayed first.\n */\n selectedEntityIds?: (string | number)[];\n\n /**\n * If `multiselect` is set to `false`, you will get the selected entity\n * in this callback.\n * @param entity\n * @callback\n */\n onSingleEntitySelected?(entity: Entity<any> | null): void;\n\n /**\n * If `multiselect` is set to `true`, you will get the selected entities\n * in this callback.\n * @param entities\n * @callback\n */\n onMultipleEntitiesSelected?(entities: Entity<any>[]): void;\n\n /**\n * Called once, with the final selection, when the user presses Done.\n *\n * `onMultipleEntitiesSelected` reports every tick as it happens, which is\n * right when the selection *is* the value (a reference field). Use this\n * one instead when acting on the selection writes something — linking\n * rows, say — so a row ticked and then unticked, or a selection cleared,\n * is never acted on.\n * @param entities\n * @callback\n */\n onSelectionDone?(entities: Entity<M>[]): void;\n\n /**\n * Allow selection of entities that pass the given filter only.\n */\n fixedFilter?: FilterValues<string>;\n\n /**\n * Use this description to indicate the user what to do in this dialog.\n */\n description?: React.ReactNode;\n\n /**\n * Maximum number of entities that can be selected.\n */\n maxSelection?: number;\n\n}\n\n/**\n * This component allows to select entities from a given collection.\n * You probably want to open this dialog as a side view using {@link useSelectionTableBinding}\n * @group Components\n */\nexport function SelectionTableBinding<M extends Record<string, unknown>>(\n props: SelectionProps<M>\n) {\n if (!props.collection) {\n return <ErrorView\n error={\"Could not find collection\"}/>\n }\n return <SelectionTableBindingInternal {...props} collection={props.collection} />;\n}\n\nfunction SelectionTableBindingInternal<M extends Record<string, unknown>>(\n {\n onSingleEntitySelected,\n onMultipleEntitiesSelected,\n onSelectionDone,\n multiselect,\n collection,\n path: pathInput,\n selectedEntityIds: selectedEntityIdsProp,\n description,\n fixedFilter,\n maxSelection\n }: SelectionProps<M> & { collection: AdminCollection<M> }) {\n\n const sideDialogContext = useSideDialogContext();\n const sidePanelController = useSidePanel();\n const urlController = useUrlController();\n const analyticsController = useAnalyticsController();\n const { t } = useTranslation();\n\n const path = urlController.resolveDatabasePathsFrom(pathInput);\n\n const dataClient = useData();\n\n const [entitiesDisplayedFirst, setEntitiesDisplayedFirst] = useState<Entity<any>[]>([]);\n\n // Explicitly `<M>`: the hook defaults to `Record<string, unknown>`, and the\n // controller is handed to a table typed `SelectionController<M>`. `Entity<M>`\n // sits on both sides of that interface (`selectedEntities` out,\n // `toggleEntitySelection` in), so the default was never actually assignable\n // here — it only looked fine while the surrounding props gave TypeScript no\n // reason to bind `M` to this component's own parameter.\n const selectionController = useSelectionController<M>();\n\n // The rows picked in this dialog.\n //\n // This surface never enters query mode: it offers no \"select all matching\",\n // because pointing a reference field at every row of a collection is not\n // something anyone means to do, and `maxSelection` could not be enforced\n // against a count nobody has read yet. Every write below goes through\n // `setSelectedEntities`, so the query branch is unreachable here.\n const selectedEntities = selectionController.selection.type === \"entities\"\n ? selectionController.selection.entities\n : EMPTY_ENTITIES;\n\n // Track whether the selection has been initialized to avoid\n // firing onMultipleEntitiesSelected during the initial mount/fetch.\n const selectionInitializedRef = useRef(false);\n\n // Propagate selection changes to the parent callback.\n // This runs after the selectionController state updates, ensuring\n // we always send the correct, non-stale selection to the parent.\n useEffect(() => {\n if (!selectionInitializedRef.current) return;\n if (onMultipleEntitiesSelected) {\n onMultipleEntitiesSelected(selectedEntities);\n }\n }, [selectedEntities]);\n\n /**\n * Fetch initially selected ids\n */\n useEffect(() => {\n let unmounted = false;\n const selectedEntityIds = selectedEntityIdsProp?.map(id => id?.toString()).filter(Boolean);\n if (selectedEntityIds && selectedEntityIds.length > 0 && collection) {\n // One request per 1,000 ids, not one per id (see findEntitiesByIds).\n findEntitiesByIds(dataClient.collection<M>(path), collection, selectedEntityIds)\n .then((found) => {\n if (!unmounted) {\n // In the order given; an id with no row is dropped.\n const result = selectedEntityIds\n .map(id => found.get(id))\n .filter((e): e is Entity<any> => !!e);\n selectionController.setSelectedEntities(result);\n setEntitiesDisplayedFirst(result);\n // Mark initialized after the initial fetch completes\n selectionInitializedRef.current = true;\n }\n });\n } else {\n selectionController.setSelectedEntities([]);\n setEntitiesDisplayedFirst([]);\n selectionInitializedRef.current = true;\n }\n return () => {\n unmounted = true;\n };\n }, [dataClient, path, selectedEntityIdsProp, collection, selectionController.setSelectedEntities]);\n\n const onClear = () => {\n analyticsController.onAnalyticsEvent?.(\"reference_selection_clear\", {\n path\n });\n selectionController.setSelectedEntities([]);\n if (!multiselect && onSingleEntitySelected) {\n onSingleEntitySelected(null);\n }\n };\n\n const onEntityClick = useCallback((entity: Entity<any>) => {\n if (!multiselect && onSingleEntitySelected) {\n analyticsController.onAnalyticsEvent?.(\"reference_selected_single\", {\n path,\n entityId: entity.id\n });\n onSingleEntitySelected(entity);\n sideDialogContext.close(false);\n } else {\n // For multiselect, delegate to the selection controller's toggle.\n // The useEffect above will propagate the change to onMultipleEntitiesSelected.\n analyticsController.onAnalyticsEvent?.(\"reference_selection_toggle\", {\n path,\n entityId: entity.id\n });\n if (selectedEntities.map((e) => e.id).indexOf(entity.id) > -1) {\n selectionController.setSelectedEntities(\n selectedEntities.filter((item: Entity<any>) => item.id !== entity.id)\n );\n } else {\n if (maxSelection && selectedEntities.length >= maxSelection) return;\n selectionController.setSelectedEntities([...selectedEntities, entity]);\n }\n }\n }, [multiselect, onSingleEntitySelected, analyticsController, path, sideDialogContext, selectionController, selectedEntities, maxSelection]);\n\n // create a new entity from within the reference dialog\n const onNewClick = () => {\n analyticsController.onAnalyticsEvent?.(\"reference_selection_new_entity\", {\n path\n });\n sidePanelController.open({\n path: path,\n collection,\n // No URL, for the reason `RelationSelector` does the same: this\n // panel is a step inside the selection dialog, which is itself a\n // step inside whatever form opened it. `useUnsavedChangesDialog`\n // blocks on a *pathname* change, and this panel's path is a\n // different collection from the one being edited — so closing it\n // raced the panel clearing its own dirty flag and answered a\n // successful save with \"There are unsaved changes\", leaving the URL\n // on the target collection. A record that does not exist yet has no\n // address worth restoring anyway.\n updateUrl: false,\n onUpdate: ({ entity }) => {\n setEntitiesDisplayedFirst([entity, ...entitiesDisplayedFirst]);\n onEntityClick(entity);\n },\n closeOnSave: true\n });\n };\n\n const tableRowActionsBuilder = ({\n entity,\n size,\n width,\n frozen\n }: {\n entity: Entity<any>,\n size: CollectionSize,\n width: number,\n frozen?: boolean\n }) => {\n const isSelected = selectionController.isEntitySelected(entity);\n return <CollectionRowActions\n width={width}\n frozen={frozen}\n entity={entity}\n size={size}\n isSelected={isSelected}\n selectionEnabled={multiselect}\n hideId={collection?.hideIdFromCollection}\n path={path}\n selectionController={selectionController}\n openEntityMode={\"side_panel\"}\n />;\n\n };\n\n const onDone = useCallback((event: React.SyntheticEvent) => {\n event.stopPropagation();\n onSelectionDone?.(selectedEntities);\n sideDialogContext.close(false);\n }, [sideDialogContext, onSelectionDone, selectedEntities]);\n\n const displayedColumnIds = useColumnIds(collection, false);\n\n const tableController = useDataTableController<M>({\n path,\n collection,\n entitiesDisplayedFirst,\n fixedFilter,\n updateUrl: false\n });\n\n return (\n\n <CollectionScopeProvider collection={collection}>\n <div className=\"flex flex-col h-full\">\n\n <div className=\"grow\">\n {entitiesDisplayedFirst &&\n <CollectionTableBinding\n additionalFields={collection.additionalFields}\n displayedColumnIds={displayedColumnIds}\n onEntityClick={onEntityClick}\n tableController={tableController}\n enablePopupIcon={false}\n tableRowActionsBuilder={tableRowActionsBuilder}\n openEntityMode={\"side_panel\"}\n title={<Typography variant={\"subtitle2\"} className={\"flex flex-row gap-2\"}>\n <IconForView\n size={\"small\"}\n collectionOrView={collection}\n className={\"text-surface-300 dark:text-surface-600\"}/>\n {collection.singularName\n ? t(\"select_specific\", { name: collection.singularName })\n : t(\"select_from\", { name: collection.name })}\n </Typography>}\n defaultSize={collection.defaultSize}\n properties={collection.properties}\n fixedFilter={fixedFilter}\n inlineEditing={false}\n selectionController={selectionController}\n actions={<EntitySelectionDialogActions\n collection={collection}\n path={path}\n onNewClick={onNewClick}\n onClear={onClear}/>\n }\n />}\n </div>\n <DialogActions translucent={false}>\n {description &&\n <Typography variant={\"body2\"}\n className=\"grow text-left\">\n {description}\n </Typography>}\n <Button\n onClick={onDone}\n variant=\"filled\">\n {t(\"done\")}\n </Button>\n </DialogActions>\n </div>\n </CollectionScopeProvider>\n\n );\n\n}\n\nfunction EntitySelectionDialogActions({\n collection,\n path,\n onClear,\n onNewClick\n}: {\n collection: AdminCollection<any>,\n path: string,\n onClear: () => void,\n onNewClick: () => void\n}) {\n\n const { canCreate } = usePermissions();\n\n const largeLayout = useLargeLayout();\n const { t } = useTranslation();\n\n const onClick: MouseEventHandler<HTMLButtonElement> | undefined = onNewClick\n ? (e) => {\n e.preventDefault();\n onNewClick();\n }\n : undefined;\n const addButton = canCreate(collection, path) &&\n onClick && (largeLayout\n ? <Button\n onClick={onClick}\n startIcon={<PlusIcon/>}>\n {t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </Button>\n : <Button\n onClick={onClick}>\n <PlusIcon/>\n </Button>);\n\n return (\n <>\n <Button onClick={onClear}\n variant={\"text\"}>\n {t(\"clear\")}\n </Button>\n {addButton}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAgCA,IAAM,iBAAgC,CAAC;;;;;;AAiFvC,SAAgB,sBACZ,OACF;CACE,IAAI,CAAC,MAAM,YACP,OAAO,oBAAC,WAAD,E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C,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,UAA4D,cAC3D,MAAM;EACL,EAAE,eAAe;EACjB,WAAW;CACf,IACE,KAAA;CACN,MAAM,YAAY,UAAU,YAAY,IAAI,KACxC,YAAY,cACN,oBAAC,QAAD;EACW;EACT,WAAW,oBAAC,UAAD,CAAU,CAAA;YACpB,EAAE,gBAAgB,EAAE,MAAM,WAAW,gBAAgB,WAAW,KAAK,CAAC;CACnE,CAAA,IACN,oBAAC,QAAD;EACW;YACT,oBAAC,UAAD,CAAU,CAAA;CACN,CAAA;CAEhB,OACI,qBAAA,UAAA,EAAA,UAAA,CACI,oBAAC,QAAD;EAAQ,SAAS;EACb,SAAS;YACR,EAAE,OAAO;CACN,CAAA,GACP,SACH,EAAA,CAAA;AAEV"}
1
+ {"version":3,"file":"SelectionTableBinding.js","names":[],"sources":["../../../src/components/ReferenceTable/SelectionTableBinding.tsx"],"sourcesContent":["\nimport React, { MouseEventHandler, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { Entity, FilterValues } from \"@rebasepro/types\";\nimport { CollectionSize, AdminCollection } from \"@rebasepro/cms-types\";\n\nimport {\n CollectionRowActions,\n CollectionTableBinding\n} from \"../CollectionTableBinding\";\nimport {\n CollectionScopeProvider,\n useAuthController,\n useCustomizationController,\n useData,\n useDataTableController,\n usePermissions,\n useTranslation\n} from \"@rebasepro/app\";\nimport { ErrorView } from \"@rebasepro/app\";\nimport { Button, DialogActions, PlusIcon, Typography, useElementWidth } from \"@rebasepro/ui\";\nimport { IconForView } from \"@rebasepro/app\";\nimport { useEntitySelectionController } from \"../CollectionViewBinding/useSelectionController\";\nimport { CollectionViewLayoutContext, LARGE_COLLECTION_WIDTH, useCollectionLargeLayout } from \"../CollectionViewBinding/useCollectionLargeLayout\";\n\nimport { useColumnIds } from \"@rebasepro/app\";\nimport { useSideDialogContext } from \"../SideDialogs\";\nimport { useAnalyticsController } from \"@rebasepro/app\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { useSidePanel } from \"../../hooks/useSidePanel\";\nimport { findEntitiesByIds } from \"../../util/find_entities_by_ids\";\nimport { entityOfRow, rowOfEntity } from \"@rebasepro/app\";\n\n/** Stable identity, so the effect that propagates the picks does not re-fire. */\nconst EMPTY_ENTITIES: Entity<any>[] = [];\n\n/**\n * What {@link useSelectionDialog} and {@link SelectionTableBinding} take: a\n * collection to pick rows from, and what to do with the rows picked. The rows\n * are the server's, as `useRows` returns them, and each callback is handed\n * their ids beside them — the strings `selectedIds` and `useSidePanel().open`\n * take.\n *\n * @group Components\n */\nexport interface SelectionProps<M extends Record<string, unknown>> {\n\n /**\n * Allow multiple selection of values\n */\n multiselect?: boolean;\n\n /**\n * Entity collection config\n */\n collection?: AdminCollection<M>;\n\n /**\n * Absolute path of the collection.\n * May be not set if this hook is being used in a component and the path is\n * dynamic. If not set, the dialog won't open.\n */\n path: string;\n\n /**\n * The ids of the rows to show as selected, and first, when the dialog\n * opens.\n */\n selectedIds?: (string | number)[];\n\n /**\n * If `multiselect` is `false`: the row picked and its id, or `null` when\n * the selection is cleared.\n * @callback\n */\n onSingleRowSelected?(row: Record<string, unknown> | null, id: string | null): void;\n\n /**\n * If `multiselect` is `true`: the rows selected and their ids, on every tick.\n * @callback\n */\n onMultipleRowsSelected?(rows: Record<string, unknown>[], ids: string[]): void;\n\n /**\n * Called once, with the rows finally selected and their ids, when the\n * user presses Done.\n *\n * `onMultipleRowsSelected` reports every tick as it happens, which is\n * right when the selection *is* the value (a reference field). Use this\n * one instead when acting on the selection writes something — linking\n * rows, say — so a row ticked and then unticked, or a selection cleared,\n * is never acted on.\n * @callback\n */\n onSelectionDone?(rows: Record<string, unknown>[], ids: string[]): void;\n\n /**\n * Allow selection of entities that pass the given filter only.\n */\n fixedFilter?: FilterValues<string>;\n\n /**\n * Use this description to indicate the user what to do in this dialog.\n */\n description?: React.ReactNode;\n\n /**\n * Maximum number of entities that can be selected.\n */\n maxSelection?: number;\n\n}\n\n/**\n * The admin's own picker props: {@link SelectionProps} over its `Entity` view\n * model, for the reference and relation fields, which build their values from\n * the records picked.\n *\n * @internal\n */\nexport interface EntitySelectionProps<M extends Record<string, unknown>> extends Omit<SelectionProps<M>,\n \"selectedIds\" | \"onSingleRowSelected\" | \"onMultipleRowsSelected\" | \"onSelectionDone\"> {\n selectedEntityIds?: (string | number)[];\n onSingleEntitySelected?(entity: Entity<any> | null): void;\n onMultipleEntitiesSelected?(entities: Entity<any>[]): void;\n onSelectionDone?(entities: Entity<M>[]): void;\n}\n\nfunction idsOf(entities: Entity<any>[]): string[] {\n return entities.map((entity) => String(entity.id));\n}\n\n/**\n * Pick rows from a collection, in a table. You probably want to open it as a\n * side dialog with {@link useSelectionDialog}.\n *\n * @group Components\n */\nexport function SelectionTableBinding<M extends Record<string, unknown>>(props: SelectionProps<M>) {\n return <EntitySelectionTable<M> {...entitySelectionPropsOf(props)}/>;\n}\n\n/**\n * {@link SelectionProps} as the admin's own picker takes them: each callback\n * handed the rows of the records picked.\n *\n * @internal\n */\nexport function entitySelectionPropsOf<M extends Record<string, unknown>>({\n selectedIds,\n onSingleRowSelected,\n onMultipleRowsSelected,\n onSelectionDone,\n ...props\n}: SelectionProps<M>): EntitySelectionProps<M> {\n const collection = props.collection;\n return {\n ...props,\n selectedEntityIds: selectedIds,\n onSingleEntitySelected: onSingleRowSelected\n && ((entity) => onSingleRowSelected(entity ? rowOfEntity(entity, collection) : null, entity ? String(entity.id) : null)),\n onMultipleEntitiesSelected: onMultipleRowsSelected\n && ((entities) => onMultipleRowsSelected(entities.map((entity) => rowOfEntity(entity, collection)), idsOf(entities))),\n onSelectionDone: onSelectionDone\n && ((entities) => onSelectionDone(entities.map((entity) => rowOfEntity(entity, collection)), idsOf(entities)))\n };\n}\n\n/**\n * The admin's own picker, over its `Entity` view model.\n *\n * @internal\n */\nexport function EntitySelectionTable<M extends Record<string, unknown>>(\n props: EntitySelectionProps<M>\n) {\n if (!props.collection) {\n return <ErrorView\n error={\"Could not find collection\"}/>\n }\n return <SelectionTableBindingInternal {...props} collection={props.collection} />;\n}\n\nfunction SelectionTableBindingInternal<M extends Record<string, unknown>>(\n {\n onSingleEntitySelected,\n onMultipleEntitiesSelected,\n onSelectionDone,\n multiselect,\n collection,\n path: pathInput,\n selectedEntityIds: selectedEntityIdsProp,\n description,\n fixedFilter,\n maxSelection\n }: EntitySelectionProps<M> & { collection: AdminCollection<M> }) {\n\n const sideDialogContext = useSideDialogContext();\n const sidePanelController = useSidePanel();\n const urlController = useUrlController();\n const analyticsController = useAnalyticsController();\n const { t } = useTranslation();\n\n const path = urlController.resolveDatabasePathsFrom(pathInput);\n\n const dataClient = useData();\n\n const [entitiesDisplayedFirst, setEntitiesDisplayedFirst] = useState<Entity<any>[]>([]);\n\n // Explicitly `<M>`: the hook defaults to `Record<string, unknown>`, and the\n // controller is handed to a table typed `EntitySelectionController<M>`. `Entity<M>`\n // sits on both sides of that interface (`selectedEntities` out,\n // `toggleEntitySelection` in), so the default was never actually assignable\n // here — it only looked fine while the surrounding props gave TypeScript no\n // reason to bind `M` to this component's own parameter.\n const selectionController = useEntitySelectionController<M>();\n\n // The rows picked in this dialog.\n //\n // This surface never enters query mode: it offers no \"select all matching\",\n // because pointing a reference field at every row of a collection is not\n // something anyone means to do, and `maxSelection` could not be enforced\n // against a count nobody has read yet. Every write below goes through\n // `setSelectedEntities`, so the query branch is unreachable here.\n const selectedEntities = selectionController.selection.type === \"entities\"\n ? selectionController.selection.entities\n : EMPTY_ENTITIES;\n\n // Track whether the selection has been initialized to avoid\n // firing onMultipleEntitiesSelected during the initial mount/fetch.\n const selectionInitializedRef = useRef(false);\n\n // Propagate selection changes to the parent callback.\n // This runs after the selectionController state updates, ensuring\n // we always send the correct, non-stale selection to the parent.\n useEffect(() => {\n if (!selectionInitializedRef.current) return;\n if (onMultipleEntitiesSelected) {\n onMultipleEntitiesSelected(selectedEntities);\n }\n }, [selectedEntities]);\n\n /**\n * Fetch initially selected ids\n */\n useEffect(() => {\n let unmounted = false;\n const selectedEntityIds = selectedEntityIdsProp?.map(id => id?.toString()).filter(Boolean);\n if (selectedEntityIds && selectedEntityIds.length > 0 && collection) {\n // One request per 1,000 ids, not one per id (see findEntitiesByIds).\n findEntitiesByIds(dataClient.collection<M>(path), collection, selectedEntityIds)\n .then((found) => {\n if (!unmounted) {\n // In the order given; an id with no row is dropped.\n const result = selectedEntityIds\n .map(id => found.get(id))\n .filter((e): e is Entity<any> => !!e);\n selectionController.setSelectedEntities(result);\n setEntitiesDisplayedFirst(result);\n // Mark initialized after the initial fetch completes\n selectionInitializedRef.current = true;\n }\n });\n } else {\n selectionController.setSelectedEntities([]);\n setEntitiesDisplayedFirst([]);\n selectionInitializedRef.current = true;\n }\n return () => {\n unmounted = true;\n };\n }, [dataClient, path, selectedEntityIdsProp, collection, selectionController.setSelectedEntities]);\n\n const onClear = () => {\n analyticsController.onAnalyticsEvent?.(\"reference_selection_clear\", {\n path\n });\n selectionController.setSelectedEntities([]);\n if (!multiselect && onSingleEntitySelected) {\n onSingleEntitySelected(null);\n }\n };\n\n const onEntityClick = useCallback((entity: Entity<any>) => {\n if (!multiselect && onSingleEntitySelected) {\n analyticsController.onAnalyticsEvent?.(\"reference_selected_single\", {\n path,\n entityId: entity.id\n });\n onSingleEntitySelected(entity);\n sideDialogContext.close(false);\n } else {\n // For multiselect, delegate to the selection controller's toggle.\n // The useEffect above will propagate the change to onMultipleEntitiesSelected.\n analyticsController.onAnalyticsEvent?.(\"reference_selection_toggle\", {\n path,\n entityId: entity.id\n });\n if (selectedEntities.some((e) => String(e.id) === String(entity.id))) {\n selectionController.setSelectedEntities(\n selectedEntities.filter((item: Entity<any>) => String(item.id) !== String(entity.id))\n );\n } else {\n if (maxSelection && selectedEntities.length >= maxSelection) return;\n selectionController.setSelectedEntities([...selectedEntities, entity]);\n }\n }\n }, [multiselect, onSingleEntitySelected, analyticsController, path, sideDialogContext, selectionController, selectedEntities, maxSelection]);\n\n // create a new entity from within the reference dialog\n const onNewClick = () => {\n analyticsController.onAnalyticsEvent?.(\"reference_selection_new_entity\", {\n path\n });\n sidePanelController.open({\n path: path,\n collection,\n // No URL, for the reason `RelationSelector` does the same: this\n // panel is a step inside the selection dialog, which is itself a\n // step inside whatever form opened it. `useUnsavedChangesDialog`\n // blocks on a *pathname* change, and this panel's path is a\n // different collection from the one being edited — so closing it\n // raced the panel clearing its own dirty flag and answered a\n // successful save with \"There are unsaved changes\", leaving the URL\n // on the target collection. A record that does not exist yet has no\n // address worth restoring anyway.\n updateUrl: false,\n onSaved: ({ row, id }) => {\n const entity = entityOfRow(row, id, path, collection);\n setEntitiesDisplayedFirst([entity, ...entitiesDisplayedFirst]);\n onEntityClick(entity);\n },\n closeOnSave: true\n });\n };\n\n const tableRowActionsBuilder = ({\n entity,\n size,\n width,\n frozen\n }: {\n entity: Entity<any>,\n size: CollectionSize,\n width: number,\n frozen?: boolean\n }) => {\n const isSelected = selectionController.isEntitySelected(entity);\n return <CollectionRowActions\n width={width}\n frozen={frozen}\n entity={entity}\n size={size}\n isSelected={isSelected}\n selectionEnabled={multiselect}\n hideId={collection?.hideIdFromCollection}\n path={path}\n selectionController={selectionController}\n openEntityMode={\"side_panel\"}\n />;\n\n };\n\n const onDone = useCallback((event: React.SyntheticEvent) => {\n event.stopPropagation();\n onSelectionDone?.(selectedEntities);\n sideDialogContext.close(false);\n }, [sideDialogContext, onSelectionDone, selectedEntities]);\n\n const displayedColumnIds = useColumnIds(collection, false);\n\n const tableController = useDataTableController<M>({\n path,\n collection,\n entitiesDisplayedFirst,\n fixedFilter,\n updateUrl: false\n });\n\n // The picker lays its table out by its own width, as a collection view\n // does: a dialog is narrow in a wide window.\n const [measureRef, width] = useElementWidth<HTMLDivElement>();\n const large = width > 0 ? width >= LARGE_COLLECTION_WIDTH : undefined;\n\n return (\n\n <CollectionScopeProvider collection={collection}>\n <CollectionViewLayoutContext.Provider value={large}>\n <div className=\"@container/collection flex flex-col h-full\" ref={measureRef}>\n\n <div className=\"grow\">\n {entitiesDisplayedFirst &&\n <CollectionTableBinding\n additionalFields={collection.additionalFields}\n displayedColumnIds={displayedColumnIds}\n onEntityClick={onEntityClick}\n tableController={tableController}\n enablePopupIcon={false}\n tableRowActionsBuilder={tableRowActionsBuilder}\n openEntityMode={\"side_panel\"}\n title={<Typography variant={\"subtitle2\"} className={\"flex flex-row gap-2\"}>\n <IconForView\n size={\"small\"}\n collectionOrView={collection}\n className={\"text-surface-300 dark:text-surface-600\"}/>\n {collection.singularName\n ? t(\"select_specific\", { name: collection.singularName })\n : t(\"select_from\", { name: collection.name })}\n </Typography>}\n defaultSize={collection.defaultSize}\n properties={collection.properties}\n fixedFilter={fixedFilter}\n inlineEditing={false}\n selectionController={selectionController}\n actions={<EntitySelectionDialogActions\n collection={collection}\n path={path}\n onNewClick={onNewClick}\n onClear={onClear}/>\n }\n />}\n </div>\n <DialogActions translucent={false}>\n {description &&\n <Typography variant={\"body2\"}\n className=\"grow text-left\">\n {description}\n </Typography>}\n <Button\n onClick={onDone}\n variant=\"filled\">\n {t(\"done\")}\n </Button>\n </DialogActions>\n </div>\n </CollectionViewLayoutContext.Provider>\n </CollectionScopeProvider>\n\n );\n\n}\n\nfunction EntitySelectionDialogActions({\n collection,\n path,\n onClear,\n onNewClick\n}: {\n collection: AdminCollection<any>,\n path: string,\n onClear: () => void,\n onNewClick: () => void\n}) {\n\n const { canCreate } = usePermissions();\n\n const largeLayout = useCollectionLargeLayout();\n const { t } = useTranslation();\n\n const onClick: MouseEventHandler<HTMLButtonElement> | undefined = onNewClick\n ? (e) => {\n e.preventDefault();\n onNewClick();\n }\n : undefined;\n const addButton = canCreate(collection, path) &&\n onClick && (largeLayout\n ? <Button\n onClick={onClick}\n startIcon={<PlusIcon/>}>\n {t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </Button>\n : <Button\n onClick={onClick}>\n <PlusIcon/>\n </Button>);\n\n return (\n <>\n <Button onClick={onClear}\n variant={\"text\"}>\n {t(\"clear\")}\n </Button>\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EACW;EACT,WAAW,oBAAC,UAAD,CAAU,CAAA;YACpB,EAAE,gBAAgB,EAAE,MAAM,WAAW,gBAAgB,WAAW,KAAK,CAAC;CACnE,CAAA,IACN,oBAAC,QAAD;EACW;YACT,oBAAC,UAAD,CAAU,CAAA;CACN,CAAA;CAEhB,OACI,qBAAA,UAAA,EAAA,UAAA,CACI,oBAAC,QAAD;EAAQ,SAAS;EACb,SAAS;YACR,EAAE,OAAO;CACN,CAAA,GACP,SACH,EAAA,CAAA;AAEV"}
@@ -1,17 +1,19 @@
1
1
  import React from "react";
2
- import { Entity, EntityReference, FilterValues } from "@rebasepro/types";
2
+ import { EntityReference, FilterValues } from "@rebasepro/types";
3
3
  import type { PreviewSize } from "../types/components/PropertyPreviewProps.js";
4
4
  export type ReferenceWidgetProps<M extends Record<string, unknown>> = {
5
5
  name?: string;
6
6
  multiselect?: boolean;
7
7
  value: EntityReference | EntityReference[] | null;
8
+ /** The reference picked, and its row as the server sends it; `null` when cleared. */
8
9
  onReferenceSelected?: (params: {
9
10
  reference: EntityReference | null;
10
- entity: Entity<M> | null;
11
+ row: Record<string, unknown> | null;
11
12
  }) => void;
13
+ /** The references picked, and their rows as the server sends them. */
12
14
  onMultipleReferenceSelected?: (params: {
13
15
  references: EntityReference[] | null;
14
- entities: Entity<M>[] | null;
16
+ rows: Record<string, unknown>[] | null;
15
17
  }) => void;
16
18
  path: string;
17
19
  disabled?: boolean;
@@ -1,10 +1,11 @@
1
1
  import { useCollectionRegistryController } from "../hooks/navigation/contexts/CollectionRegistryContext.js";
2
2
  import { useReferencePaths } from "../hooks/useReferencePaths.js";
3
3
  import { ReferencePreview } from "../preview/components/ReferencePreview.js";
4
- import { useSelectionDialog } from "../hooks/useSelectionDialog.js";
4
+ import { useEntitySelectionDialog } from "../hooks/useSelectionDialog.js";
5
5
  import { useCallback, useMemo } from "react";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { Button, cls } from "@rebasepro/ui";
8
+ import { rowOfEntity } from "@rebasepro/app";
8
9
  //#region src/components/ReferenceWidget.tsx
9
10
  /**
10
11
  * This field allows selecting reference/s.
@@ -22,26 +23,28 @@ function ReferenceWidget({ name, multiselect = false, path, disabled, value, onR
22
23
  const reference = entity ? referenceTo(entity) : null;
23
24
  onReferenceSelected?.({
24
25
  reference,
25
- entity
26
+ row: entity ? rowOfEntity(entity, collection) : null
26
27
  });
27
28
  }
28
29
  }, [
29
30
  disabled,
30
31
  onReferenceSelected,
31
- referenceTo
32
+ referenceTo,
33
+ collection
32
34
  ]);
33
35
  const onMultipleEntitiesSelected = useCallback((entities) => {
34
36
  if (disabled) return;
35
37
  if (onMultipleReferenceSelected) onMultipleReferenceSelected({
36
38
  references: entities ? entities.map((e) => referenceTo(e)) : null,
37
- entities
39
+ rows: entities ? entities.map((e) => rowOfEntity(e, collection)) : null
38
40
  });
39
41
  }, [
40
42
  disabled,
41
- onReferenceSelected,
42
- referenceTo
43
+ onMultipleReferenceSelected,
44
+ referenceTo,
45
+ collection
43
46
  ]);
44
- const referenceDialogController = useSelectionDialog({
47
+ const referenceDialogController = useEntitySelectionDialog({
45
48
  multiselect,
46
49
  path: collectionPath,
47
50
  collection,
@@ -1 +1 @@
1
- {"version":3,"file":"ReferenceWidget.js","names":[],"sources":["../../src/components/ReferenceWidget.tsx"],"sourcesContent":["import { useSelectionDialog } from \"../hooks/useSelectionDialog\";\n\nimport React, { useCallback, useMemo } from \"react\";\n\nimport { Entity, EntityReference, FilterValues } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../types/components/PropertyPreviewProps\";\nimport { ReferencePreview } from \"../preview\";\nimport { Button, cls } from \"@rebasepro/ui\";\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../hooks/useReferencePaths\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type ReferenceWidgetProps<M extends Record<string, unknown>> = {\n name?: string,\n multiselect?: boolean,\n value: EntityReference | EntityReference[] | null,\n onReferenceSelected?: (params: {\n reference: EntityReference | null,\n entity: Entity<M> | null\n }) => void,\n onMultipleReferenceSelected?: (params: {\n references: EntityReference[] | null,\n entities: Entity<M>[] | null\n }) => void,\n path: string,\n disabled?: boolean,\n previewProperties?: string[];\n /**\n * Allow selection of entities that pass the given filter only.\n */\n fixedFilter?: FilterValues<string>;\n size: PreviewSize;\n className?: string;\n includeId?: boolean;\n includeEntityLink?: boolean;\n};\n\n/**\n * This field allows selecting reference/s.\n */\nexport function ReferenceWidget<M extends Record<string, unknown>>({\n name,\n multiselect = false,\n path,\n disabled,\n value,\n onReferenceSelected,\n onMultipleReferenceSelected,\n previewProperties,\n fixedFilter,\n size,\n className,\n includeId,\n includeEntityLink\n}: ReferenceWidgetProps<M>) {\n\n const collectionRegistryController = useCollectionRegistryController();\n const { toCollectionPath, referenceTo } = useReferencePaths();\n const collectionPath = toCollectionPath(path);\n\n const collection: AdminCollection | undefined = useMemo(() => {\n return collectionRegistryController.getCollection(collectionPath);\n }, [collectionPath, collectionRegistryController.getCollection]);\n\n const onSingleEntitySelected = useCallback((entity: Entity<M> | null) => {\n if (disabled)\n return;\n if (onReferenceSelected) {\n const reference = entity ? referenceTo(entity) : null;\n onReferenceSelected?.({\n reference,\n entity\n });\n }\n }, [disabled, onReferenceSelected, referenceTo]);\n\n const onMultipleEntitiesSelected = useCallback((entities: Entity<M>[]) => {\n if (disabled)\n return;\n if (onMultipleReferenceSelected) {\n const references = entities ? entities.map(e => referenceTo(e)) : null;\n onMultipleReferenceSelected({\n references,\n entities\n });\n }\n }, [disabled, onReferenceSelected, referenceTo]);\n\n const referenceDialogController = useSelectionDialog({\n multiselect,\n path: collectionPath,\n collection,\n onSingleEntitySelected,\n onMultipleEntitiesSelected,\n fixedFilter\n }\n );\n\n const clearValue = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n if (multiselect) {\n onMultipleEntitiesSelected([]);\n } else {\n onSingleEntitySelected(null);\n }\n }, [onReferenceSelected]);\n\n let child: React.ReactNode;\n\n const onEntryClick = () => {\n if (disabled)\n return;\n referenceDialogController.open();\n };\n\n if (Array.isArray(value)) {\n child = <div className={\"flex flex-col gap-4\"}>\n {value.map((ref, index) => {\n return <ReferencePreview\n key={`reference_preview_${index}`}\n onClick={onEntryClick}\n reference={ref}\n disabled={disabled}\n previewProperties={previewProperties}\n size={size}\n includeId={includeId}\n includeEntityLink={includeEntityLink}/>\n })}\n </div>\n } else if (value?.isEntityReference && value?.isEntityReference()) {\n child = <ReferencePreview\n reference={value}\n onClick={onEntryClick}\n disabled={disabled}\n previewProperties={previewProperties}\n size={size}\n includeId={includeId}\n includeEntityLink={includeEntityLink}/>\n\n }\n return <div className={cls(\"text-sm font-medium\",\n \"min-w-80 flex flex-col gap-4\",\n \"relative transition-colors duration-200 ease-in rounded-xs font-medium\",\n \"dark:text-white/50 text-text-primary/50 dark:text-text-primary-dark/50 dark:text-white/50\",\n className\n )}>\n\n {child}\n {!value && <div className=\"justify-center text-left\">\n <Button disabled={disabled}\n onClick={onEntryClick}>\n Edit {name}\n </Button>\n </div>}\n\n </div>;\n}\n"],"mappings":";;;;;;;;;;;AAwCA,SAAgB,gBAAmD,EAC/D,MACA,cAAc,OACd,MACA,UACA,OACA,qBACA,6BACA,mBACA,aACA,MACA,WACA,WACA,qBACwB;CAExB,MAAM,+BAA+B,gCAAgC;CACrE,MAAM,EAAE,kBAAkB,gBAAgB,kBAAkB;CAC5D,MAAM,iBAAiB,iBAAiB,IAAI;CAE5C,MAAM,aAA0C,cAAc;EAC1D,OAAO,6BAA6B,cAAc,cAAc;CACpE,GAAG,CAAC,gBAAgB,6BAA6B,aAAa,CAAC;CAE/D,MAAM,yBAAyB,aAAa,WAA6B;EACrE,IAAI,UACA;EACJ,IAAI,qBAAqB;GACrB,MAAM,YAAY,SAAS,YAAY,MAAM,IAAI;GACjD,sBAAsB;IAClB;IACA;GACJ,CAAC;EACL;CACJ,GAAG;EAAC;EAAU;EAAqB;CAAW,CAAC;CAE/C,MAAM,6BAA6B,aAAa,aAA0B;EACtE,IAAI,UACA;EACJ,IAAI,6BAEA,4BAA4B;GACxB,YAFe,WAAW,SAAS,KAAI,MAAK,YAAY,CAAC,CAAC,IAAI;GAG9D;EACJ,CAAC;CAET,GAAG;EAAC;EAAU;EAAqB;CAAW,CAAC;CAE/C,MAAM,4BAA4B,mBAAmB;EACjD;EACA,MAAM;EACN;EACA;EACA;EACA;CACJ,CACA;CAEmB,aAAa,MAAwB;EACpD,EAAE,gBAAgB;EAClB,IAAI,aACA,2BAA2B,CAAC,CAAC;OAE7B,uBAAuB,IAAI;CAEnC,GAAG,CAAC,mBAAmB,CAAC;CAExB,IAAI;CAEJ,MAAM,qBAAqB;EACvB,IAAI,UACA;EACJ,0BAA0B,KAAK;CACnC;CAEA,IAAI,MAAM,QAAQ,KAAK,GACnB,QAAQ,oBAAC,OAAD;EAAK,WAAW;YACnB,MAAM,KAAK,KAAK,UAAU;GACvB,OAAO,oBAAC,kBAAD;IAEH,SAAS;IACT,WAAW;IACD;IACS;IACb;IACK;IACQ;GAAmB,GAPjC,qBAAqB,OAOY;EAC9C,CAAC;CACA,CAAA;MACF,IAAI,OAAO,qBAAqB,OAAO,kBAAkB,GAC5D,QAAQ,oBAAC,kBAAD;EACJ,WAAW;EACX,SAAS;EACC;EACS;EACb;EACK;EACQ;CAAmB,CAAA;CAG9C,OAAO,qBAAC,OAAD;EAAK,WAAW,IAAI,uBACvB,gCACA,0EACA,6FACA,SACJ;YALO,CAOF,OACA,CAAC,SAAS,oBAAC,OAAD;GAAK,WAAU;aACtB,qBAAC,QAAD;IAAkB;IACd,SAAS;cADb,CAC2B,SACjB,IACF;;EACP,CAAA,CAEJ;;AACT"}
1
+ {"version":3,"file":"ReferenceWidget.js","names":[],"sources":["../../src/components/ReferenceWidget.tsx"],"sourcesContent":["import { useEntitySelectionDialog } from \"../hooks/useSelectionDialog\";\n\nimport React, { useCallback, useMemo } from \"react\";\n\nimport { Entity, EntityReference, FilterValues } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../types/components/PropertyPreviewProps\";\nimport { ReferencePreview } from \"../preview\";\nimport { Button, cls } from \"@rebasepro/ui\";\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../hooks/useReferencePaths\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\nimport { rowOfEntity } from \"@rebasepro/app\";\n\nexport type ReferenceWidgetProps<M extends Record<string, unknown>> = {\n name?: string,\n multiselect?: boolean,\n value: EntityReference | EntityReference[] | null,\n /** The reference picked, and its row as the server sends it; `null` when cleared. */\n onReferenceSelected?: (params: {\n reference: EntityReference | null,\n row: Record<string, unknown> | null\n }) => void,\n /** The references picked, and their rows as the server sends them. */\n onMultipleReferenceSelected?: (params: {\n references: EntityReference[] | null,\n rows: Record<string, unknown>[] | null\n }) => void,\n path: string,\n disabled?: boolean,\n previewProperties?: string[];\n /**\n * Allow selection of entities that pass the given filter only.\n */\n fixedFilter?: FilterValues<string>;\n size: PreviewSize;\n className?: string;\n includeId?: boolean;\n includeEntityLink?: boolean;\n};\n\n/**\n * This field allows selecting reference/s.\n */\nexport function ReferenceWidget<M extends Record<string, unknown>>({\n name,\n multiselect = false,\n path,\n disabled,\n value,\n onReferenceSelected,\n onMultipleReferenceSelected,\n previewProperties,\n fixedFilter,\n size,\n className,\n includeId,\n includeEntityLink\n}: ReferenceWidgetProps<M>) {\n\n const collectionRegistryController = useCollectionRegistryController();\n const { toCollectionPath, referenceTo } = useReferencePaths();\n const collectionPath = toCollectionPath(path);\n\n const collection: AdminCollection | undefined = useMemo(() => {\n return collectionRegistryController.getCollection(collectionPath);\n }, [collectionPath, collectionRegistryController.getCollection]);\n\n const onSingleEntitySelected = useCallback((entity: Entity<M> | null) => {\n if (disabled)\n return;\n if (onReferenceSelected) {\n const reference = entity ? referenceTo(entity) : null;\n onReferenceSelected?.({\n reference,\n row: entity ? rowOfEntity(entity, collection) : null\n });\n }\n }, [disabled, onReferenceSelected, referenceTo, collection]);\n\n const onMultipleEntitiesSelected = useCallback((entities: Entity<M>[]) => {\n if (disabled)\n return;\n if (onMultipleReferenceSelected) {\n const references = entities ? entities.map(e => referenceTo(e)) : null;\n onMultipleReferenceSelected({\n references,\n rows: entities ? entities.map(e => rowOfEntity(e, collection)) : null\n });\n }\n }, [disabled, onMultipleReferenceSelected, referenceTo, collection]);\n\n const referenceDialogController = useEntitySelectionDialog({\n multiselect,\n path: collectionPath,\n collection,\n onSingleEntitySelected,\n onMultipleEntitiesSelected,\n fixedFilter\n }\n );\n\n const clearValue = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n if (multiselect) {\n onMultipleEntitiesSelected([]);\n } else {\n onSingleEntitySelected(null);\n }\n }, [onReferenceSelected]);\n\n let child: React.ReactNode;\n\n const onEntryClick = () => {\n if (disabled)\n return;\n referenceDialogController.open();\n };\n\n if (Array.isArray(value)) {\n child = <div className={\"flex flex-col gap-4\"}>\n {value.map((ref, index) => {\n return <ReferencePreview\n key={`reference_preview_${index}`}\n onClick={onEntryClick}\n reference={ref}\n disabled={disabled}\n previewProperties={previewProperties}\n size={size}\n includeId={includeId}\n includeEntityLink={includeEntityLink}/>\n })}\n </div>\n } else if (value?.isEntityReference && value?.isEntityReference()) {\n child = <ReferencePreview\n reference={value}\n onClick={onEntryClick}\n disabled={disabled}\n previewProperties={previewProperties}\n size={size}\n includeId={includeId}\n includeEntityLink={includeEntityLink}/>\n\n }\n return <div className={cls(\"text-sm font-medium\",\n \"min-w-80 flex flex-col gap-4\",\n \"relative transition-colors duration-200 ease-in rounded-xs font-medium\",\n \"dark:text-white/50 text-text-primary/50 dark:text-text-primary-dark/50 dark:text-white/50\",\n className\n )}>\n\n {child}\n {!value && <div className=\"justify-center text-left\">\n <Button disabled={disabled}\n onClick={onEntryClick}>\n Edit {name}\n </Button>\n </div>}\n\n </div>;\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,SAAgB,gBAAmD,EAC/D,MACA,c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ACD;IACS;IACb;IACK;IACQ;GAAmB,GAPjC,qBAAqB,OAOY;EAC9C,CAAC;CACA,CAAA;MACF,IAAI,OAAO,qBAAqB,OAAO,kBAAkB,GAC5D,QAAQ,oBAAC,kBAAD;EACJ,WAAW;EACX,SAAS;EACC;EACS;EACb;EACK;EACQ;CAAmB,CAAA;CAG9C,OAAO,qBAAC,OAAD;EAAK,WAAW,IAAI,uBACvB,gCACA,0EACA,6FACA,SACJ;YALO,CAOF,OACA,CAAC,SAAS,oBAAC,OAAD;GAAK,WAAU;aACtB,qBAAC,QAAD;IAAkB;IACd,SAAS;cADb,CAC2B,SACjB,IACF;;EACP,CAAA,CAEJ;;AACT"}
@@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
7
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
8
  import { ArrowRightToLineIcon, CheckIcon, ChevronDownIcon, Chip, CircularProgress, IconButton, PlusIcon, PopoverPrimitive, SearchIcon, Separator, Tooltip, XIcon, cls, defaultBorderMixin, fieldBackgroundDisabledMixin, fieldBackgroundHoverMixin, fieldBackgroundInvisibleMixin, fieldBackgroundMixin, focusedDisabled, iconSize, usePortalContainer } from "@rebasepro/ui";
9
9
  import { normalizeToEntityRelation } from "@rebasepro/common";
10
- import { getTitlePropertyKey, useData, usePermissions, useRelationSelector, useTranslation } from "@rebasepro/app";
10
+ import { entityOfRow, getTitlePropertyKey, useData, usePermissions, useRelationSelector, useTranslation } from "@rebasepro/app";
11
11
  import { EntityRelation, getCollectionDataPath } from "@rebasepro/types";
12
12
  import { Command } from "cmdk";
13
13
  //#region src/components/RelationSelector.tsx
@@ -328,8 +328,8 @@ var RelationSelector = React$1.forwardRef(({ value, size = "medium", onValueChan
328
328
  updateUrl: false,
329
329
  closeOnSave: true,
330
330
  defaultValues,
331
- onUpdate: ({ entity }) => {
332
- if (!entity) return;
331
+ onSaved: ({ row, id }) => {
332
+ const entity = entityOfRow(row, id, dataPath, collection);
333
333
  const item = entityToRelationItemRef.current(entity, new EntityRelation(entity.id, dataPath));
334
334
  const current = selectedItemsRef.current;
335
335
  const newSelected = multiple ? [...current.filter((i) => String(i.id) !== String(item.id)), item] : [item];
@@ -452,7 +452,7 @@ var RelationSelector = React$1.forwardRef(({ value, size = "medium", onValueChan
452
452
  const entity = selectedItems[0].data;
453
453
  setPopoverOpen(false);
454
454
  sidePanelController.open({
455
- entityId: entity.id,
455
+ id: entity.id,
456
456
  path: entity.path,
457
457
  collection,
458
458
  updateUrl: true
@@ -1 +1 @@
1
- {"version":3,"file":"RelationSelector.js","names":[],"sources":["../../src/components/RelationSelector.tsx"],"sourcesContent":["\nimport {\n ArrowRightToLineIcon,\n CheckIcon,\n ChevronDownIcon,\n Chip,\n CircularProgress,\n cls,\n defaultBorderMixin,\n fieldBackgroundDisabledMixin,\n fieldBackgroundHoverMixin,\n fieldBackgroundInvisibleMixin,\n fieldBackgroundMixin,\n focusedDisabled,\n IconButton,\n iconSize,\n PlusIcon,\n PopoverPrimitive,\n SearchIcon,\n Separator,\n Tooltip,\n usePortalContainer,\n XIcon\n} from \"@rebasepro/ui\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Command as CommandPrimitive } from \"cmdk\";\nimport { Entity, EntityRelation, FilterValues, Relation, getCollectionDataPath } from \"@rebasepro/types\";\nimport { EntityPreviewBindingData } from \"./EntityPreviewBinding\";\nimport { PickerTrigger } from \"./PickerTrigger\";\nimport { getTitlePropertyKey, useData, usePermissions, useRelationSelector, useTranslation } from \"@rebasepro/app\";\nimport { useSidePanel } from \"../hooks/useSidePanel\";\nimport { normalizeToEntityRelation } from \"@rebasepro/common\";\nimport { findEntitiesByIds } from \"../util/find_entities_by_ids\";\n\n/** Whether an authored relation yields many rows. Derived from its kind. */\nfunction relationCardinality(relation: { kind?: string; cardinality?: string } | undefined): \"one\" | \"many\" | undefined {\n if (!relation) return undefined;\n if (relation.kind === \"via\") return relation.cardinality as \"one\" | \"many\" | undefined;\n if (relation.kind === \"hasMany\" || relation.kind === \"manyToMany\") return \"many\";\n if (relation.kind === \"belongsTo\" || relation.kind === \"hasOne\") return \"one\";\n return relation.cardinality as \"one\" | \"many\" | undefined;\n}\n\n\nexport interface RelationItem {\n id: string | number;\n label: string;\n description?: string;\n data?: Entity;\n relation: EntityRelation;\n}\n\nexport interface RelationSelectorProps {\n className?: string;\n name?: string;\n id?: string;\n value?: EntityRelation | EntityRelation[] | null;\n /** Callback returning selected EntityRelation(s) */\n\n onValueChange?: (updatedValue: EntityRelation | EntityRelation[] | undefined) => void;\n placeholder?: React.ReactNode;\n /**\n * `large` is the form's size and is on the shared 28/32/40/48 control\n * scale, so a relation picker lines up with the text field beside it.\n *\n * `small` and `medium` predate that scale (42 and 56) and are kept as they\n * are because the filter row is built around them. A table cell passes\n * `triggerContent` instead, and has no size of its own.\n */\n size?: \"small\" | \"medium\" | \"large\";\n useChips?: boolean;\n disabled?: boolean;\n invisible?: boolean;\n\n relation: Relation;\n /**\n * Whether the selector picks many rows or one.\n *\n * Defaults to what the relation implies — a `hasMany` or `manyToMany`\n * picks many — which is right wherever the selector *edits* the relation,\n * because there the cardinality is the shape of the stored value.\n *\n * A filter is the case where it is not. `tags == <one tag>` asks a single\n * question about a to-many link, and the operator is what decides how many\n * values it takes. Deriving multiplicity from the relation there meant a\n * to-many relation could only ever emit a list, so the filter field had to\n * hide every single-value operator to avoid handing `==` an array.\n */\n multiple?: boolean;\n fixedFilter?: FilterValues<string>;\n pageSize?: number;\n emptyPlaceholder?: string;\n searchPlaceholder?: string;\n /** Shown in the open list when a search matched nothing. */\n noResultsText?: string;\n /**\n * Shown on the closed trigger when nothing is selected. Says only that the\n * field is empty — see the note by `resolvedPlaceholder` for why it cannot\n * say whether there is anything to pick.\n */\n emptyText?: string;\n /**\n * Shown in the open list when the target collection turned out to hold no\n * rows at all, as opposed to a search simply not matching. Defaults to a\n * sentence naming the target collection.\n */\n emptyCollectionText?: string;\n loadingText?: string;\n /**\n * Whether the list is open, for a caller that opens it from outside the\n * trigger — a table cell's opener. Every open and close the selector\n * makes itself is reported through `onOpenChange`, controlled or not.\n */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Replaces everything the trigger draws — the value, the box, its padding\n * and the chevron — with this node. For a caller that frames the picker\n * itself: a table cell passes the preview it shows at rest, so the cell\n * looks the same whether the picker is mounted, closed or open.\n */\n triggerContent?: React.ReactNode;\n /**\n * Positions the list against this element instead of the trigger. A\n * table cell passes itself: the trigger inside it can be taller than the\n * cell that clips it, and the list belongs under what can be seen.\n */\n anchorRef?: React.RefObject<HTMLElement | null>;\n /**\n * Whether the open list offers to create a row in the target collection.\n * Defaults to `true`. The offer is shown only when the user could actually\n * insert into that collection — the same permission check the selection\n * dialog's \"Add\" button makes — so turning this off is for the cases where\n * creating is possible but not wanted, like a filter.\n */\n allowCreate?: boolean;\n}\n\nexport const RelationSelector = React.forwardRef<\n HTMLElement,\n RelationSelectorProps\n>(\n (\n {\n value,\n size = \"medium\",\n onValueChange,\n invisible,\n disabled,\n placeholder,\n useChips = true,\n className,\n relation,\n multiple: multipleOverride,\n fixedFilter,\n pageSize,\n emptyPlaceholder,\n searchPlaceholder = \"Search...\",\n noResultsText = \"No matches.\",\n emptyText = \"Select…\",\n emptyCollectionText,\n loadingText = \"Loading...\",\n allowCreate = true,\n open: openProp,\n onOpenChange,\n triggerContent,\n anchorRef\n },\n ref\n ) => {\n\n const collection = relation.target();\n const dataPath = getCollectionDataPath(collection);\n const dataClient = useData();\n const sidePanelController = useSidePanel();\n const { canCreate } = usePermissions();\n const { t } = useTranslation();\n const contextPortalContainer = usePortalContainer();\n const multiple = multipleOverride ?? relationCardinality(relation) === \"many\";\n\n const [isPopoverOpen, setIsPopoverOpenState] = useState(false);\n const isPopoverOpenRef = useRef(false);\n // The list is only worth fetching once the picker has been opened. A\n // table cell mounts one of these per row, and the selected value is\n // resolved by its own effect below, not from the list. Latches on the\n // first open so a closed popover keeps its results.\n const [listRequested, setListRequested] = useState(false);\n const [selectedItems, setSelectedItems] = useState<RelationItem[]>([]);\n const [isLoadingSelectedItems, setIsLoadingSelectedItems] = useState(false);\n const [searchString, setSearchString] = useState<string>(\"\");\n\n // Track IDs that were set via local user interaction (onItemClick / handleClear / handleRemoveItem).\n // When an incoming value change matches these IDs exactly, we skip async re-resolution.\n const localSelectionIdsRef = useRef<string | null>(null);\n // Entity of selected IDs captured when the popover opens.\n // Used to sort the dropdown list so selected items appear at the top.\n // Stays stable for the entire popover session so items don't jump around.\n const pinnedIdsRef = useRef<Set<string> | null>(null);\n\n const selectedItemsForPinRef = useRef<RelationItem[]>([]);\n selectedItemsForPinRef.current = selectedItems;\n const onOpenChangeRef = useRef(onOpenChange);\n onOpenChangeRef.current = onOpenChange;\n\n // Every open and close goes through here. Opening pins the current\n // selection to the top of the list for as long as it stays open, and\n // is what first requests the list at all.\n const setPopoverOpen = useCallback((next: boolean, notify = true) => {\n if (next) {\n // From the value as well as the resolved items: a picker a\n // table cell mounts already open has not resolved them yet.\n pinnedIdsRef.current = new Set([\n ...selectedItemsForPinRef.current.map(i => String(i.id)),\n ...relationsArrayRef.current.map(rel =>\n String(typeof rel === \"string\" || typeof rel === \"number\" ? rel : rel.id))\n ]);\n setListRequested(true);\n } else {\n pinnedIdsRef.current = null;\n }\n const changed = isPopoverOpenRef.current !== next;\n isPopoverOpenRef.current = next;\n setIsPopoverOpenState(next);\n if (changed && notify) onOpenChangeRef.current?.(next);\n }, []);\n\n useEffect(() => {\n if (openProp === undefined || openProp === isPopoverOpenRef.current) return;\n if (openProp && disabled) {\n onOpenChangeRef.current?.(false);\n return;\n }\n setPopoverOpen(openProp, false);\n }, [openProp, disabled, setPopoverOpen]);\n\n const {\n items: availableItems,\n isLoading,\n hasMore,\n search,\n loadMore,\n entityToRelationItem\n } = useRelationSelector({\n path: dataPath,\n collection,\n fixedFilter,\n pageSize,\n enabled: listRequested\n });\n\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const sentinelRef = useRef<HTMLDivElement>(null);\n const observerRef = useRef<IntersectionObserver | null>(null);\n const localTriggerRef = useRef<HTMLElement | null>(null);\n\n const handleButtonRef = useCallback((node: HTMLElement | null) => {\n localTriggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [ref]);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const searchInputRef = useRef<HTMLInputElement | null>(null);\n\n // Keep stable refs for dependencies used in the value-resolution effect\n // so the effect only re-fires when the actual `value` identity changes.\n const dataClientRef = useRef(dataClient);\n dataClientRef.current = dataClient;\n const entityToRelationItemRef = useRef(entityToRelationItem);\n entityToRelationItemRef.current = entityToRelationItem;\n const collectionSlugRef = useRef(collection.slug);\n collectionSlugRef.current = collection.slug;\n const collectionRef = useRef(collection);\n collectionRef.current = collection;\n\n // Stable ref to track which IDs we've already resolved\n const resolvedIdsRef = useRef<string>(\"\");\n // Track whether we have resolved items (used for skip guard without adding to deps)\n const hasResolvedItemsRef = useRef(false);\n\n const selectedItemsRef = useRef(selectedItems);\n selectedItemsRef.current = selectedItems;\n\n // Normalize incoming values — plain { __type: \"relation\" } objects\n // from the server are converted to proper EntityRelation instances.\n const rawArray = !value ? [] : Array.isArray(value) ? value : [value];\n const relationsArray = rawArray.map(rel => {\n if (typeof rel === \"string\" || typeof rel === \"number\") return rel;\n return normalizeToEntityRelation(rel) ?? rel;\n });\n\n // Build a fingerprint of the incoming value's IDs\n const incomingIds = relationsArray\n .map(rel => {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n return String(isPrimitive ? rel : (rel as EntityRelation).id);\n })\n .sort()\n .join(\",\");\n\n // CheckIcon if every relation already has embedded data\n const allHaveData = relationsArray.length > 0 && relationsArray.every(rel => {\n if (typeof rel === \"string\" || typeof rel === \"number\") return false;\n return !!(rel as EntityRelation)?.data;\n });\n\n const relationsArrayRef = useRef(relationsArray);\n relationsArrayRef.current = relationsArray;\n\n useEffect(() => {\n let active = true;\n const currentRelationsArray = relationsArrayRef.current;\n\n // If the IDs haven't changed and we already resolved them, skip entirely\n if (incomingIds === resolvedIdsRef.current && (allHaveData || hasResolvedItemsRef.current)) {\n return;\n }\n\n // FAST PATH: If the incoming IDs match what we just set locally via user interaction,\n // our selectedItems already have the correct data — no re-resolution needed.\n //\n // The fingerprint answers for one echo only, and is dropped on the\n // first incoming value whether it matches or not. Kept, it also\n // matched a *later* return to the same ids — pick A, discard to B,\n // undo back to A — and the chip went on showing B.\n const localSelectionIds = localSelectionIdsRef.current;\n localSelectionIdsRef.current = null;\n if (localSelectionIds !== null && incomingIds === localSelectionIds) {\n resolvedIdsRef.current = incomingIds;\n hasResolvedItemsRef.current = true;\n // Do NOT call setSelectedItems or setIsLoadingSelectedItems — they are already correct.\n return;\n }\n\n const currentSelected = selectedItemsRef.current;\n const currentSelectedMap = new Map(currentSelected.map(item => [String(item.id), item]));\n\n let allCovered = true;\n const newResolvedItems: RelationItem[] = [];\n const toRelationItem = entityToRelationItemRef.current;\n const slug = collectionSlugRef.current;\n\n for (const rel of currentRelationsArray) {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = String(isPrimitive ? rel : (rel as EntityRelation).id);\n const hasEmbeddedData = !isPrimitive && !!(rel as EntityRelation).data;\n\n if (hasEmbeddedData) {\n const r = rel as EntityRelation;\n // admin wire format embeds relation data as { id, path, values }\n newResolvedItems.push(toRelationItem(r.data as unknown as Entity, r));\n } else if (currentSelectedMap.has(relId)) {\n // We already have it in currentSelected\n const existingItem = currentSelectedMap.get(relId)!;\n newResolvedItems.push(existingItem);\n } else {\n allCovered = false;\n break;\n }\n }\n\n // FAST PATH: We have all necessary data embedded or in local cache\n if (allCovered) {\n setSelectedItems(newResolvedItems);\n hasResolvedItemsRef.current = true;\n resolvedIdsRef.current = incomingIds;\n setIsLoadingSelectedItems(false);\n return;\n }\n\n // SLOW PATH: fetch missing data — but don't show loading if popover is open\n // (user is actively interacting; showing a spinner is disruptive)\n if (!isPopoverOpenRef.current) {\n setIsLoadingSelectedItems(true);\n }\n const client = dataClientRef.current;\n const target = collectionRef.current;\n\n // The ids nothing above resolves, by the path they are read at:\n // one request per path (per 1,000 ids), not one per id.\n const unresolved = new Map<string, (string | number)[]>();\n for (const rel of currentRelationsArray) {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = isPrimitive ? rel : (rel as EntityRelation).id;\n if (!isPrimitive && (rel as EntityRelation).data) continue;\n if (currentSelectedMap.has(String(relId))) continue;\n const path = isPrimitive ? slug : (rel as EntityRelation).path;\n unresolved.set(path, [...(unresolved.get(path) ?? []), relId]);\n }\n\n Promise.all(\n [...unresolved].map(async ([path, ids]): Promise<[string, Map<string, Entity>]> => {\n try {\n return [path, await findEntitiesByIds(client.collection(path), target, ids)];\n } catch (e) {\n console.warn(\"RelationSelector: could not fetch the entities for relations\", path, ids, e);\n return [path, new Map()];\n }\n })\n ).then(read => {\n const readByPath = new Map(read);\n return currentRelationsArray.map((rel) => {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = isPrimitive ? rel : (rel as EntityRelation).id;\n const path = isPrimitive ? slug : (rel as EntityRelation).path;\n const relation = isPrimitive ? new EntityRelation(relId, path) : rel as EntityRelation;\n\n if (!isPrimitive && (rel as EntityRelation).data) {\n // admin wire format embeds relation data as { id, path, values }\n return toRelationItem((rel as EntityRelation).data as unknown as Entity, relation);\n }\n if (currentSelectedMap.has(String(relId))) {\n return currentSelectedMap.get(String(relId))!;\n }\n const entity = readByPath.get(path)?.get(String(relId));\n if (entity) return toRelationItem(entity, relation);\n return { id: relId,\nlabel: String(relId),\nrelation } as RelationItem;\n });\n }).then(resolved => {\n if (active) {\n setSelectedItems(resolved);\n setIsLoadingSelectedItems(false);\n hasResolvedItemsRef.current = true;\n resolvedIdsRef.current = incomingIds;\n }\n });\n\n return () => {\n active = false;\n };\n }, [incomingIds, allHaveData]);\n\n const sentinelCallbackRef = useCallback((node: HTMLDivElement | null) => {\n if (observerRef.current) {\n observerRef.current.disconnect();\n observerRef.current = null;\n }\n if (sentinelRef.current !== node) {\n (sentinelRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n if (!node || !hasMore || isLoading || !loadMore) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[0];\n if (entry.isIntersecting && hasMore && !isLoading) loadMore();\n },\n {\n root: scrollContainerRef.current,\n rootMargin: \"20px\",\n threshold: 0\n }\n );\n observer.observe(node);\n observerRef.current = observer;\n }, [hasMore, isLoading, loadMore]);\n\n useEffect(() => () => {\n if (observerRef.current) observerRef.current.disconnect();\n }, []);\n\n // Enhanced scroll event listener specifically for dialog contexts\n useEffect(() => {\n const scrollContainer = scrollContainerRef.current;\n if (!scrollContainer || !hasMore || isLoading || !isPopoverOpen) return;\n\n const handleScroll = () => {\n const { scrollTop, scrollHeight, clientHeight } = scrollContainer;\n const isNearBottom = scrollTop + clientHeight >= scrollHeight - 100;\n\n if (isNearBottom && hasMore && !isLoading) {\n loadMore();\n }\n };\n\n // Add scroll listener directly to the container\n scrollContainer.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n return () => {\n scrollContainer.removeEventListener(\"scroll\", handleScroll);\n };\n }, [hasMore, isLoading, loadMore, isPopoverOpen]);\n\n const handleSearchChange = useCallback((newSearchString: string) => {\n setSearchString(newSearchString);\n search(newSearchString);\n }, [search]);\n\n const emitValueChange = useCallback((selected: RelationItem[]) => {\n if (multiple) onValueChange?.(selected.length ? selected.map(i => i.relation) : undefined);\n else onValueChange?.(selected[0]?.relation);\n }, [onValueChange, multiple]);\n\n // The picker can hand its selection over long after the render that\n // built the callback — a row created in the side panel arrives whenever\n // the person saves it — so the emitter is read from a ref rather than\n // captured.\n const emitValueChangeRef = useRef(emitValueChange);\n emitValueChangeRef.current = emitValueChange;\n\n // Helper: compute the \"IDs fingerprint\" for a set of RelationItems\n // so we can mark it in localSelectionIdsRef and skip re-resolution.\n const computeSelectionFingerprint = useCallback((items: RelationItem[]): string => {\n return items.map(i => String(i.id)).sort().join(\",\");\n }, []);\n\n const onItemClick = useCallback((item: RelationItem) => {\n let newSelected: RelationItem[];\n if (multiple) {\n const isSelected = selectedItems.some(v => String(v.id) === String(item.id));\n newSelected = isSelected\n ? selectedItems.filter(v => String(v.id) !== String(item.id))\n : [...selectedItems, item];\n } else {\n newSelected = [item];\n setPopoverOpen(false);\n }\n setSelectedItems(newSelected);\n // Mark this fingerprint so the resolution effect skips async work\n // when the parent echoes the same IDs back via props.\n localSelectionIdsRef.current = computeSelectionFingerprint(newSelected);\n emitValueChange(newSelected);\n }, [multiple, selectedItems, emitValueChange, computeSelectionFingerprint, setPopoverOpen]);\n\n const handleClear = useCallback(() => {\n setSelectedItems([]);\n localSelectionIdsRef.current = \"\";\n onValueChange?.(undefined);\n }, [onValueChange]);\n\n const handleRemoveItem = useCallback((itemToRemove: RelationItem) => {\n const newSelected = selectedItems.filter(v => String(v.id) !== String(itemToRemove.id));\n setSelectedItems(newSelected);\n localSelectionIdsRef.current = computeSelectionFingerprint(newSelected);\n emitValueChange(newSelected);\n }, [selectedItems, emitValueChange, computeSelectionFingerprint]);\n\n const handleRootOpenChange = useCallback((next: boolean) => {\n if (disabled) return;\n // We control open manually; only allow opening attempts from Radix (e.g. trigger press)\n if (next) setPopoverOpen(true);\n // Ignore close attempts here; outside click/Escape handled manually; single select closes explicitly on selection.\n }, [disabled, setPopoverOpen]);\n\n // Outside click + Escape handling (simple and reliable)\n useEffect(() => {\n if (!isPopoverOpen) return;\n\n function handlePointerDown(ev: MouseEvent) {\n const target = ev.target as Node;\n const triggerEl = localTriggerRef.current;\n const contentEl = contentRef.current;\n if (triggerEl?.contains(target)) return;\n if (contentEl?.contains(target)) return;\n // Outside\n setPopoverOpen(false);\n }\n\n // A layer of its own, so capture phase — and it claims the Escape\n // it acts on, so the record view underneath leaves the record open.\n function handleKey(ev: KeyboardEvent) {\n if (ev.key !== \"Escape\") return;\n ev.preventDefault();\n setPopoverOpen(false);\n }\n\n document.addEventListener(\"mousedown\", handlePointerDown, true);\n document.addEventListener(\"keydown\", handleKey, true);\n return () => {\n document.removeEventListener(\"mousedown\", handlePointerDown, true);\n document.removeEventListener(\"keydown\", handleKey, true);\n };\n }, [isPopoverOpen, setPopoverOpen]);\n\n const closePopover = useCallback(() => setPopoverOpen(false), [setPopoverOpen]);\n\n const toggleOpen = useCallback(() => {\n if (disabled) return;\n setPopoverOpen(!isPopoverOpenRef.current);\n }, [disabled, setPopoverOpen]);\n\n // Pointing at a row that does not exist yet.\n //\n // Until now the only way out of that was to abandon the form, go to the\n // other collection, create the row, come back and start again — and on\n // a new record that meant losing everything typed so far. The side\n // panel already stacks (the selection dialog creates from inside itself\n // this way), so the picker can open a create form over the form it\n // belongs to and select what comes back.\n const canCreateTarget = allowCreate && canCreate(collection, dataPath);\n\n // A search that matched nothing is the name the person was looking for,\n // so it seeds the new row. Only when the title lands on a plain string\n // property: putting free text into an enum, a relation or a computed\n // property would be worse than not prefilling at all.\n const buildDefaultValues = useCallback((searchText: string): Record<string, unknown> | undefined => {\n const trimmed = searchText.trim();\n if (!trimmed) return undefined;\n const titleKey = getTitlePropertyKey(collection);\n if (!titleKey || titleKey.includes(\".\")) return undefined;\n const titleProperty = collection.properties?.[titleKey];\n // A property builder is a function, and it decides its own value.\n if (!titleProperty || typeof titleProperty === \"function\") return undefined;\n if (titleProperty.type !== \"string\" || titleProperty.enum) return undefined;\n return { [titleKey]: trimmed };\n }, [collection]);\n\n const handleCreateNew = useCallback(() => {\n const defaultValues = buildDefaultValues(searchString);\n closePopover();\n sidePanelController.open({\n path: dataPath,\n collection,\n // No URL. This panel is a detour inside the form you are\n // filling in, not somewhere you navigated to, and its address\n // would restore nothing anyway — a record that does not exist\n // yet has none.\n //\n // Pushing one made closing it a *pathname* change, which is\n // exactly what the unsaved-changes blocker watches\n // (`useUnsavedChangesDialog`). So saving the new row raced the\n // panel clearing its own dirty flag, and often enough lost:\n // \"There are unsaved changes\" over a record that had just been\n // saved, with the URL stranded on the target collection. Worst\n // of all in the case this feature exists for — the outer form\n // has content in it, which is the whole reason not to leave.\n updateUrl: false,\n // Saving is the whole point of the detour; the panel goes away\n // and the picker is left holding the row it made.\n closeOnSave: true,\n defaultValues,\n onUpdate: ({ entity }) => {\n if (!entity) return;\n const item = entityToRelationItemRef.current(entity, new EntityRelation(entity.id, dataPath));\n const current = selectedItemsRef.current;\n const newSelected = multiple\n ? [...current.filter(i => String(i.id) !== String(item.id)), item]\n : [item];\n setSelectedItems(newSelected);\n // Same bookkeeping `onItemClick` does: mark the fingerprint\n // so the resolution effect does not re-fetch the row we\n // already hold when the form echoes the value back.\n localSelectionIdsRef.current = newSelected.map(i => String(i.id)).sort().join(\",\");\n emitValueChangeRef.current(newSelected);\n }\n });\n }, [buildDefaultValues, searchString, closePopover, sidePanelController, dataPath, collection, multiple]);\n\n // Text, not `EmptyValue`. That component draws a small grey rounded bar\n // with no text in it, which is the same shape the `Skeleton` component\n // uses while data is in flight — so a relation you simply had not filled\n // in was indistinguishable from one that was still loading, and an empty\n // Author or Tags field read as permanently stuck. It also left the trigger\n // button with no accessible name, since the bar contains no text at all.\n //\n // This says \"not filled in\" rather than \"nothing to choose from\": which of\n // those it is cannot be known here. The list is deliberately not fetched\n // until the picker is first opened (`enabled: listRequested`, guarded by\n // relation_cell_picker_gating.test.tsx, because a table renders one of\n // these per row), so before that `availableItems` is empty because nobody\n // asked, not because the target collection is. The genuine \"nothing to\n // pick yet\" state is reported inside the popover below, where the fetch\n // has actually happened.\n const resolvedPlaceholder = placeholder || emptyPlaceholder || emptyText;\n\n // Whatever dialog, side dialog or sheet we are inside offers as its\n // portal host, falling back to `document.body`. This is not cosmetic:\n // those are modal, and a modal locks scrolling everywhere outside its\n // own content — a list portaled to the body opens and then refuses to\n // scroll, because every wheel event over it is cancelled.\n const portalContainer = (contextPortalContainer ?? (typeof document !== \"undefined\" ? document.body : undefined)) ?? undefined;\n\n return (\n <>\n <PopoverPrimitive.Root open={isPopoverOpen} onOpenChange={handleRootOpenChange} modal={false}>\n <PickerTrigger anchorRef={anchorRef}>\n {triggerContent !== undefined\n // Bare: the caller frames it. No box, no padding,\n // no height of its own — the node it passed,\n // exactly where it would be anyway. A `div`, not a\n // `button`: what it wraps can hold buttons of its\n // own (a record card's open button, at tall rows).\n ? <div\n ref={handleButtonRef}\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isPopoverOpen}\n data-relation-selector-trigger\n onClick={toggleOpen}\n // A record's title in the value opens that\n // record, and the list has no business staying\n // open over it.\n onClickCapture={(event) => {\n const target = event.target;\n if (!(target instanceof Element) || !isPopoverOpenRef.current) return;\n const interactive = target.closest(\"a, button, [role=\\\"button\\\"]\");\n if (interactive && interactive !== event.currentTarget) setPopoverOpen(false);\n }}\n onKeyDown={(event) => {\n if (event.key !== \"Enter\" && event.key !== \" \") return;\n event.preventDefault();\n toggleOpen();\n }}\n className={cls(\"w-full select-none text-left text-sm relative flex items-center outline-none\", className)}>\n {triggerContent}\n </div>\n : <button\n ref={handleButtonRef}\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={isPopoverOpen}\n data-relation-selector-trigger\n disabled={disabled}\n onClick={toggleOpen}\n className={cls(\n {\n \"min-h-[42px] py-1 px-2\": size === \"small\",\n \"min-h-[56px] py-2 px-4\": size === \"medium\",\n \"min-h-[48px] py-1 px-4\": size === \"large\"\n },\n // `rounded-lg` like every other field box —\n // `rounded-md` made this the one control in a\n // row with a different corner.\n \"w-full select-none rounded-lg text-sm relative flex items-center\",\n invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,\n disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,\n className\n )}\n >\n <div className=\"flex justify-between items-center w-full\">\n {isLoadingSelectedItems ? (\n <div className=\"flex items-center gap-2\">\n <CircularProgress size=\"smallest\"/>\n <span className=\"text-sm text-text-secondary dark:text-text-secondary-dark\">{loadingText}</span>\n </div>\n ) : selectedItems.length > 0 ? (\n <div\n className=\"flex flex-wrap items-center gap-1.5 text-start flex-1 min-w-0 mr-2\">\n {selectedItems.map((item) => {\n if (!useChips || !multiple) {\n return (\n <div key={String(item.id)}\n className=\"flex flex-row items-center gap-1 truncate\">\n {item.data ? (\n <EntityPreviewBindingData size={\"medium\"}\n entity={item.data}\n includeEntityLink={false}\n includeId={false}\n onSidePanelClick={closePopover}\n />\n ) : (\n <span className=\"text-sm truncate\">{item.label}</span>\n )}\n </div>\n );\n }\n return (\n <Chip\n size={\"small\"}\n key={String(item.id)}\n className={cls(\"flex flex-row items-center gap-1 truncate\")}\n >\n {item.data ? (\n <EntityPreviewBindingData size={\"smallest\"} entity={item.data}\n includeEntityLink={false}\n includeId={false}/>\n ) : (\n <span className=\"text-sm truncate\">{item.label}</span>\n )}\n <XIcon\n size={iconSize.smallest}\n onClick={(event) => {\n event.stopPropagation();\n handleRemoveItem(item);\n }}\n />\n </Chip>\n );\n })}\n </div>\n ) :\n (\n <span className=\"text-sm text-text-secondary dark:text-text-secondary-dark\">\n {resolvedPlaceholder}\n </span>\n )}\n\n <div className=\"flex items-center flex-shrink-0\">\n {!multiple && selectedItems.length === 1 && selectedItems[0]?.data && (\n <Tooltip title={t(\"relation_open_record\", { label: selectedItems[0].label })}>\n <IconButton aria-label={t(\"relation_open_record\", { label: selectedItems[0].label })}\n component={\"div\"}\n size={\"small\"}\n className=\"opacity-60 hover:opacity-100\"\n onClick={(e) => {\n e.stopPropagation();\n e.preventDefault();\n const entity = selectedItems[0].data!;\n setPopoverOpen(false);\n sidePanelController.open({\n entityId: entity.id,\n path: entity.path,\n collection,\n updateUrl: true\n });\n }}>\n <ArrowRightToLineIcon size={iconSize.small}/>\n </IconButton>\n </Tooltip>\n )}\n <ChevronDownIcon\n size={size === \"small\" ? iconSize.small : iconSize.medium}\n className={cls(\"transition\", isPopoverOpen ? \"rotate-180\" : \"\")}\n />\n </div>\n </div>\n\n </button>}\n </PickerTrigger>\n <PopoverPrimitive.Portal container={portalContainer}>\n <PopoverPrimitive.Content\n ref={contentRef}\n data-relation-selector-content\n className={cls(\"z-50 overflow-hidden border bg-surface-card rounded-lg min-w-72\", defaultBorderMixin)}\n align=\"start\"\n sideOffset={8}\n side=\"bottom\"\n avoidCollisions={true}\n collisionPadding={16}\n // Allow default auto focus (we manually refocus anyway)\n onOpenAutoFocus={(_e) => { /* leave default or custom manual focus */\n }}\n onCloseAutoFocus={(e) => {\n e.preventDefault();\n }}\n style={{ width: \"var(--radix-popover-trigger-width)\" }}\n >\n <CommandPrimitive shouldFilter={false}>\n <div className=\"flex flex-row items-center\">\n <div className=\"relative flex-1\">\n <SearchIcon\n className=\"absolute left-3 top-1/2 transform -translate-y-1/2 text-text-secondary dark:text-text-secondary-dark\"\n size={iconSize.smallest}/>\n <CommandPrimitive.Input\n ref={searchInputRef}\n className={cls(\n focusedDisabled,\n \"bg-transparent outline-hidden flex-1 h-full w-full pl-10 pr-4 py-3 text-text-primary dark:text-text-primary-dark placeholder:text-text-secondary dark:placeholder:text-text-secondary-dark\"\n )}\n placeholder={searchPlaceholder}\n value={searchString}\n onValueChange={handleSearchChange}\n />\n </div>\n {isLoading && (\n <div className=\"flex items-center justify-center px-3\">\n <CircularProgress size=\"smallest\"/>\n </div>\n )}\n {selectedItems.length > 0 && (\n <div\n onClick={handleClear}\n className=\"text-sm justify-center cursor-pointer py-3 px-4 text-text-secondary dark:text-text-secondary-dark hover:text-text-primary dark:hover:text-text-primary-dark\"\n >\n Clear\n </div>\n )}\n </div>\n <Separator orientation=\"horizontal\" className=\"my-0\"/>\n <CommandPrimitive.List\n ref={scrollContainerRef}\n style={{\n maxHeight: \"40vh\",\n overflowY: \"auto\"\n }}\n >\n {isLoading && availableItems.length === 0 && (\n <div className=\"flex items-center justify-center py-6\">\n <CircularProgress size=\"small\"/>\n <span\n className=\"ml-2 text-sm text-text-secondary dark:text-text-secondary-dark\">{loadingText}</span>\n </div>\n )}\n {/* Two different nothings, which used to share one\n message (\"No relations found.\") even though the\n fix for each is the opposite: clear the search, or\n go and create the first row. With the fetch done,\n the search string is what tells them apart. */}\n {!isLoading && availableItems.length === 0 && (\n <CommandPrimitive.Empty\n className=\"px-4 py-6 text-center text-text-secondary dark:text-text-secondary-dark\">\n {searchString\n ? noResultsText\n : (emptyCollectionText ?? `No ${collection.name ?? \"entries\"} yet.`)}\n </CommandPrimitive.Empty>\n )}\n <CommandPrimitive.Group>\n {(() => {\n // Sort items so that initially-selected (pinned) items appear first.\n // We use the entity taken when the popover opened so items don't\n // jump around as the user checks/unchecks.\n const pinned = pinnedIdsRef.current;\n const sortedItems = pinned && pinned.size > 0\n ? [...availableItems].sort((a, b) => {\n const aP = pinned.has(String(a.id)) ? 0 : 1;\n const bP = pinned.has(String(b.id)) ? 0 : 1;\n return aP - bP;\n })\n : availableItems;\n return sortedItems;\n })().map((item) => {\n const isSelected = selectedItems.some(v => String(v.id) === String(item.id));\n return (\n <CommandPrimitive.Item\n key={String(item.id)}\n value={String(item.id)}\n onMouseDown={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onSelect={() => onItemClick(item)}\n className={cls(\n \"flex flex-row items-center gap-1.5 m-1 p-1 rounded-xs cursor-pointer ring-offset-transparent\",\n isSelected && \"bg-surface-active\",\n \"aria-selected:outline-hidden aria-selected:bg-surface-active\"\n )}\n >\n {multiple && (<InnerCheckBox checked={isSelected}/>)}\n {item.data ? (\n <div\n className=\"flex flex-row items-center gap-2 min-w-0 w-full\">\n <EntityPreviewBindingData\n size={multiple ? \"smallest\" : \"medium\"}\n entity={item.data}\n includeId={false}\n includeEntityLink={true}\n />\n </div>\n ) : (\n <div>\n <div\n className=\"text-sm font-medium text-text-primary dark:text-text-primary-dark\">{item.label}</div>\n {item.description && (\n <div\n className=\"text-xs text-text-secondary dark:text-text-secondary-dark\">{item.description}</div>\n )}\n </div>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {availableItems.length > 0 && hasMore && (\n <div ref={sentinelCallbackRef} className=\"h-1 w-full\"\n style={{ visibility: \"hidden\" }}/>\n )}\n {isLoading && availableItems.length > 0 && (\n <div className=\"flex items-center justify-center py-4\">\n <CircularProgress size=\"smallest\"/>\n <span\n className=\"ml-2 text-xs text-text-secondary dark:text-text-secondary-dark\">Loading...</span>\n </div>\n )}\n </CommandPrimitive.Group>\n </CommandPrimitive.List>\n {canCreateTarget && <>\n <Separator orientation=\"horizontal\" className=\"my-0\"/>\n {/* Outside the scrolling list on purpose: it\n is most wanted exactly when the list is\n long and nothing in it matched. */}\n <button\n type=\"button\"\n data-relation-selector-create\n onMouseDown={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onClick={handleCreateNew}\n className={cls(\n \"w-full flex flex-row items-center gap-2 px-4 py-3 text-sm text-left\",\n \"text-primary hover:bg-surface-hover\"\n )}>\n <PlusIcon size={iconSize.smallest}/>\n <span className=\"truncate\">\n {searchString.trim()\n ? t(\"add_named\", { name: searchString.trim() })\n : t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </span>\n </button>\n </>}\n </CommandPrimitive>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </>\n );\n }\n);\n\nRelationSelector.displayName = \"RelationSelector\";\n\nfunction InnerCheckBox({ checked }: { checked: boolean }) {\n return (\n <div className={cls(\n \"p-2 w-8 h-8 inline-flex items-center justify-center text-sm font-medium focus:outline-hidden transition-colors ease-in-out duration-150\"\n )}>\n <div\n className={cls(\n \"border-2 relative transition-colors ease-in-out duration-150 w-4 h-4 rounded-xs flex items-center justify-center\",\n checked ? \"bg-primary text-surface-accent-100 dark:text-surface-accent-900 border-transparent\" : \"bg-surface-card border-surface-accent-800 dark:border-surface-accent-500\"\n )}\n >\n {checked && <CheckIcon size={iconSize.smallest} className=\"absolute\"/>}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,SAAS,oBAAoB,UAA2F;CACpH,IAAI,CAAC,UAAU,OAAO,KAAA;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aAEC,WAAW,oBAAC,WAAD;IAAW,MAAM,SAAS;IAAU,WAAU;GAAW,CAAA;EACpE,CAAA;CACJ,CAAA;AAEb"}
1
+ {"version":3,"file":"RelationSelector.js","names":[],"sources":["../../src/components/RelationSelector.tsx"],"sourcesContent":["\nimport {\n ArrowRightToLineIcon,\n CheckIcon,\n ChevronDownIcon,\n Chip,\n CircularProgress,\n cls,\n defaultBorderMixin,\n fieldBackgroundDisabledMixin,\n fieldBackgroundHoverMixin,\n fieldBackgroundInvisibleMixin,\n fieldBackgroundMixin,\n focusedDisabled,\n IconButton,\n iconSize,\n PlusIcon,\n PopoverPrimitive,\n SearchIcon,\n Separator,\n Tooltip,\n usePortalContainer,\n XIcon\n} from \"@rebasepro/ui\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Command as CommandPrimitive } from \"cmdk\";\nimport { Entity, EntityRelation, FilterValues, Relation, getCollectionDataPath } from \"@rebasepro/types\";\nimport { EntityPreviewBindingData } from \"./EntityPreviewBinding\";\nimport { PickerTrigger } from \"./PickerTrigger\";\nimport { getTitlePropertyKey, useData, usePermissions, useRelationSelector, useTranslation } from \"@rebasepro/app\";\nimport { useSidePanel } from \"../hooks/useSidePanel\";\nimport { normalizeToEntityRelation } from \"@rebasepro/common\";\nimport { findEntitiesByIds } from \"../util/find_entities_by_ids\";\nimport { entityOfRow } from \"@rebasepro/app\";\n\n/** Whether an authored relation yields many rows. Derived from its kind. */\nfunction relationCardinality(relation: { kind?: string; cardinality?: string } | undefined): \"one\" | \"many\" | undefined {\n if (!relation) return undefined;\n if (relation.kind === \"via\") return relation.cardinality as \"one\" | \"many\" | undefined;\n if (relation.kind === \"hasMany\" || relation.kind === \"manyToMany\") return \"many\";\n if (relation.kind === \"belongsTo\" || relation.kind === \"hasOne\") return \"one\";\n return relation.cardinality as \"one\" | \"many\" | undefined;\n}\n\n\nexport interface RelationItem {\n id: string | number;\n label: string;\n description?: string;\n data?: Entity;\n relation: EntityRelation;\n}\n\nexport interface RelationSelectorProps {\n className?: string;\n name?: string;\n id?: string;\n value?: EntityRelation | EntityRelation[] | null;\n /** Callback returning selected EntityRelation(s) */\n\n onValueChange?: (updatedValue: EntityRelation | EntityRelation[] | undefined) => void;\n placeholder?: React.ReactNode;\n /**\n * `large` is the form's size and is on the shared 28/32/40/48 control\n * scale, so a relation picker lines up with the text field beside it.\n *\n * `small` and `medium` predate that scale (42 and 56) and are kept as they\n * are because the filter row is built around them. A table cell passes\n * `triggerContent` instead, and has no size of its own.\n */\n size?: \"small\" | \"medium\" | \"large\";\n useChips?: boolean;\n disabled?: boolean;\n invisible?: boolean;\n\n relation: Relation;\n /**\n * Whether the selector picks many rows or one.\n *\n * Defaults to what the relation implies — a `hasMany` or `manyToMany`\n * picks many — which is right wherever the selector *edits* the relation,\n * because there the cardinality is the shape of the stored value.\n *\n * A filter is the case where it is not. `tags == <one tag>` asks a single\n * question about a to-many link, and the operator is what decides how many\n * values it takes. Deriving multiplicity from the relation there meant a\n * to-many relation could only ever emit a list, so the filter field had to\n * hide every single-value operator to avoid handing `==` an array.\n */\n multiple?: boolean;\n fixedFilter?: FilterValues<string>;\n pageSize?: number;\n emptyPlaceholder?: string;\n searchPlaceholder?: string;\n /** Shown in the open list when a search matched nothing. */\n noResultsText?: string;\n /**\n * Shown on the closed trigger when nothing is selected. Says only that the\n * field is empty — see the note by `resolvedPlaceholder` for why it cannot\n * say whether there is anything to pick.\n */\n emptyText?: string;\n /**\n * Shown in the open list when the target collection turned out to hold no\n * rows at all, as opposed to a search simply not matching. Defaults to a\n * sentence naming the target collection.\n */\n emptyCollectionText?: string;\n loadingText?: string;\n /**\n * Whether the list is open, for a caller that opens it from outside the\n * trigger — a table cell's opener. Every open and close the selector\n * makes itself is reported through `onOpenChange`, controlled or not.\n */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Replaces everything the trigger draws — the value, the box, its padding\n * and the chevron — with this node. For a caller that frames the picker\n * itself: a table cell passes the preview it shows at rest, so the cell\n * looks the same whether the picker is mounted, closed or open.\n */\n triggerContent?: React.ReactNode;\n /**\n * Positions the list against this element instead of the trigger. A\n * table cell passes itself: the trigger inside it can be taller than the\n * cell that clips it, and the list belongs under what can be seen.\n */\n anchorRef?: React.RefObject<HTMLElement | null>;\n /**\n * Whether the open list offers to create a row in the target collection.\n * Defaults to `true`. The offer is shown only when the user could actually\n * insert into that collection — the same permission check the selection\n * dialog's \"Add\" button makes — so turning this off is for the cases where\n * creating is possible but not wanted, like a filter.\n */\n allowCreate?: boolean;\n}\n\nexport const RelationSelector = React.forwardRef<\n HTMLElement,\n RelationSelectorProps\n>(\n (\n {\n value,\n size = \"medium\",\n onValueChange,\n invisible,\n disabled,\n placeholder,\n useChips = true,\n className,\n relation,\n multiple: multipleOverride,\n fixedFilter,\n pageSize,\n emptyPlaceholder,\n searchPlaceholder = \"Search...\",\n noResultsText = \"No matches.\",\n emptyText = \"Select…\",\n emptyCollectionText,\n loadingText = \"Loading...\",\n allowCreate = true,\n open: openProp,\n onOpenChange,\n triggerContent,\n anchorRef\n },\n ref\n ) => {\n\n const collection = relation.target();\n const dataPath = getCollectionDataPath(collection);\n const dataClient = useData();\n const sidePanelController = useSidePanel();\n const { canCreate } = usePermissions();\n const { t } = useTranslation();\n const contextPortalContainer = usePortalContainer();\n const multiple = multipleOverride ?? relationCardinality(relation) === \"many\";\n\n const [isPopoverOpen, setIsPopoverOpenState] = useState(false);\n const isPopoverOpenRef = useRef(false);\n // The list is only worth fetching once the picker has been opened. A\n // table cell mounts one of these per row, and the selected value is\n // resolved by its own effect below, not from the list. Latches on the\n // first open so a closed popover keeps its results.\n const [listRequested, setListRequested] = useState(false);\n const [selectedItems, setSelectedItems] = useState<RelationItem[]>([]);\n const [isLoadingSelectedItems, setIsLoadingSelectedItems] = useState(false);\n const [searchString, setSearchString] = useState<string>(\"\");\n\n // Track IDs that were set via local user interaction (onItemClick / handleClear / handleRemoveItem).\n // When an incoming value change matches these IDs exactly, we skip async re-resolution.\n const localSelectionIdsRef = useRef<string | null>(null);\n // Entity of selected IDs captured when the popover opens.\n // Used to sort the dropdown list so selected items appear at the top.\n // Stays stable for the entire popover session so items don't jump around.\n const pinnedIdsRef = useRef<Set<string> | null>(null);\n\n const selectedItemsForPinRef = useRef<RelationItem[]>([]);\n selectedItemsForPinRef.current = selectedItems;\n const onOpenChangeRef = useRef(onOpenChange);\n onOpenChangeRef.current = onOpenChange;\n\n // Every open and close goes through here. Opening pins the current\n // selection to the top of the list for as long as it stays open, and\n // is what first requests the list at all.\n const setPopoverOpen = useCallback((next: boolean, notify = true) => {\n if (next) {\n // From the value as well as the resolved items: a picker a\n // table cell mounts already open has not resolved them yet.\n pinnedIdsRef.current = new Set([\n ...selectedItemsForPinRef.current.map(i => String(i.id)),\n ...relationsArrayRef.current.map(rel =>\n String(typeof rel === \"string\" || typeof rel === \"number\" ? rel : rel.id))\n ]);\n setListRequested(true);\n } else {\n pinnedIdsRef.current = null;\n }\n const changed = isPopoverOpenRef.current !== next;\n isPopoverOpenRef.current = next;\n setIsPopoverOpenState(next);\n if (changed && notify) onOpenChangeRef.current?.(next);\n }, []);\n\n useEffect(() => {\n if (openProp === undefined || openProp === isPopoverOpenRef.current) return;\n if (openProp && disabled) {\n onOpenChangeRef.current?.(false);\n return;\n }\n setPopoverOpen(openProp, false);\n }, [openProp, disabled, setPopoverOpen]);\n\n const {\n items: availableItems,\n isLoading,\n hasMore,\n search,\n loadMore,\n entityToRelationItem\n } = useRelationSelector({\n path: dataPath,\n collection,\n fixedFilter,\n pageSize,\n enabled: listRequested\n });\n\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const sentinelRef = useRef<HTMLDivElement>(null);\n const observerRef = useRef<IntersectionObserver | null>(null);\n const localTriggerRef = useRef<HTMLElement | null>(null);\n\n const handleButtonRef = useCallback((node: HTMLElement | null) => {\n localTriggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [ref]);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const searchInputRef = useRef<HTMLInputElement | null>(null);\n\n // Keep stable refs for dependencies used in the value-resolution effect\n // so the effect only re-fires when the actual `value` identity changes.\n const dataClientRef = useRef(dataClient);\n dataClientRef.current = dataClient;\n const entityToRelationItemRef = useRef(entityToRelationItem);\n entityToRelationItemRef.current = entityToRelationItem;\n const collectionSlugRef = useRef(collection.slug);\n collectionSlugRef.current = collection.slug;\n const collectionRef = useRef(collection);\n collectionRef.current = collection;\n\n // Stable ref to track which IDs we've already resolved\n const resolvedIdsRef = useRef<string>(\"\");\n // Track whether we have resolved items (used for skip guard without adding to deps)\n const hasResolvedItemsRef = useRef(false);\n\n const selectedItemsRef = useRef(selectedItems);\n selectedItemsRef.current = selectedItems;\n\n // Normalize incoming values — plain { __type: \"relation\" } objects\n // from the server are converted to proper EntityRelation instances.\n const rawArray = !value ? [] : Array.isArray(value) ? value : [value];\n const relationsArray = rawArray.map(rel => {\n if (typeof rel === \"string\" || typeof rel === \"number\") return rel;\n return normalizeToEntityRelation(rel) ?? rel;\n });\n\n // Build a fingerprint of the incoming value's IDs\n const incomingIds = relationsArray\n .map(rel => {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n return String(isPrimitive ? rel : (rel as EntityRelation).id);\n })\n .sort()\n .join(\",\");\n\n // CheckIcon if every relation already has embedded data\n const allHaveData = relationsArray.length > 0 && relationsArray.every(rel => {\n if (typeof rel === \"string\" || typeof rel === \"number\") return false;\n return !!(rel as EntityRelation)?.data;\n });\n\n const relationsArrayRef = useRef(relationsArray);\n relationsArrayRef.current = relationsArray;\n\n useEffect(() => {\n let active = true;\n const currentRelationsArray = relationsArrayRef.current;\n\n // If the IDs haven't changed and we already resolved them, skip entirely\n if (incomingIds === resolvedIdsRef.current && (allHaveData || hasResolvedItemsRef.current)) {\n return;\n }\n\n // FAST PATH: If the incoming IDs match what we just set locally via user interaction,\n // our selectedItems already have the correct data — no re-resolution needed.\n //\n // The fingerprint answers for one echo only, and is dropped on the\n // first incoming value whether it matches or not. Kept, it also\n // matched a *later* return to the same ids — pick A, discard to B,\n // undo back to A — and the chip went on showing B.\n const localSelectionIds = localSelectionIdsRef.current;\n localSelectionIdsRef.current = null;\n if (localSelectionIds !== null && incomingIds === localSelectionIds) {\n resolvedIdsRef.current = incomingIds;\n hasResolvedItemsRef.current = true;\n // Do NOT call setSelectedItems or setIsLoadingSelectedItems — they are already correct.\n return;\n }\n\n const currentSelected = selectedItemsRef.current;\n const currentSelectedMap = new Map(currentSelected.map(item => [String(item.id), item]));\n\n let allCovered = true;\n const newResolvedItems: RelationItem[] = [];\n const toRelationItem = entityToRelationItemRef.current;\n const slug = collectionSlugRef.current;\n\n for (const rel of currentRelationsArray) {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = String(isPrimitive ? rel : (rel as EntityRelation).id);\n const hasEmbeddedData = !isPrimitive && !!(rel as EntityRelation).data;\n\n if (hasEmbeddedData) {\n const r = rel as EntityRelation;\n // admin wire format embeds relation data as { id, path, values }\n newResolvedItems.push(toRelationItem(r.data as unknown as Entity, r));\n } else if (currentSelectedMap.has(relId)) {\n // We already have it in currentSelected\n const existingItem = currentSelectedMap.get(relId)!;\n newResolvedItems.push(existingItem);\n } else {\n allCovered = false;\n break;\n }\n }\n\n // FAST PATH: We have all necessary data embedded or in local cache\n if (allCovered) {\n setSelectedItems(newResolvedItems);\n hasResolvedItemsRef.current = true;\n resolvedIdsRef.current = incomingIds;\n setIsLoadingSelectedItems(false);\n return;\n }\n\n // SLOW PATH: fetch missing data — but don't show loading if popover is open\n // (user is actively interacting; showing a spinner is disruptive)\n if (!isPopoverOpenRef.current) {\n setIsLoadingSelectedItems(true);\n }\n const client = dataClientRef.current;\n const target = collectionRef.current;\n\n // The ids nothing above resolves, by the path they are read at:\n // one request per path (per 1,000 ids), not one per id.\n const unresolved = new Map<string, (string | number)[]>();\n for (const rel of currentRelationsArray) {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = isPrimitive ? rel : (rel as EntityRelation).id;\n if (!isPrimitive && (rel as EntityRelation).data) continue;\n if (currentSelectedMap.has(String(relId))) continue;\n const path = isPrimitive ? slug : (rel as EntityRelation).path;\n unresolved.set(path, [...(unresolved.get(path) ?? []), relId]);\n }\n\n Promise.all(\n [...unresolved].map(async ([path, ids]): Promise<[string, Map<string, Entity>]> => {\n try {\n return [path, await findEntitiesByIds(client.collection(path), target, ids)];\n } catch (e) {\n console.warn(\"RelationSelector: could not fetch the entities for relations\", path, ids, e);\n return [path, new Map()];\n }\n })\n ).then(read => {\n const readByPath = new Map(read);\n return currentRelationsArray.map((rel) => {\n const isPrimitive = typeof rel === \"string\" || typeof rel === \"number\";\n const relId = isPrimitive ? rel : (rel as EntityRelation).id;\n const path = isPrimitive ? slug : (rel as EntityRelation).path;\n const relation = isPrimitive ? new EntityRelation(relId, path) : rel as EntityRelation;\n\n if (!isPrimitive && (rel as EntityRelation).data) {\n // admin wire format embeds relation data as { id, path, values }\n return toRelationItem((rel as EntityRelation).data as unknown as Entity, relation);\n }\n if (currentSelectedMap.has(String(relId))) {\n return currentSelectedMap.get(String(relId))!;\n }\n const entity = readByPath.get(path)?.get(String(relId));\n if (entity) return toRelationItem(entity, relation);\n return { id: relId,\nlabel: String(relId),\nrelation } as RelationItem;\n });\n }).then(resolved => {\n if (active) {\n setSelectedItems(resolved);\n setIsLoadingSelectedItems(false);\n hasResolvedItemsRef.current = true;\n resolvedIdsRef.current = incomingIds;\n }\n });\n\n return () => {\n active = false;\n };\n }, [incomingIds, allHaveData]);\n\n const sentinelCallbackRef = useCallback((node: HTMLDivElement | null) => {\n if (observerRef.current) {\n observerRef.current.disconnect();\n observerRef.current = null;\n }\n if (sentinelRef.current !== node) {\n (sentinelRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n if (!node || !hasMore || isLoading || !loadMore) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[0];\n if (entry.isIntersecting && hasMore && !isLoading) loadMore();\n },\n {\n root: scrollContainerRef.current,\n rootMargin: \"20px\",\n threshold: 0\n }\n );\n observer.observe(node);\n observerRef.current = observer;\n }, [hasMore, isLoading, loadMore]);\n\n useEffect(() => () => {\n if (observerRef.current) observerRef.current.disconnect();\n }, []);\n\n // Enhanced scroll event listener specifically for dialog contexts\n useEffect(() => {\n const scrollContainer = scrollContainerRef.current;\n if (!scrollContainer || !hasMore || isLoading || !isPopoverOpen) return;\n\n const handleScroll = () => {\n const { scrollTop, scrollHeight, clientHeight } = scrollContainer;\n const isNearBottom = scrollTop + clientHeight >= scrollHeight - 100;\n\n if (isNearBottom && hasMore && !isLoading) {\n loadMore();\n }\n };\n\n // Add scroll listener directly to the container\n scrollContainer.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n return () => {\n scrollContainer.removeEventListener(\"scroll\", handleScroll);\n };\n }, [hasMore, isLoading, loadMore, isPopoverOpen]);\n\n const handleSearchChange = useCallback((newSearchString: string) => {\n setSearchString(newSearchString);\n search(newSearchString);\n }, [search]);\n\n const emitValueChange = useCallback((selected: RelationItem[]) => {\n if (multiple) onValueChange?.(selected.length ? selected.map(i => i.relation) : undefined);\n else onValueChange?.(selected[0]?.relation);\n }, [onValueChange, multiple]);\n\n // The picker can hand its selection over long after the render that\n // built the callback — a row created in the side panel arrives whenever\n // the person saves it — so the emitter is read from a ref rather than\n // captured.\n const emitValueChangeRef = useRef(emitValueChange);\n emitValueChangeRef.current = emitValueChange;\n\n // Helper: compute the \"IDs fingerprint\" for a set of RelationItems\n // so we can mark it in localSelectionIdsRef and skip re-resolution.\n const computeSelectionFingerprint = useCallback((items: RelationItem[]): string => {\n return items.map(i => String(i.id)).sort().join(\",\");\n }, []);\n\n const onItemClick = useCallback((item: RelationItem) => {\n let newSelected: RelationItem[];\n if (multiple) {\n const isSelected = selectedItems.some(v => String(v.id) === String(item.id));\n newSelected = isSelected\n ? selectedItems.filter(v => String(v.id) !== String(item.id))\n : [...selectedItems, item];\n } else {\n newSelected = [item];\n setPopoverOpen(false);\n }\n setSelectedItems(newSelected);\n // Mark this fingerprint so the resolution effect skips async work\n // when the parent echoes the same IDs back via props.\n localSelectionIdsRef.current = computeSelectionFingerprint(newSelected);\n emitValueChange(newSelected);\n }, [multiple, selectedItems, emitValueChange, computeSelectionFingerprint, setPopoverOpen]);\n\n const handleClear = useCallback(() => {\n setSelectedItems([]);\n localSelectionIdsRef.current = \"\";\n onValueChange?.(undefined);\n }, [onValueChange]);\n\n const handleRemoveItem = useCallback((itemToRemove: RelationItem) => {\n const newSelected = selectedItems.filter(v => String(v.id) !== String(itemToRemove.id));\n setSelectedItems(newSelected);\n localSelectionIdsRef.current = computeSelectionFingerprint(newSelected);\n emitValueChange(newSelected);\n }, [selectedItems, emitValueChange, computeSelectionFingerprint]);\n\n const handleRootOpenChange = useCallback((next: boolean) => {\n if (disabled) return;\n // We control open manually; only allow opening attempts from Radix (e.g. trigger press)\n if (next) setPopoverOpen(true);\n // Ignore close attempts here; outside click/Escape handled manually; single select closes explicitly on selection.\n }, [disabled, setPopoverOpen]);\n\n // Outside click + Escape handling (simple and reliable)\n useEffect(() => {\n if (!isPopoverOpen) return;\n\n function handlePointerDown(ev: MouseEvent) {\n const target = ev.target as Node;\n const triggerEl = localTriggerRef.current;\n const contentEl = contentRef.current;\n if (triggerEl?.contains(target)) return;\n if (contentEl?.contains(target)) return;\n // Outside\n setPopoverOpen(false);\n }\n\n // A layer of its own, so capture phase — and it claims the Escape\n // it acts on, so the record view underneath leaves the record open.\n function handleKey(ev: KeyboardEvent) {\n if (ev.key !== \"Escape\") return;\n ev.preventDefault();\n setPopoverOpen(false);\n }\n\n document.addEventListener(\"mousedown\", handlePointerDown, true);\n document.addEventListener(\"keydown\", handleKey, true);\n return () => {\n document.removeEventListener(\"mousedown\", handlePointerDown, true);\n document.removeEventListener(\"keydown\", handleKey, true);\n };\n }, [isPopoverOpen, setPopoverOpen]);\n\n const closePopover = useCallback(() => setPopoverOpen(false), [setPopoverOpen]);\n\n const toggleOpen = useCallback(() => {\n if (disabled) return;\n setPopoverOpen(!isPopoverOpenRef.current);\n }, [disabled, setPopoverOpen]);\n\n // Pointing at a row that does not exist yet.\n //\n // Until now the only way out of that was to abandon the form, go to the\n // other collection, create the row, come back and start again — and on\n // a new record that meant losing everything typed so far. The side\n // panel already stacks (the selection dialog creates from inside itself\n // this way), so the picker can open a create form over the form it\n // belongs to and select what comes back.\n const canCreateTarget = allowCreate && canCreate(collection, dataPath);\n\n // A search that matched nothing is the name the person was looking for,\n // so it seeds the new row. Only when the title lands on a plain string\n // property: putting free text into an enum, a relation or a computed\n // property would be worse than not prefilling at all.\n const buildDefaultValues = useCallback((searchText: string): Record<string, unknown> | undefined => {\n const trimmed = searchText.trim();\n if (!trimmed) return undefined;\n const titleKey = getTitlePropertyKey(collection);\n if (!titleKey || titleKey.includes(\".\")) return undefined;\n const titleProperty = collection.properties?.[titleKey];\n // A property builder is a function, and it decides its own value.\n if (!titleProperty || typeof titleProperty === \"function\") return undefined;\n if (titleProperty.type !== \"string\" || titleProperty.enum) return undefined;\n return { [titleKey]: trimmed };\n }, [collection]);\n\n const handleCreateNew = useCallback(() => {\n const defaultValues = buildDefaultValues(searchString);\n closePopover();\n sidePanelController.open({\n path: dataPath,\n collection,\n // No URL. This panel is a detour inside the form you are\n // filling in, not somewhere you navigated to, and its address\n // would restore nothing anyway — a record that does not exist\n // yet has none.\n //\n // Pushing one made closing it a *pathname* change, which is\n // exactly what the unsaved-changes blocker watches\n // (`useUnsavedChangesDialog`). So saving the new row raced the\n // panel clearing its own dirty flag, and often enough lost:\n // \"There are unsaved changes\" over a record that had just been\n // saved, with the URL stranded on the target collection. Worst\n // of all in the case this feature exists for — the outer form\n // has content in it, which is the whole reason not to leave.\n updateUrl: false,\n // Saving is the whole point of the detour; the panel goes away\n // and the picker is left holding the row it made.\n closeOnSave: true,\n defaultValues,\n onSaved: ({ row, id }) => {\n const entity = entityOfRow(row, id, dataPath, collection);\n const item = entityToRelationItemRef.current(entity, new EntityRelation(entity.id, dataPath));\n const current = selectedItemsRef.current;\n const newSelected = multiple\n ? [...current.filter(i => String(i.id) !== String(item.id)), item]\n : [item];\n setSelectedItems(newSelected);\n // Same bookkeeping `onItemClick` does: mark the fingerprint\n // so the resolution effect does not re-fetch the row we\n // already hold when the form echoes the value back.\n localSelectionIdsRef.current = newSelected.map(i => String(i.id)).sort().join(\",\");\n emitValueChangeRef.current(newSelected);\n }\n });\n }, [buildDefaultValues, searchString, closePopover, sidePanelController, dataPath, collection, multiple]);\n\n // Text, not `EmptyValue`. That component draws a small grey rounded bar\n // with no text in it, which is the same shape the `Skeleton` component\n // uses while data is in flight — so a relation you simply had not filled\n // in was indistinguishable from one that was still loading, and an empty\n // Author or Tags field read as permanently stuck. It also left the trigger\n // button with no accessible name, since the bar contains no text at all.\n //\n // This says \"not filled in\" rather than \"nothing to choose from\": which of\n // those it is cannot be known here. The list is deliberately not fetched\n // until the picker is first opened (`enabled: listRequested`, guarded by\n // relation_cell_picker_gating.test.tsx, because a table renders one of\n // these per row), so before that `availableItems` is empty because nobody\n // asked, not because the target collection is. The genuine \"nothing to\n // pick yet\" state is reported inside the popover below, where the fetch\n // has actually happened.\n const resolvedPlaceholder = placeholder || emptyPlaceholder || emptyText;\n\n // Whatever dialog, side dialog or sheet we are inside offers as its\n // portal host, falling back to `document.body`. This is not cosmetic:\n // those are modal, and a modal locks scrolling everywhere outside its\n // own content — a list portaled to the body opens and then refuses to\n // scroll, because every wheel event over it is cancelled.\n const portalContainer = (contextPortalContainer ?? (typeof document !== \"undefined\" ? document.body : undefined)) ?? undefined;\n\n return (\n <>\n <PopoverPrimitive.Root open={isPopoverOpen} onOpenChange={handleRootOpenChange} modal={false}>\n <PickerTrigger anchorRef={anchorRef}>\n {triggerContent !== undefined\n // Bare: the caller frames it. No box, no padding,\n // no height of its own — the node it passed,\n // exactly where it would be anyway. A `div`, not a\n // `button`: what it wraps can hold buttons of its\n // own (a record card's open button, at tall rows).\n ? <div\n ref={handleButtonRef}\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isPopoverOpen}\n data-relation-selector-trigger\n onClick={toggleOpen}\n // A record's title in the value opens that\n // record, and the list has no business staying\n // open over it.\n onClickCapture={(event) => {\n const target = event.target;\n if (!(target instanceof Element) || !isPopoverOpenRef.current) return;\n const interactive = target.closest(\"a, button, [role=\\\"button\\\"]\");\n if (interactive && interactive !== event.currentTarget) setPopoverOpen(false);\n }}\n onKeyDown={(event) => {\n if (event.key !== \"Enter\" && event.key !== \" \") return;\n event.preventDefault();\n toggleOpen();\n }}\n className={cls(\"w-full select-none text-left text-sm relative flex items-center outline-none\", className)}>\n {triggerContent}\n </div>\n : <button\n ref={handleButtonRef}\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={isPopoverOpen}\n data-relation-selector-trigger\n disabled={disabled}\n onClick={toggleOpen}\n className={cls(\n {\n \"min-h-[42px] py-1 px-2\": size === \"small\",\n \"min-h-[56px] py-2 px-4\": size === \"medium\",\n \"min-h-[48px] py-1 px-4\": size === \"large\"\n },\n // `rounded-lg` like every other field box —\n // `rounded-md` made this the one control in a\n // row with a different corner.\n \"w-full select-none rounded-lg text-sm relative flex items-center\",\n invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,\n disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,\n className\n )}\n >\n <div className=\"flex justify-between items-center w-full\">\n {isLoadingSelectedItems ? (\n <div className=\"flex items-center gap-2\">\n <CircularProgress size=\"smallest\"/>\n <span className=\"text-sm text-text-secondary dark:text-text-secondary-dark\">{loadingText}</span>\n </div>\n ) : selectedItems.length > 0 ? (\n <div\n className=\"flex flex-wrap items-center gap-1.5 text-start flex-1 min-w-0 mr-2\">\n {selectedItems.map((item) => {\n if (!useChips || !multiple) {\n return (\n <div key={String(item.id)}\n className=\"flex flex-row items-center gap-1 truncate\">\n {item.data ? (\n <EntityPreviewBindingData size={\"medium\"}\n entity={item.data}\n includeEntityLink={false}\n includeId={false}\n onSidePanelClick={closePopover}\n />\n ) : (\n <span className=\"text-sm truncate\">{item.label}</span>\n )}\n </div>\n );\n }\n return (\n <Chip\n size={\"small\"}\n key={String(item.id)}\n className={cls(\"flex flex-row items-center gap-1 truncate\")}\n >\n {item.data ? (\n <EntityPreviewBindingData size={\"smallest\"} entity={item.data}\n includeEntityLink={false}\n includeId={false}/>\n ) : (\n <span className=\"text-sm truncate\">{item.label}</span>\n )}\n <XIcon\n size={iconSize.smallest}\n onClick={(event) => {\n event.stopPropagation();\n handleRemoveItem(item);\n }}\n />\n </Chip>\n );\n })}\n </div>\n ) :\n (\n <span className=\"text-sm text-text-secondary dark:text-text-secondary-dark\">\n {resolvedPlaceholder}\n </span>\n )}\n\n <div className=\"flex items-center flex-shrink-0\">\n {!multiple && selectedItems.length === 1 && selectedItems[0]?.data && (\n <Tooltip title={t(\"relation_open_record\", { label: selectedItems[0].label })}>\n <IconButton aria-label={t(\"relation_open_record\", { label: selectedItems[0].label })}\n component={\"div\"}\n size={\"small\"}\n className=\"opacity-60 hover:opacity-100\"\n onClick={(e) => {\n e.stopPropagation();\n e.preventDefault();\n const entity = selectedItems[0].data!;\n setPopoverOpen(false);\n sidePanelController.open({\n id: entity.id,\n path: entity.path,\n collection,\n updateUrl: true\n });\n }}>\n <ArrowRightToLineIcon size={iconSize.small}/>\n </IconButton>\n </Tooltip>\n )}\n <ChevronDownIcon\n size={size === \"small\" ? iconSize.small : iconSize.medium}\n className={cls(\"transition\", isPopoverOpen ? \"rotate-180\" : \"\")}\n />\n </div>\n </div>\n\n </button>}\n </PickerTrigger>\n <PopoverPrimitive.Portal container={portalContainer}>\n <PopoverPrimitive.Content\n ref={contentRef}\n data-relation-selector-content\n className={cls(\"z-50 overflow-hidden border bg-surface-card rounded-lg min-w-72\", defaultBorderMixin)}\n align=\"start\"\n sideOffset={8}\n side=\"bottom\"\n avoidCollisions={true}\n collisionPadding={16}\n // Allow default auto focus (we manually refocus anyway)\n onOpenAutoFocus={(_e) => { /* leave default or custom manual focus */\n }}\n onCloseAutoFocus={(e) => {\n e.preventDefault();\n }}\n style={{ width: \"var(--radix-popover-trigger-width)\" }}\n >\n <CommandPrimitive shouldFilter={false}>\n <div className=\"flex flex-row items-center\">\n <div className=\"relative flex-1\">\n <SearchIcon\n className=\"absolute left-3 top-1/2 transform -translate-y-1/2 text-text-secondary dark:text-text-secondary-dark\"\n size={iconSize.smallest}/>\n <CommandPrimitive.Input\n ref={searchInputRef}\n className={cls(\n focusedDisabled,\n \"bg-transparent outline-hidden flex-1 h-full w-full pl-10 pr-4 py-3 text-text-primary dark:text-text-primary-dark placeholder:text-text-secondary dark:placeholder:text-text-secondary-dark\"\n )}\n placeholder={searchPlaceholder}\n value={searchString}\n onValueChange={handleSearchChange}\n />\n </div>\n {isLoading && (\n <div className=\"flex items-center justify-center px-3\">\n <CircularProgress size=\"smallest\"/>\n </div>\n )}\n {selectedItems.length > 0 && (\n <div\n onClick={handleClear}\n className=\"text-sm justify-center cursor-pointer py-3 px-4 text-text-secondary dark:text-text-secondary-dark hover:text-text-primary dark:hover:text-text-primary-dark\"\n >\n Clear\n </div>\n )}\n </div>\n <Separator orientation=\"horizontal\" className=\"my-0\"/>\n <CommandPrimitive.List\n ref={scrollContainerRef}\n style={{\n maxHeight: \"40vh\",\n overflowY: \"auto\"\n }}\n >\n {isLoading && availableItems.length === 0 && (\n <div className=\"flex items-center justify-center py-6\">\n <CircularProgress size=\"small\"/>\n <span\n className=\"ml-2 text-sm text-text-secondary dark:text-text-secondary-dark\">{loadingText}</span>\n </div>\n )}\n {/* Two different nothings, which used to share one\n message (\"No relations found.\") even though the\n fix for each is the opposite: clear the search, or\n go and create the first row. With the fetch done,\n the search string is what tells them apart. */}\n {!isLoading && availableItems.length === 0 && (\n <CommandPrimitive.Empty\n className=\"px-4 py-6 text-center text-text-secondary dark:text-text-secondary-dark\">\n {searchString\n ? noResultsText\n : (emptyCollectionText ?? `No ${collection.name ?? \"entries\"} yet.`)}\n </CommandPrimitive.Empty>\n )}\n <CommandPrimitive.Group>\n {(() => {\n // Sort items so that initially-selected (pinned) items appear first.\n // We use the entity taken when the popover opened so items don't\n // jump around as the user checks/unchecks.\n const pinned = pinnedIdsRef.current;\n const sortedItems = pinned && pinned.size > 0\n ? [...availableItems].sort((a, b) => {\n const aP = pinned.has(String(a.id)) ? 0 : 1;\n const bP = pinned.has(String(b.id)) ? 0 : 1;\n return aP - bP;\n })\n : availableItems;\n return sortedItems;\n })().map((item) => {\n const isSelected = selectedItems.some(v => String(v.id) === String(item.id));\n return (\n <CommandPrimitive.Item\n key={String(item.id)}\n value={String(item.id)}\n onMouseDown={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onSelect={() => onItemClick(item)}\n className={cls(\n \"flex flex-row items-center gap-1.5 m-1 p-1 rounded-xs cursor-pointer ring-offset-transparent\",\n isSelected && \"bg-surface-active\",\n \"aria-selected:outline-hidden aria-selected:bg-surface-active\"\n )}\n >\n {multiple && (<InnerCheckBox checked={isSelected}/>)}\n {item.data ? (\n <div\n className=\"flex flex-row items-center gap-2 min-w-0 w-full\">\n <EntityPreviewBindingData\n size={multiple ? \"smallest\" : \"medium\"}\n entity={item.data}\n includeId={false}\n includeEntityLink={true}\n />\n </div>\n ) : (\n <div>\n <div\n className=\"text-sm font-medium text-text-primary dark:text-text-primary-dark\">{item.label}</div>\n {item.description && (\n <div\n className=\"text-xs text-text-secondary dark:text-text-secondary-dark\">{item.description}</div>\n )}\n </div>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {availableItems.length > 0 && hasMore && (\n <div ref={sentinelCallbackRef} className=\"h-1 w-full\"\n style={{ visibility: \"hidden\" }}/>\n )}\n {isLoading && availableItems.length > 0 && (\n <div className=\"flex items-center justify-center py-4\">\n <CircularProgress size=\"smallest\"/>\n <span\n className=\"ml-2 text-xs text-text-secondary dark:text-text-secondary-dark\">Loading...</span>\n </div>\n )}\n </CommandPrimitive.Group>\n </CommandPrimitive.List>\n {canCreateTarget && <>\n <Separator orientation=\"horizontal\" className=\"my-0\"/>\n {/* Outside the scrolling list on purpose: it\n is most wanted exactly when the list is\n long and nothing in it matched. */}\n <button\n type=\"button\"\n data-relation-selector-create\n onMouseDown={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onClick={handleCreateNew}\n className={cls(\n \"w-full flex flex-row items-center gap-2 px-4 py-3 text-sm text-left\",\n \"text-primary hover:bg-surface-hover\"\n )}>\n <PlusIcon size={iconSize.smallest}/>\n <span className=\"truncate\">\n {searchString.trim()\n ? t(\"add_named\", { name: searchString.trim() })\n : t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </span>\n </button>\n </>}\n </CommandPrimitive>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </>\n );\n }\n);\n\nRelationSelector.displayName = \"RelationSelector\";\n\nfunction InnerCheckBox({ checked }: { checked: boolean }) {\n return (\n <div className={cls(\n \"p-2 w-8 h-8 inline-flex items-center justify-center text-sm font-medium focus:outline-hidden transition-colors ease-in-out duration-150\"\n )}>\n <div\n className={cls(\n \"border-2 relative transition-colors ease-in-out duration-150 w-4 h-4 rounded-xs flex items-center justify-center\",\n checked ? \"bg-primary text-surface-accent-100 dark:text-surface-accent-900 border-transparent\" : \"bg-surface-card border-surface-accent-800 dark:border-surface-accent-500\"\n )}\n >\n {checked && <CheckIcon size={iconSize.smallest} className=\"absolute\"/>}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAqCA,SAAS,oBAAoB,UAA2F;CACpH,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,IAAI,SAAS,SAAS,OAAO,OAAO,SAAS;CAC7C,IAAI,SAAS,SAAS,aAAa,SAAS,SAAS,cAAc,OAAO;CAC1E,IAAI,SAAS,SAAS,eAAe,SAAS,SAAS,UAAU,OAAO;CACxE,OAAO,SAAS;AACpB;AAiGA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