@arbidocs/blocks 0.5.182 → 0.5.183

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 (378) hide show
  1. package/README.md +30 -0
  2. package/dist/{ClippingPdfViewer-D5BYHEAH.cjs → ClippingPdfViewer-Z6L5DZW5.cjs} +4 -4
  3. package/dist/{ClippingPdfViewer-D5BYHEAH.cjs.map → ClippingPdfViewer-Z6L5DZW5.cjs.map} +1 -1
  4. package/dist/{ConnectedCallDock-C5UPUMMJ.cjs → ConnectedCallDock-CF7KF5KM.cjs} +6 -6
  5. package/dist/{ConnectedCallDock-C5UPUMMJ.cjs.map → ConnectedCallDock-CF7KF5KM.cjs.map} +1 -1
  6. package/dist/{ConnectedCallRoom-SEMH4DSA.cjs → ConnectedCallRoom-NQOE2RYD.cjs} +6 -6
  7. package/dist/{ConnectedCallRoom-SEMH4DSA.cjs.map → ConnectedCallRoom-NQOE2RYD.cjs.map} +1 -1
  8. package/dist/{ConnectedNativeDocxComparison-3MRTTNR2.cjs → ConnectedNativeDocxComparison-3KTHPCMT.cjs} +11 -10
  9. package/dist/{ConnectedNativeDocxComparison-3MRTTNR2.cjs.map → ConnectedNativeDocxComparison-3KTHPCMT.cjs.map} +1 -1
  10. package/dist/ConnectedPresentation-LNDESKYE.cjs +1 -1
  11. package/dist/{ConnectedSlidesTab-LEA5OW75.cjs → ConnectedSlidesTab-SYDDGJWM.cjs} +3 -3
  12. package/dist/{ConnectedSlidesTab-LEA5OW75.cjs.map → ConnectedSlidesTab-SYDDGJWM.cjs.map} +1 -1
  13. package/dist/{ConnectedStreamedWordArtifact-HNTS6HS4.cjs → ConnectedStreamedWordArtifact-LUM6WE7F.cjs} +11 -10
  14. package/dist/{ConnectedStreamedWordArtifact-HNTS6HS4.cjs.map → ConnectedStreamedWordArtifact-LUM6WE7F.cjs.map} +1 -1
  15. package/dist/{DocumentReviewCard-RPHIQZ2Y.cjs → DocumentReviewCard-NKCKBY3P.cjs} +15 -13
  16. package/dist/DocumentReviewCard-NKCKBY3P.cjs.map +1 -0
  17. package/dist/{FilesViewerDialog-PZ5H435S.cjs → FilesViewerDialog-T4SOKUKO.cjs} +14 -12
  18. package/dist/FilesViewerDialog-T4SOKUKO.cjs.map +1 -0
  19. package/dist/{NativeDocxEditor-T7FSMKG3.cjs → NativeDocxEditor-JJQJEYQD.cjs} +8 -7
  20. package/dist/{NativeDocxEditor-T7FSMKG3.cjs.map → NativeDocxEditor-JJQJEYQD.cjs.map} +1 -1
  21. package/dist/WorkspaceTableView-QT63XYII.cjs +1 -1
  22. package/dist/agents/index.cjs +1 -1
  23. package/dist/{ai-XIT4MY3S.cjs → ai-CTJWECJ5.cjs} +14 -14
  24. package/dist/ai-CTJWECJ5.cjs.map +1 -0
  25. package/dist/calls/index.cjs +3 -3
  26. package/dist/chat/index.cjs +26 -26
  27. package/dist/{chunk-4AT2LJ2H.cjs → chunk-3YPVXIFF.cjs} +6 -6
  28. package/dist/{chunk-4AT2LJ2H.cjs.map → chunk-3YPVXIFF.cjs.map} +1 -1
  29. package/dist/{chunk-GLFMRQBT.cjs → chunk-4TCOUQMC.cjs} +4 -4
  30. package/dist/{chunk-GLFMRQBT.cjs.map → chunk-4TCOUQMC.cjs.map} +1 -1
  31. package/dist/{chunk-DDWLMYRO.cjs → chunk-4XKROAMO.cjs} +8 -3
  32. package/dist/chunk-4XKROAMO.cjs.map +1 -0
  33. package/dist/{chunk-AWWGV5LL.cjs → chunk-6VIS6B3O.cjs} +28 -28
  34. package/dist/{chunk-AWWGV5LL.cjs.map → chunk-6VIS6B3O.cjs.map} +1 -1
  35. package/dist/chunk-76S6WTEC.cjs +39 -0
  36. package/dist/chunk-76S6WTEC.cjs.map +1 -0
  37. package/dist/{chunk-MZ7IUHQA.cjs → chunk-7ARRFRQR.cjs} +38 -38
  38. package/dist/chunk-7ARRFRQR.cjs.map +1 -0
  39. package/dist/{chunk-CYMAF656.cjs → chunk-7QZXHSQX.cjs} +18 -5
  40. package/dist/chunk-7QZXHSQX.cjs.map +1 -0
  41. package/dist/chunk-AZP4ABNL.cjs +18 -0
  42. package/dist/{chunk-TUURH4NE.cjs.map → chunk-AZP4ABNL.cjs.map} +1 -1
  43. package/dist/{chunk-TJY7XPDE.cjs → chunk-CWECDS4I.cjs} +4 -95
  44. package/dist/chunk-CWECDS4I.cjs.map +1 -0
  45. package/dist/{chunk-YC72ZCV4.cjs → chunk-DWUWPF2A.cjs} +147 -90
  46. package/dist/chunk-DWUWPF2A.cjs.map +1 -0
  47. package/dist/{chunk-POUMLXMJ.cjs → chunk-FTSXCBUO.cjs} +6 -6
  48. package/dist/{chunk-POUMLXMJ.cjs.map → chunk-FTSXCBUO.cjs.map} +1 -1
  49. package/dist/chunk-GISMY7J7.cjs +99 -0
  50. package/dist/chunk-GISMY7J7.cjs.map +1 -0
  51. package/dist/chunk-GXJW5EK5.cjs +102 -0
  52. package/dist/chunk-GXJW5EK5.cjs.map +1 -0
  53. package/dist/{chunk-HX5SALXN.cjs → chunk-H3C5BY2H.cjs} +4 -4
  54. package/dist/{chunk-HX5SALXN.cjs.map → chunk-H3C5BY2H.cjs.map} +1 -1
  55. package/dist/{chunk-G2B2BWE5.cjs → chunk-HGQGXY5Q.cjs} +4 -4
  56. package/dist/{chunk-G2B2BWE5.cjs.map → chunk-HGQGXY5Q.cjs.map} +1 -1
  57. package/dist/{chunk-7H7KIJW2.cjs → chunk-HQ6SK34T.cjs} +3 -3
  58. package/dist/{chunk-7H7KIJW2.cjs.map → chunk-HQ6SK34T.cjs.map} +1 -1
  59. package/dist/{chunk-YHABS4UE.cjs → chunk-HYULUR6E.cjs} +12 -12
  60. package/dist/{chunk-YHABS4UE.cjs.map → chunk-HYULUR6E.cjs.map} +1 -1
  61. package/dist/chunk-I24N4OSB.cjs +57 -0
  62. package/dist/chunk-I24N4OSB.cjs.map +1 -0
  63. package/dist/{chunk-TQATDAJV.cjs → chunk-J4X3LYGC.cjs} +4 -4
  64. package/dist/{chunk-TQATDAJV.cjs.map → chunk-J4X3LYGC.cjs.map} +1 -1
  65. package/dist/chunk-KHZEFLQC.cjs +524 -0
  66. package/dist/chunk-KHZEFLQC.cjs.map +1 -0
  67. package/dist/{chunk-DKKW7GOJ.cjs → chunk-LIAC6O7W.cjs} +4 -4
  68. package/dist/{chunk-DKKW7GOJ.cjs.map → chunk-LIAC6O7W.cjs.map} +1 -1
  69. package/dist/{chunk-MWHVETKN.cjs → chunk-LIJB6XOR.cjs} +47 -7
  70. package/dist/chunk-LIJB6XOR.cjs.map +1 -0
  71. package/dist/{chunk-PJ5OQ5VB.cjs → chunk-LNYICHFJ.cjs} +23 -23
  72. package/dist/{chunk-PJ5OQ5VB.cjs.map → chunk-LNYICHFJ.cjs.map} +1 -1
  73. package/dist/{chunk-UC6Z7E6C.cjs → chunk-LRBX4VIG.cjs} +4 -4
  74. package/dist/{chunk-UC6Z7E6C.cjs.map → chunk-LRBX4VIG.cjs.map} +1 -1
  75. package/dist/{chunk-JITYC4OS.cjs → chunk-NDRE7LD2.cjs} +17 -2
  76. package/dist/chunk-NDRE7LD2.cjs.map +1 -0
  77. package/dist/{chunk-FUKN3PI5.cjs → chunk-NGT3P5ZG.cjs} +100 -506
  78. package/dist/chunk-NGT3P5ZG.cjs.map +1 -0
  79. package/dist/{chunk-2D5GZMSK.cjs → chunk-SFAAOEQE.cjs} +43 -30
  80. package/dist/chunk-SFAAOEQE.cjs.map +1 -0
  81. package/dist/{chunk-KULGPKLY.cjs → chunk-TBDQGSFI.cjs} +4 -4
  82. package/dist/{chunk-KULGPKLY.cjs.map → chunk-TBDQGSFI.cjs.map} +1 -1
  83. package/dist/{chunk-BQOL4XNZ.cjs → chunk-U46OGRCO.cjs} +94 -10
  84. package/dist/chunk-U46OGRCO.cjs.map +1 -0
  85. package/dist/{chunk-UTYEXDJK.cjs → chunk-UFDUDQYT.cjs} +887 -168
  86. package/dist/chunk-UFDUDQYT.cjs.map +1 -0
  87. package/dist/chunk-V5P5MRSR.cjs +21 -0
  88. package/dist/chunk-V5P5MRSR.cjs.map +1 -0
  89. package/dist/{chunk-N33U2SB5.cjs → chunk-VBD4RJOL.cjs} +730 -72
  90. package/dist/chunk-VBD4RJOL.cjs.map +1 -0
  91. package/dist/{chunk-ADMNU2CR.cjs → chunk-W5UGKUV7.cjs} +66 -132
  92. package/dist/chunk-W5UGKUV7.cjs.map +1 -0
  93. package/dist/{chunk-6EJ7KD4U.cjs → chunk-WDL3TOMX.cjs} +6 -6
  94. package/dist/{chunk-6EJ7KD4U.cjs.map → chunk-WDL3TOMX.cjs.map} +1 -1
  95. package/dist/{chunk-S4KKJX3G.cjs → chunk-WIQDXRRB.cjs} +12 -12
  96. package/dist/{chunk-S4KKJX3G.cjs.map → chunk-WIQDXRRB.cjs.map} +1 -1
  97. package/dist/{chunk-6CPJ5ZOY.cjs → chunk-YM77I6V7.cjs} +3 -3
  98. package/dist/{chunk-6CPJ5ZOY.cjs.map → chunk-YM77I6V7.cjs.map} +1 -1
  99. package/dist/{chunk-ICZSVCDT.cjs → chunk-YYMCN76N.cjs} +5 -5
  100. package/dist/{chunk-ICZSVCDT.cjs.map → chunk-YYMCN76N.cjs.map} +1 -1
  101. package/dist/{chunk-JKTUL4L3.cjs → chunk-ZON25DCD.cjs} +5 -5
  102. package/dist/{chunk-JKTUL4L3.cjs.map → chunk-ZON25DCD.cjs.map} +1 -1
  103. package/dist/{chunk-YBDHWNFZ.cjs → chunk-ZTLPUUZB.cjs} +20 -20
  104. package/dist/{chunk-YBDHWNFZ.cjs.map → chunk-ZTLPUUZB.cjs.map} +1 -1
  105. package/dist/components/DetailPanel.d.ts +46 -3
  106. package/dist/components/DetailPanel.js +94 -10
  107. package/dist/components/DetailPanel.js.map +2 -2
  108. package/dist/connect/docx.cjs +15 -14
  109. package/dist/connect/docx.cjs.map +1 -1
  110. package/dist/connect/index.cjs +4478 -1585
  111. package/dist/connect/index.cjs.map +1 -1
  112. package/dist/connect/index.d.ts +2 -1
  113. package/dist/connect/index.js +5 -1
  114. package/dist/connect/index.js.map +2 -2
  115. package/dist/connect/viewer.cjs +12 -10
  116. package/dist/connection/databases/ConnectedDatabasesPage.d.ts +22 -1
  117. package/dist/connection/databases/ConnectedDatabasesPage.js +189 -422
  118. package/dist/connection/databases/ConnectedDatabasesPage.js.map +2 -2
  119. package/dist/connection/databases/ConnectedRecentDatabases.d.ts +15 -0
  120. package/dist/connection/databases/ConnectedRecentDatabases.js +80 -0
  121. package/dist/connection/databases/ConnectedRecentDatabases.js.map +7 -0
  122. package/dist/connection/databases/DatabaseViewsMenu.d.ts +8 -4
  123. package/dist/connection/databases/DatabaseViewsMenu.js +60 -27
  124. package/dist/connection/databases/DatabaseViewsMenu.js.map +2 -2
  125. package/dist/connection/databases/DatabaseWorkbench.d.ts +10 -0
  126. package/dist/connection/databases/DatabaseWorkbench.js +681 -0
  127. package/dist/connection/databases/DatabaseWorkbench.js.map +7 -0
  128. package/dist/connection/databases/databaseViewState.d.ts +12 -0
  129. package/dist/connection/databases/databaseViewState.js +50 -0
  130. package/dist/connection/databases/databaseViewState.js.map +7 -0
  131. package/dist/connection/databases/fixedPins.d.ts +6 -0
  132. package/dist/connection/databases/fixedPins.js +19 -0
  133. package/dist/connection/databases/fixedPins.js.map +7 -0
  134. package/dist/connection/databases/index.d.ts +6 -1
  135. package/dist/connection/databases/index.js +9 -1
  136. package/dist/connection/databases/index.js.map +2 -2
  137. package/dist/connection/databases/source.d.ts +26 -0
  138. package/dist/connection/databases/toRowView.d.ts +4 -0
  139. package/dist/connection/databases/toRowView.js +11 -0
  140. package/dist/connection/databases/toRowView.js.map +7 -0
  141. package/dist/connection/databases/useApiDatabaseSource.d.ts +11 -0
  142. package/dist/connection/databases/useApiDatabaseSource.js +449 -0
  143. package/dist/connection/databases/useApiDatabaseSource.js.map +7 -0
  144. package/dist/connection/databases/useApiViewStore.d.ts +5 -0
  145. package/dist/connection/databases/useApiViewStore.js +57 -0
  146. package/dist/connection/databases/useApiViewStore.js.map +7 -0
  147. package/dist/connection/databases/useDeviceLayoutSettings.d.ts +6 -0
  148. package/dist/connection/databases/useDeviceLayoutSettings.js +57 -0
  149. package/dist/connection/databases/useDeviceLayoutSettings.js.map +7 -0
  150. package/dist/connection/databases/useLayoutRows.d.ts +13 -0
  151. package/dist/connection/databases/useLayoutRows.js +89 -0
  152. package/dist/connection/databases/useLayoutRows.js.map +7 -0
  153. package/dist/connection/databases/useSourceEntries.d.ts +6 -0
  154. package/dist/connection/databases/useSourceEntries.js +8 -0
  155. package/dist/connection/databases/useSourceEntries.js.map +7 -0
  156. package/dist/connection/facts/ConnectedFactsPage.d.ts +11 -1
  157. package/dist/connection/facts/ConnectedFactsPage.js +42 -10
  158. package/dist/connection/facts/ConnectedFactsPage.js.map +2 -2
  159. package/dist/connection/facts/FactMarkdownEditor.d.ts +19 -1
  160. package/dist/connection/facts/FactMarkdownEditor.js +67 -49
  161. package/dist/connection/facts/FactMarkdownEditor.js.map +2 -2
  162. package/dist/connection/facts/FactSourcesPopover.d.ts +3 -1
  163. package/dist/connection/facts/FactSourcesPopover.js +71 -61
  164. package/dist/connection/facts/FactSourcesPopover.js.map +2 -2
  165. package/dist/connection/facts/FactsQuickFilters.d.ts +16 -0
  166. package/dist/connection/facts/FactsQuickFilters.js +57 -0
  167. package/dist/connection/facts/FactsQuickFilters.js.map +7 -0
  168. package/dist/connection/facts/factsRows.d.ts +49 -0
  169. package/dist/connection/facts/factsRows.js +103 -0
  170. package/dist/connection/facts/factsRows.js.map +7 -0
  171. package/dist/connection/facts/factsScope.d.ts +24 -0
  172. package/dist/connection/facts/factsScope.js +32 -0
  173. package/dist/connection/facts/factsScope.js.map +7 -0
  174. package/dist/connection/facts/factsSource.d.ts +12 -0
  175. package/dist/connection/facts/factsSource.js +1320 -0
  176. package/dist/connection/facts/factsSource.js.map +7 -0
  177. package/dist/connection/facts/useFactActions.d.ts +2 -2
  178. package/dist/connection/facts/useFactActions.js +4 -0
  179. package/dist/connection/facts/useFactActions.js.map +2 -2
  180. package/dist/connection/facts/useFactComposer.d.ts +8 -2
  181. package/dist/connection/facts/useFactComposer.js +31 -8
  182. package/dist/connection/facts/useFactComposer.js.map +2 -2
  183. package/dist/connection/facts/view-keys.d.ts +4 -0
  184. package/dist/connection/facts/view-keys.js +2 -0
  185. package/dist/connection/facts/view-keys.js.map +2 -2
  186. package/dist/connection/files/explorer/FileTiles.js +2 -2
  187. package/dist/connection/files/explorer/FileTiles.js.map +2 -2
  188. package/dist/connection/files/page/ConnectedFilesPage.js +4 -1
  189. package/dist/connection/files/page/ConnectedFilesPage.js.map +2 -2
  190. package/dist/connection/files/views/useTableViews.js +11 -3
  191. package/dist/connection/files/views/useTableViews.js.map +2 -2
  192. package/dist/connection/live-blocks/list-rows.d.ts +10 -0
  193. package/dist/connection/live-blocks/list-rows.js +12 -0
  194. package/dist/connection/live-blocks/list-rows.js.map +2 -2
  195. package/dist/connection/viewer/pdf/PdfPassageHighlights.d.ts +10 -2
  196. package/dist/connection/viewer/pdf/PdfPassageHighlights.js +57 -26
  197. package/dist/connection/viewer/pdf/PdfPassageHighlights.js.map +2 -2
  198. package/dist/connection/viewer/pdf/passageHighlights.d.ts +8 -0
  199. package/dist/connection/viewer/pdf/passageHighlights.js +15 -0
  200. package/dist/connection/viewer/pdf/passageHighlights.js.map +2 -2
  201. package/dist/connection/viewer/pdf/usePdfPassageHighlights.js +31 -5
  202. package/dist/connection/viewer/pdf/usePdfPassageHighlights.js.map +2 -2
  203. package/dist/connection/workspace-dashboard/ConnectedWorkspaceDashboard.d.ts +9 -2
  204. package/dist/connection/workspace-dashboard/ConnectedWorkspaceDashboard.js +16 -6
  205. package/dist/connection/workspace-dashboard/ConnectedWorkspaceDashboard.js.map +2 -2
  206. package/dist/dashboards/ConditionsEditor.d.ts +14 -1
  207. package/dist/dashboards/ConditionsEditor.js +45 -5
  208. package/dist/dashboards/ConditionsEditor.js.map +2 -2
  209. package/dist/dashboards/index.cjs +9 -9
  210. package/dist/databases/ColumnConfigFields.js +1 -1
  211. package/dist/databases/ColumnConfigFields.js.map +2 -2
  212. package/dist/databases/DatabaseColumnDialog.d.ts +6 -1
  213. package/dist/databases/DatabaseColumnDialog.js +44 -3
  214. package/dist/databases/DatabaseColumnDialog.js.map +2 -2
  215. package/dist/databases/DatabaseFilterMenu.d.ts +23 -1
  216. package/dist/databases/DatabaseFilterMenu.js +37 -7
  217. package/dist/databases/DatabaseFilterMenu.js.map +2 -2
  218. package/dist/databases/DatabaseList.d.ts +22 -1
  219. package/dist/databases/DatabaseList.js +44 -9
  220. package/dist/databases/DatabaseList.js.map +2 -2
  221. package/dist/databases/DatabaseRowDetail.d.ts +40 -3
  222. package/dist/databases/DatabaseRowDetail.js +107 -20
  223. package/dist/databases/DatabaseRowDetail.js.map +2 -2
  224. package/dist/databases/DatabaseTable.d.ts +44 -5
  225. package/dist/databases/DatabaseTable.js +165 -15
  226. package/dist/databases/DatabaseTable.js.map +2 -2
  227. package/dist/databases/DatabaseToolbar.d.ts +29 -3
  228. package/dist/databases/DatabaseToolbar.js +148 -96
  229. package/dist/databases/DatabaseToolbar.js.map +2 -2
  230. package/dist/databases/DateSpanEditor.d.ts +32 -0
  231. package/dist/databases/DateSpanEditor.js +155 -0
  232. package/dist/databases/DateSpanEditor.js.map +7 -0
  233. package/dist/databases/LabelChip.d.ts +6 -0
  234. package/dist/databases/LabelChip.js +34 -0
  235. package/dist/databases/LabelChip.js.map +7 -0
  236. package/dist/databases/LabelsCell.d.ts +13 -0
  237. package/dist/databases/LabelsCell.js +38 -0
  238. package/dist/databases/LabelsCell.js.map +7 -0
  239. package/dist/databases/LabelsField.d.ts +6 -0
  240. package/dist/databases/LabelsField.js +17 -0
  241. package/dist/databases/LabelsField.js.map +7 -0
  242. package/dist/databases/SourcesCell.d.ts +21 -0
  243. package/dist/databases/SourcesCell.js +106 -0
  244. package/dist/databases/SourcesCell.js.map +7 -0
  245. package/dist/databases/SourcesField.d.ts +7 -0
  246. package/dist/databases/SourcesField.js +36 -0
  247. package/dist/databases/SourcesField.js.map +7 -0
  248. package/dist/databases/column-kits.d.ts +28 -0
  249. package/dist/databases/column-kits.js +87 -0
  250. package/dist/databases/column-kits.js.map +7 -0
  251. package/dist/databases/column-types.d.ts +36 -4
  252. package/dist/databases/column-types.js +22 -3
  253. package/dist/databases/column-types.js.map +2 -2
  254. package/dist/databases/databaseColumns.d.ts +29 -2
  255. package/dist/databases/databaseColumns.js +174 -46
  256. package/dist/databases/databaseColumns.js.map +2 -2
  257. package/dist/databases/index.cjs +135 -54
  258. package/dist/databases/index.d.ts +12 -5
  259. package/dist/databases/index.js +17 -0
  260. package/dist/databases/index.js.map +2 -2
  261. package/dist/databases/layouts/DatabaseCalendar.d.ts +17 -0
  262. package/dist/databases/layouts/DatabaseCalendar.js +63 -0
  263. package/dist/databases/layouts/DatabaseCalendar.js.map +7 -0
  264. package/dist/databases/layouts/DatabaseGantt.d.ts +9 -0
  265. package/dist/databases/layouts/DatabaseGantt.js +52 -0
  266. package/dist/databases/layouts/DatabaseGantt.js.map +7 -0
  267. package/dist/databases/layouts/DatabaseLayoutSwitcher.d.ts +43 -0
  268. package/dist/databases/layouts/DatabaseLayoutSwitcher.js +190 -0
  269. package/dist/databases/layouts/DatabaseLayoutSwitcher.js.map +7 -0
  270. package/dist/databases/layouts/definitions.d.ts +11 -0
  271. package/dist/databases/layouts/definitions.js +56 -0
  272. package/dist/databases/layouts/definitions.js.map +7 -0
  273. package/dist/databases/layouts/index.d.ts +7 -0
  274. package/dist/databases/layouts/index.js +27 -0
  275. package/dist/databases/layouts/index.js.map +7 -0
  276. package/dist/databases/layouts/resolveLayoutSettings.d.ts +13 -0
  277. package/dist/databases/layouts/resolveLayoutSettings.js +47 -0
  278. package/dist/databases/layouts/resolveLayoutSettings.js.map +7 -0
  279. package/dist/databases/layouts/rowsToTimelineItems.d.ts +19 -0
  280. package/dist/databases/layouts/rowsToTimelineItems.js +81 -0
  281. package/dist/databases/layouts/rowsToTimelineItems.js.map +7 -0
  282. package/dist/databases/layouts/undated.d.ts +6 -0
  283. package/dist/databases/layouts/undated.js +10 -0
  284. package/dist/databases/layouts/undated.js.map +7 -0
  285. package/dist/databases/linkCells.d.ts +14 -1
  286. package/dist/databases/linkCells.js +11 -5
  287. package/dist/databases/linkCells.js.map +2 -2
  288. package/dist/databases/local-query.d.ts +7 -0
  289. package/dist/databases/local-query.js +89 -0
  290. package/dist/databases/local-query.js.map +7 -0
  291. package/dist/databases/source.d.ts +291 -0
  292. package/dist/databases/sourcesOverflow.d.ts +5 -0
  293. package/dist/databases/sourcesOverflow.js +10 -0
  294. package/dist/databases/sourcesOverflow.js.map +7 -0
  295. package/dist/docx/index.cjs +40 -39
  296. package/dist/embed/index.cjs +17 -14
  297. package/dist/facts/FactDateInput.d.ts +3 -1
  298. package/dist/facts/FactDateInput.js +110 -93
  299. package/dist/facts/FactDateInput.js.map +2 -2
  300. package/dist/facts/FactLabelsCell.d.ts +4 -0
  301. package/dist/facts/FactLabelsCell.js +27 -13
  302. package/dist/facts/FactLabelsCell.js.map +2 -2
  303. package/dist/facts/FactPassages.d.ts +6 -1
  304. package/dist/facts/FactPassages.js +6 -1
  305. package/dist/facts/FactPassages.js.map +2 -2
  306. package/dist/facts/FactsScopeEmpty.d.ts +8 -0
  307. package/dist/facts/FactsScopeEmpty.js +29 -0
  308. package/dist/facts/FactsScopeEmpty.js.map +7 -0
  309. package/dist/facts/FactsScopePicker.d.ts +33 -0
  310. package/dist/facts/FactsScopePicker.js +108 -0
  311. package/dist/facts/FactsScopePicker.js.map +7 -0
  312. package/dist/facts/index.cjs +107 -94
  313. package/dist/facts/index.cjs.map +1 -1
  314. package/dist/facts/index.d.ts +1 -0
  315. package/dist/facts/index.js +6 -0
  316. package/dist/facts/index.js.map +2 -2
  317. package/dist/files/ExplorerTile.d.ts +2 -2
  318. package/dist/files/ExplorerTile.js +3 -3
  319. package/dist/files/ExplorerTile.js.map +1 -1
  320. package/dist/files/HtmlViewerParts.js +7 -1
  321. package/dist/files/HtmlViewerParts.js.map +2 -2
  322. package/dist/files/folders/DocumentsFolderButton.d.ts +3 -1
  323. package/dist/files/folders/DocumentsFolderButton.js +3 -1
  324. package/dist/files/folders/DocumentsFolderButton.js.map +2 -2
  325. package/dist/files/folders/FolderTreePicker.d.ts +3 -1
  326. package/dist/files/folders/FolderTreePicker.js +23 -3
  327. package/dist/files/folders/FolderTreePicker.js.map +2 -2
  328. package/dist/files/index.cjs +250 -248
  329. package/dist/files/views/gridViews.d.ts +2 -0
  330. package/dist/files/views/gridViews.js.map +2 -2
  331. package/dist/home/index.cjs +1 -1
  332. package/dist/index.cjs +139 -126
  333. package/dist/index.cjs.map +1 -1
  334. package/dist/index.d.ts +1 -1
  335. package/dist/index.js +7 -1
  336. package/dist/index.js.map +2 -2
  337. package/dist/lib/pointer-hover.d.ts +11 -0
  338. package/dist/lib/pointer-hover.js +36 -0
  339. package/dist/lib/pointer-hover.js.map +7 -0
  340. package/dist/pages/index.cjs +33 -28
  341. package/dist/pages/index.cjs.map +1 -1
  342. package/dist/settings/TriStateChips.d.ts +24 -0
  343. package/dist/settings/TriStateChips.js +124 -0
  344. package/dist/settings/TriStateChips.js.map +7 -0
  345. package/dist/settings/index.cjs +1 -1
  346. package/dist/shell/index.cjs +1 -1
  347. package/dist/site/index.cjs +33 -31
  348. package/dist/studio/index.cjs +12 -11
  349. package/dist/studio/index.cjs.map +1 -1
  350. package/dist/styles.css +1 -1
  351. package/dist/timeline/TimelineCalendar.js +2 -1
  352. package/dist/timeline/TimelineCalendar.js.map +2 -2
  353. package/dist/timeline/TimelineGantt.d.ts +6 -1
  354. package/dist/timeline/TimelineGantt.js +34 -8
  355. package/dist/timeline/TimelineGantt.js.map +2 -2
  356. package/dist/timeline/index.cjs +14 -12
  357. package/dist/workflow-canvas/index.cjs +22 -20
  358. package/dist/workflow-canvas/index.cjs.map +1 -1
  359. package/node_modules/@arbidocs/coedit/package.json +1 -1
  360. package/package.json +5 -5
  361. package/src/components/grid.css +23 -1
  362. package/dist/DocumentReviewCard-RPHIQZ2Y.cjs.map +0 -1
  363. package/dist/FilesViewerDialog-PZ5H435S.cjs.map +0 -1
  364. package/dist/ai-XIT4MY3S.cjs.map +0 -1
  365. package/dist/chunk-2D5GZMSK.cjs.map +0 -1
  366. package/dist/chunk-ADMNU2CR.cjs.map +0 -1
  367. package/dist/chunk-BQOL4XNZ.cjs.map +0 -1
  368. package/dist/chunk-CYMAF656.cjs.map +0 -1
  369. package/dist/chunk-DDWLMYRO.cjs.map +0 -1
  370. package/dist/chunk-FUKN3PI5.cjs.map +0 -1
  371. package/dist/chunk-JITYC4OS.cjs.map +0 -1
  372. package/dist/chunk-MWHVETKN.cjs.map +0 -1
  373. package/dist/chunk-MZ7IUHQA.cjs.map +0 -1
  374. package/dist/chunk-N33U2SB5.cjs.map +0 -1
  375. package/dist/chunk-TJY7XPDE.cjs.map +0 -1
  376. package/dist/chunk-TUURH4NE.cjs +0 -18
  377. package/dist/chunk-UTYEXDJK.cjs.map +0 -1
  378. package/dist/chunk-YC72ZCV4.cjs.map +0 -1
@@ -0,0 +1,1320 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { Milestone, Search, Tags } from "lucide-react";
5
+ import {
6
+ useArbiSession,
7
+ useArbiSessionStore,
8
+ useDeleteFact,
9
+ useFacts,
10
+ useSessionView,
11
+ useTransientView,
12
+ useUpdateFact,
13
+ useWorkspaceUsers,
14
+ useWorkspaces
15
+ } from "@arbidocs/react";
16
+ import { downloadBlob } from "@arbidocs/react/document-tools/core";
17
+ import { useAssistantCopy } from "@arbidocs/react/shell";
18
+ import {
19
+ DropdownMenuItem,
20
+ VisibilityToggle,
21
+ cn,
22
+ getDocumentTitle,
23
+ getEntityColor,
24
+ getEntityLabel,
25
+ getUserDisplayName,
26
+ isImageDocument,
27
+ markdownToPlainText
28
+ } from "@arbidocs/react/ui";
29
+ import { refusalReason } from "@arbidocs/sdk/browser";
30
+ import {
31
+ CALENDAR_LAYOUT,
32
+ DatabaseRowDetail,
33
+ GANTT_LAYOUT,
34
+ TABLE_LAYOUT,
35
+ formatCell
36
+ } from "../../databases/index.js";
37
+ import { applyLocalQuery } from "../../databases/local-query.js";
38
+ import { DetailHint } from "../../components/DetailPanel.js";
39
+ import { DEFAULT_FACT_SOURCES_ROW_LABELS } from "../../facts/FactComposer.js";
40
+ import { FactDateInput } from "../../facts/FactDateInput.js";
41
+ import { FactRowActions } from "../../facts/FactRowActions.js";
42
+ import { FactsBulkBar, DEFAULT_FACTS_BULK_BAR_LABELS } from "../../facts/FactsBulkBar.js";
43
+ import { FactsScopeEmpty } from "../../facts/FactsScopeEmpty.js";
44
+ import { FactsScopePicker } from "../../facts/FactsScopePicker.js";
45
+ import { docIdsOf, toFactCitations } from "../../facts/fact-citations.js";
46
+ import { decodeWhitespaceEntities } from "../../facts/fact-text.js";
47
+ import { DocumentPicker } from "../../settings/DocumentPicker.js";
48
+ import { useBlocksEnvironment } from "../../provider/environment.js";
49
+ import { useConnectedWorkspace } from "../ConnectionProvider.js";
50
+ import { CHAT_FACTS_CHAR_CAP, chatFactsTextLength } from "../chat-context/chat-facts.js";
51
+ import { useChatFacts } from "../chat-context/useChatFacts.js";
52
+ import { ConnectedExportDialog } from "../export/ConnectedExportDialog.js";
53
+ import { ConnectedFieldsManagerPanel } from "../files/fields/ConnectedFieldsManagerPanel.js";
54
+ import { openFieldsManagerIn } from "../files/fields/fields-manager-panel.js";
55
+ import { useConnectedDocuments } from "../workspaceData.js";
56
+ import { ConnectedFactsSmartSearch } from "./ConnectedFactsSmartSearch.js";
57
+ import { FactMarkdownEditor } from "./FactMarkdownEditor.js";
58
+ import {
59
+ FactsQuickFilters,
60
+ clearQuickFilters,
61
+ quickFilterCount,
62
+ quickFilterSummary
63
+ } from "./FactsQuickFilters.js";
64
+ import { sharedItemPermissions } from "./fact-permissions.js";
65
+ import { FACT_COLUMN, FACT_COLUMNS, dateCellPatch, factToRow } from "./factsRows.js";
66
+ import {
67
+ newFactTagIdsFor,
68
+ scopeIsLabelOf,
69
+ scopeLabelName,
70
+ scopeNotes,
71
+ scopeOptionsOf
72
+ } from "./factsScope.js";
73
+ import { useFactActions } from "./useFactActions.js";
74
+ import { useFactComposer } from "./useFactComposer.js";
75
+ import { useFactFilters } from "./useFactFilters.js";
76
+ import { useFactsPageView } from "./useFactsPageView.js";
77
+ import { useViewerCollector } from "./useViewerCollector.js";
78
+ import { FACTS_COMPOSE_VIEW, FACTS_DATABASE_GRID_ID, FACTS_FOCUS_VIEW } from "./view-keys.js";
79
+ const SOURCE_ID = "facts";
80
+ const NO_FACTS = [];
81
+ const NO_VIEWS = [];
82
+ const NO_FILTERS = [];
83
+ const VIEWS_KEY = "databases.views.facts";
84
+ const SEARCHED_COLUMNS = /* @__PURE__ */ new Set([
85
+ FACT_COLUMN.text,
86
+ FACT_COLUMN.labels,
87
+ FACT_COLUMN.sources
88
+ ]);
89
+ const LAYOUT_LABELS = [TABLE_LAYOUT, CALENDAR_LAYOUT, GANTT_LAYOUT].map((l) => l.label);
90
+ const CHARS_PER_TOKEN = 4;
91
+ const INLINE_DATE_RE = /^\d{4}(-\d{2})?(-\d{2})?$/;
92
+ const DEFAULT_COLUMNS = [
93
+ FACT_COLUMN.text,
94
+ FACT_COLUMN.date,
95
+ FACT_COLUMN.labels,
96
+ FACT_COLUMN.sources,
97
+ FACT_COLUMN.confirmed,
98
+ FACT_COLUMN.shared,
99
+ FACT_COLUMN.inChat
100
+ ];
101
+ const EXPORT_COLUMNS = [...DEFAULT_COLUMNS, FACT_COLUMN.createdBy, FACT_COLUMN.createdAt];
102
+ const CAPABILITIES = {
103
+ rename: false,
104
+ remove: false,
105
+ importRows: false,
106
+ export: ["csv"],
107
+ chart: false,
108
+ addColumn: false,
109
+ addRow: true,
110
+ deleteRows: true,
111
+ shareRow: false,
112
+ columnTypes: [],
113
+ query: "local",
114
+ layouts: ["table", "calendar", "gantt", "smart_search"],
115
+ rowSet: "complete"
116
+ };
117
+ const READ_ONLY_CAPABILITIES = {
118
+ ...CAPABILITIES,
119
+ addRow: false,
120
+ deleteRows: false
121
+ };
122
+ const NEW_ROW = "New row";
123
+ const LABELS = {
124
+ newRow: NEW_ROW,
125
+ rowNoun: "row",
126
+ rowNounPlural: "rows",
127
+ emptyTitle: "No rows yet",
128
+ readOnlyNote: "Read-only here: rows can only be changed in a live workspace.",
129
+ layoutEmptyMessage: "Give a row a date and it appears here.",
130
+ // The table's own line names importing a spreadsheet, which Facts has not.
131
+ emptyBody: "Add a row."
132
+ };
133
+ const CELL_TEST_ID = {
134
+ [FACT_COLUMN.text]: "text",
135
+ [FACT_COLUMN.date]: "date",
136
+ [FACT_COLUMN.inChat]: "in-chat",
137
+ [FACT_COLUMN.confirmed]: "confirmed",
138
+ [FACT_COLUMN.shared]: "shared",
139
+ [FACT_COLUMN.sources]: "sources"
140
+ };
141
+ function useFactsChat() {
142
+ const { chatFacts, chatFactIds, addFactsToChat, removeFactsFromChat } = useChatFacts();
143
+ return useMemo(
144
+ () => ({
145
+ factIds: chatFactIds,
146
+ add: addFactsToChat,
147
+ remove: removeFactsFromChat,
148
+ budget: { used: chatFactsTextLength(chatFacts), cap: CHAT_FACTS_CHAR_CAP }
149
+ }),
150
+ [chatFactIds, chatFacts, addFactsToChat, removeFactsFromChat]
151
+ );
152
+ }
153
+ function useUserLookup() {
154
+ const currentUser = useArbiSession().user;
155
+ const { data: workspaces } = useWorkspaces();
156
+ return useMemo(
157
+ () => (externalId) => {
158
+ if (!externalId) return null;
159
+ if (currentUser?.external_id === externalId) return currentUser;
160
+ for (const ws of workspaces ?? []) {
161
+ const found = ws.users?.find((wu) => wu.user.external_id === externalId);
162
+ if (found) return found.user;
163
+ }
164
+ return null;
165
+ },
166
+ [currentUser, workspaces]
167
+ );
168
+ }
169
+ const NO_LINKS = { aliases: /* @__PURE__ */ new Map(), swaps: [] };
170
+ function withAlias(links, oldId, newId) {
171
+ if (oldId === newId) return links;
172
+ let key = oldId;
173
+ for (const [k, v] of links.aliases) if (v === oldId) key = k;
174
+ if (links.aliases.get(key) === newId) return links;
175
+ const aliases = new Map(links.aliases);
176
+ aliases.set(key, newId);
177
+ return { aliases, swaps: [...links.swaps, [oldId, newId]] };
178
+ }
179
+ const csvCell = (value) => {
180
+ const safe = /^[=+\-@\t\r]/.test(value) ? `'${value}` : value;
181
+ return /[",\n\r]/.test(safe) ? `"${safe.replace(/"/g, '""')}"` : safe;
182
+ };
183
+ function savedViewsAfter(views, name, state) {
184
+ const existing = views.find((v) => v.name === name && v.mine);
185
+ if (existing) return views.map((v) => v === existing ? { ...v, state } : v);
186
+ const next = 1 + Math.max(0, ...views.map((v) => Number(/^view-(\d+)$/.exec(v.id)?.[1] ?? 0)));
187
+ return [...views, { id: `view-${next}`, name, mine: true, canDelete: true, shared: false, state }];
188
+ }
189
+ function createSelectionStore() {
190
+ let ids = [];
191
+ const listeners = /* @__PURE__ */ new Set();
192
+ return {
193
+ get: () => ids,
194
+ set(next) {
195
+ if (next.length === ids.length && next.every((id, i) => id === ids[i])) return;
196
+ ids = next;
197
+ listeners.forEach((l) => l());
198
+ },
199
+ subscribe(listener) {
200
+ listeners.add(listener);
201
+ return () => listeners.delete(listener);
202
+ }
203
+ };
204
+ }
205
+ function createFactsSource(options = {}) {
206
+ const useEntry = () => {
207
+ const { workspaceId } = useConnectedWorkspace();
208
+ const { data: facts } = useFacts(workspaceId);
209
+ const count = facts ? `${facts.length} ${facts.length === 1 ? "row" : "rows"}` : void 0;
210
+ const { name = "Facts", description, icon = Milestone } = options;
211
+ return useMemo(
212
+ () => ({ id: SOURCE_ID, name, description, icon, count, views: LAYOUT_LABELS }),
213
+ [name, description, icon, count]
214
+ );
215
+ };
216
+ const useOpen = (request) => useFactsOpen(options, request);
217
+ return { id: SOURCE_ID, useEntry, useOpen };
218
+ }
219
+ function useFactsOpen(options, request) {
220
+ const { scope = null, onScopeChange } = options;
221
+ const { notify, confirm, openDocument } = useBlocksEnvironment();
222
+ const session = useArbiSessionStore();
223
+ const pageView = useFactsPageView();
224
+ const chat = useFactsChat();
225
+ const collector = useViewerCollector();
226
+ const lookupUser = useUserLookup();
227
+ const [compose, setCompose] = useTransientView(FACTS_COMPOSE_VIEW, false);
228
+ const [focusFactId, setFocusFactId] = useTransientView(FACTS_FOCUS_VIEW, null);
229
+ const { workspaceId, live, userId } = useConnectedWorkspace();
230
+ const { data: allNotes = NO_FACTS, isLoading, isError, error, refetch } = useFacts(workspaceId);
231
+ const { data: documents } = useConnectedDocuments();
232
+ const members = useWorkspaceUsers(workspaceId ?? void 0);
233
+ const role = members.data?.find((m) => m.user.external_id === userId)?.role;
234
+ const { canChangeSharing, canRewrite } = useMemo(
235
+ () => sharedItemPermissions(userId, role),
236
+ [userId, role]
237
+ );
238
+ const editable = live;
239
+ const notes = useMemo(() => scopeNotes(allNotes, scope), [allNotes, scope]);
240
+ const actions = useFactActions(refetch);
241
+ const quickView = useMemo(() => ({ ...pageView, filterText: "", searchFields: [] }), [pageView]);
242
+ const filters = useFactFilters(notes, quickView, chat);
243
+ const scopeIsLabel = scopeIsLabelOf(scope, filters.labelTags);
244
+ const newFactTagIds = useMemo(() => newFactTagIdsFor(scope, scopeIsLabel), [scope, scopeIsLabel]);
245
+ const gridApiRef = useRef(null);
246
+ const composer = useFactComposer(
247
+ allNotes,
248
+ actions.remove,
249
+ gridApiRef,
250
+ collector,
251
+ !!compose,
252
+ () => setCompose(void 0),
253
+ workspaceId,
254
+ newFactTagIds
255
+ );
256
+ const updateFact = useUpdateFact();
257
+ const deleteFact = useDeleteFact();
258
+ const byId = useMemo(() => new Map(allNotes.map((f) => [f.external_id, f])), [allNotes]);
259
+ const [links, setLinks] = useState(NO_LINKS);
260
+ const registerAlias = useCallback(
261
+ (oldId, newId) => setLinks((l) => withAlias(l, oldId, newId)),
262
+ []
263
+ );
264
+ const keyOfId = useMemo(() => {
265
+ const reverse = /* @__PURE__ */ new Map();
266
+ for (const [key, id] of links.aliases) reverse.set(id, key);
267
+ return (id) => reverse.get(id) ?? id;
268
+ }, [links.aliases]);
269
+ const currentId = useCallback((key) => links.aliases.get(key) ?? key, [links.aliases]);
270
+ const rewording = useRef(/* @__PURE__ */ new Map());
271
+ const noteIds = useMemo(() => allNotes.map((f) => f.external_id), [allNotes]);
272
+ const idsKey = useMemo(() => noteIds.join("\n"), [noteIds]);
273
+ const [seen, setSeen] = useState(() => ({ key: idsKey, ids: noteIds }));
274
+ if (seen.key !== idsKey) {
275
+ setSeen({ key: idsKey, ids: noteIds });
276
+ const now = new Set(noteIds);
277
+ const before = new Set(seen.ids);
278
+ const gone = seen.ids.filter((id) => !now.has(id));
279
+ const fresh = noteIds.filter((id) => !before.has(id));
280
+ let matched = false;
281
+ for (const oldId of gone) {
282
+ const wanted = rewording.current.get(oldId);
283
+ if (wanted === void 0) continue;
284
+ const hits = fresh.filter((id) => byId.get(id)?.text?.trim() === wanted);
285
+ if (hits.length === 1) {
286
+ matched = true;
287
+ setLinks((l) => withAlias(l, oldId, hits[0]));
288
+ }
289
+ }
290
+ if (!matched && gone.length === 1 && fresh.length === 1 && (gone[0] === composer.editingId || fresh[0] === composer.editingId || rewording.current.has(gone[0]))) {
291
+ setLinks((l) => withAlias(l, gone[0], fresh[0]));
292
+ }
293
+ }
294
+ useEffect(() => {
295
+ for (const [from, to] of links.swaps) {
296
+ const s = session.getState();
297
+ const convKey = s.conversationId ?? "new";
298
+ const ids = s.conversationFacts[convKey] ?? [];
299
+ if (ids.includes(from) && !ids.includes(to))
300
+ session.setConversationFacts(
301
+ convKey,
302
+ ids.map((id) => id === from ? to : id)
303
+ );
304
+ }
305
+ }, [links.swaps, session]);
306
+ const openSeen = useRef(null);
307
+ const { composing, editingId, followReworded, resetComposer, deletingIdRef } = composer;
308
+ useEffect(() => {
309
+ if (!composing || !editingId) {
310
+ openSeen.current = null;
311
+ return;
312
+ }
313
+ if (byId.has(editingId)) {
314
+ openSeen.current = editingId;
315
+ return;
316
+ }
317
+ const swap = links.swaps.find(([from]) => from === editingId);
318
+ if (swap) {
319
+ followReworded(swap[0], swap[1]);
320
+ return;
321
+ }
322
+ if (openSeen.current !== editingId || rewording.current.has(editingId) || deletingIdRef.current === editingId)
323
+ return;
324
+ openSeen.current = null;
325
+ resetComposer();
326
+ notify("This fact was deleted, so its page was closed", "warning");
327
+ }, [
328
+ composing,
329
+ editingId,
330
+ byId,
331
+ links.swaps,
332
+ followReworded,
333
+ resetComposer,
334
+ deletingIdRef,
335
+ notify
336
+ ]);
337
+ const columns = useMemo(
338
+ () => editable ? FACT_COLUMNS : FACT_COLUMNS.map((c) => ({ ...c, locked: true })),
339
+ [editable]
340
+ );
341
+ const labelNames = useMemo(
342
+ () => new Map(filters.labelTags.map((t) => [t.external_id, t.name])),
343
+ [filters.labelTags]
344
+ );
345
+ const docTitles = useMemo(
346
+ () => new Map(documents.map((d) => [d.external_id, getDocumentTitle(d, d.file_name ?? void 0)])),
347
+ [documents]
348
+ );
349
+ const chatIds = useMemo(() => new Set(chat.factIds), [chat.factIds]);
350
+ const creatorName = useCallback(
351
+ (extId) => {
352
+ const user = lookupUser(extId);
353
+ return user ? getUserDisplayName(user) : null;
354
+ },
355
+ [lookupUser]
356
+ );
357
+ const rowOf = useCallback(
358
+ (f) => factToRow(f, {
359
+ key: keyOfId(f.external_id),
360
+ inChat: chatIds.has(f.external_id),
361
+ labelNames,
362
+ docTitles,
363
+ creatorName
364
+ }),
365
+ [keyOfId, chatIds, labelNames, docTitles, creatorName]
366
+ );
367
+ const [rowsEpoch, setRowsEpoch] = useState(0);
368
+ const revertRows = useCallback(() => setRowsEpoch((n) => n + 1), []);
369
+ const factRows = useMemo(
370
+ () => {
371
+ const dated = (r) => {
372
+ const d = r.values[FACT_COLUMN.date];
373
+ return typeof d === "string" && d ? d : null;
374
+ };
375
+ return filters.filteredNotes.map(rowOf).sort((a, b) => {
376
+ const da = dated(a);
377
+ const db = dated(b);
378
+ if (da === db) return 0;
379
+ if (da === null) return 1;
380
+ if (db === null) return -1;
381
+ return da < db ? -1 : 1;
382
+ });
383
+ },
384
+ // eslint-disable-next-line react-hooks/exhaustive-deps
385
+ [filters.filteredNotes, rowOf, rowsEpoch]
386
+ );
387
+ const [genericFilters, setGenericFilters] = useState(NO_FILTERS);
388
+ const search = pageView.filterText;
389
+ const rows = useMemo(
390
+ () => applyLocalQuery(
391
+ // The search reads what a fact says: its text, labels and sources, not its ids or dates.
392
+ applyLocalQuery(
393
+ factRows,
394
+ columns.filter((c) => SEARCHED_COLUMNS.has(c.id)),
395
+ { search, filters: NO_FILTERS }
396
+ ),
397
+ columns,
398
+ { search: "", filters: genericFilters }
399
+ ),
400
+ [factRows, columns, search, genericFilters]
401
+ );
402
+ const setFilterText = pageView.setFilterText;
403
+ const setQuery = useCallback(
404
+ (next) => {
405
+ if (next.search !== void 0) setFilterText(next.search);
406
+ if (next.filters !== void 0) setGenericFilters(next.filters);
407
+ },
408
+ [setFilterText]
409
+ );
410
+ const labelOptions = useMemo(
411
+ () => filters.labelTags.map((t) => ({
412
+ id: t.external_id,
413
+ name: t.name,
414
+ color: getEntityColor(t.external_id, "medium")
415
+ })),
416
+ [filters.labelTags]
417
+ );
418
+ const createTagAsync = filters.createTagStable.mutateAsync;
419
+ const documentOptions = useMemo(
420
+ () => documents.map((d) => ({ id: d.external_id, label: d.file_name || d.external_id })),
421
+ [documents]
422
+ );
423
+ const cellSources = useMemo(
424
+ () => ({
425
+ labels: {
426
+ options: labelOptions,
427
+ onCreate: async (name) => {
428
+ const created = await createTagAsync({
429
+ name,
430
+ tagType: { type: "checkbox", options: [] },
431
+ shared: true
432
+ });
433
+ return created?.external_id;
434
+ }
435
+ },
436
+ documents: documentOptions,
437
+ onOpenDocument: (docId) => openDocument(docId)
438
+ }),
439
+ [labelOptions, createTagAsync, documentOptions, openDocument]
440
+ );
441
+ const openEditIfAllowed = (fact) => {
442
+ if (!canRewrite(fact.created_by_ext_id)) {
443
+ notify(
444
+ "Only the creator or a workspace owner can reword this fact. You can still add it to the chat, label and confirm it.",
445
+ "warning"
446
+ );
447
+ return false;
448
+ }
449
+ composer.openEdit(fact);
450
+ return true;
451
+ };
452
+ const openFactById = (id) => {
453
+ const fact = byId.get(id);
454
+ if (fact) openEditIfAllowed(fact);
455
+ };
456
+ const latest = useRef({
457
+ byId,
458
+ currentId,
459
+ keyOfId,
460
+ canChangeSharing,
461
+ canRewrite,
462
+ actions,
463
+ chat,
464
+ composer,
465
+ rows,
466
+ columns,
467
+ notify,
468
+ confirm,
469
+ updateFact,
470
+ deleteFact,
471
+ registerAlias,
472
+ editable,
473
+ openFactById
474
+ });
475
+ latest.current = {
476
+ byId,
477
+ currentId,
478
+ keyOfId,
479
+ canChangeSharing,
480
+ canRewrite,
481
+ actions,
482
+ chat,
483
+ composer,
484
+ rows,
485
+ columns,
486
+ notify,
487
+ confirm,
488
+ updateFact,
489
+ deleteFact,
490
+ registerAlias,
491
+ editable,
492
+ openFactById
493
+ };
494
+ const updateCell = useCallback(
495
+ async (row, columnId, value, extra) => {
496
+ const l = latest.current;
497
+ const id = l.currentId(row.id);
498
+ const fact = l.byId.get(id);
499
+ if (!fact) {
500
+ l.notify("This fact is no longer there, so the change was not saved", "warning");
501
+ revertRows();
502
+ return;
503
+ }
504
+ switch (columnId) {
505
+ case FACT_COLUMN.confirmed:
506
+ if (!!value !== fact.confirmed && !await l.actions.toggleConfirmed(fact)) revertRows();
507
+ return;
508
+ case FACT_COLUMN.shared:
509
+ if (!l.canChangeSharing(fact.created_by_ext_id)) {
510
+ l.notify("Only the creator can change who can see this fact", "warning");
511
+ return revertRows();
512
+ }
513
+ if (!!value !== fact.shared && !await l.actions.toggleShared(fact)) revertRows();
514
+ return;
515
+ case FACT_COLUMN.labels:
516
+ try {
517
+ await l.updateFact.mutateAsync({
518
+ factId: id,
519
+ patch: { tag_ext_ids: Array.isArray(value) ? value : [] }
520
+ });
521
+ } catch (err) {
522
+ l.notify(refusalReason(err, "Could not update labels"), "error");
523
+ revertRows();
524
+ }
525
+ return;
526
+ case FACT_COLUMN.inChat:
527
+ if (value) l.chat.add([fact]);
528
+ else l.chat.remove([fact.external_id]);
529
+ return;
530
+ case FACT_COLUMN.date: {
531
+ const raw = typeof value === "string" ? value.trim() : "";
532
+ if (raw && !extra && !INLINE_DATE_RE.test(raw)) {
533
+ l.notify("Use YYYY, YYYY-MM or YYYY-MM-DD (or clear the cell)", "error");
534
+ revertRows();
535
+ throw new Error("Not a date");
536
+ }
537
+ try {
538
+ await l.updateFact.mutateAsync({ factId: id, patch: dateCellPatch(value, extra) });
539
+ l.notify(raw ? "Date updated" : "Date cleared", "success");
540
+ } catch (err) {
541
+ l.notify(refusalReason(err, "Could not update date"), "error");
542
+ revertRows();
543
+ throw err;
544
+ }
545
+ return;
546
+ }
547
+ case FACT_COLUMN.text: {
548
+ const text = String(value ?? "").trim();
549
+ if (!text || text === fact.text) return;
550
+ rewording.current.set(id, text);
551
+ try {
552
+ const saved = await l.updateFact.mutateAsync({ factId: id, patch: { text } });
553
+ if (saved?.external_id) {
554
+ l.registerAlias(id, saved.external_id);
555
+ l.composer.followReworded(id, saved.external_id);
556
+ }
557
+ l.notify("Fact updated", "success");
558
+ } catch (err) {
559
+ l.notify(refusalReason(err, "Could not update fact"), "error");
560
+ revertRows();
561
+ throw err;
562
+ } finally {
563
+ rewording.current.delete(id);
564
+ }
565
+ return;
566
+ }
567
+ case FACT_COLUMN.sources:
568
+ try {
569
+ await l.updateFact.mutateAsync({
570
+ factId: id,
571
+ patch: { citations: Array.isArray(value) ? value : [] }
572
+ });
573
+ } catch (err) {
574
+ l.notify(refusalReason(err, "Could not update sources"), "error");
575
+ throw err;
576
+ }
577
+ return;
578
+ default:
579
+ throw new Error("This column cannot be edited here");
580
+ }
581
+ },
582
+ [revertRows]
583
+ );
584
+ const isCellEditable = useCallback((row, column) => {
585
+ const l = latest.current;
586
+ if (!l.editable || column.locked) return false;
587
+ switch (column.id) {
588
+ case FACT_COLUMN.shared: {
589
+ const fact = l.byId.get(l.currentId(row.id));
590
+ return !!fact && l.canChangeSharing(fact.created_by_ext_id);
591
+ }
592
+ case FACT_COLUMN.confirmed:
593
+ case FACT_COLUMN.labels:
594
+ case FACT_COLUMN.date:
595
+ case FACT_COLUMN.inChat:
596
+ return true;
597
+ default:
598
+ return false;
599
+ }
600
+ }, []);
601
+ const canDeleteRow = useCallback((row) => {
602
+ const l = latest.current;
603
+ const fact = l.byId.get(l.currentId(row.id));
604
+ return !!fact && l.canRewrite(fact.created_by_ext_id);
605
+ }, []);
606
+ const deleteFacts = useCallback(async (facts) => {
607
+ const l = latest.current;
608
+ const count = facts.length;
609
+ if (count === 0) return;
610
+ const label = count === 1 ? "fact" : "facts";
611
+ const results = await Promise.allSettled(
612
+ facts.map((f) => l.deleteFact.mutateAsync(f.external_id))
613
+ );
614
+ const failed = results.filter((r) => r.status === "rejected").length;
615
+ if (failed === 0) l.notify(`Deleted ${count} ${label}`, "success");
616
+ else
617
+ l.notify(
618
+ `Deleted ${count - failed} of ${count} ${label} \u2014 ${failed} failed (you may not have permission)`,
619
+ "error"
620
+ );
621
+ if (failed > 0) throw new Error("Some facts could not be deleted");
622
+ }, []);
623
+ const factsOf = useCallback((selected) => {
624
+ const l = latest.current;
625
+ return selected.flatMap((r) => {
626
+ const fact = l.byId.get(l.currentId(r.id));
627
+ return fact ? [fact] : [];
628
+ });
629
+ }, []);
630
+ const deleteRows = useCallback(
631
+ async (doomed) => deleteFacts(factsOf(doomed)),
632
+ [deleteFacts, factsOf]
633
+ );
634
+ const addRow = useCallback(async () => {
635
+ const c = latest.current.composer;
636
+ if (!(c.composing && !c.editingId)) c.startNewFact();
637
+ return null;
638
+ }, []);
639
+ const clearFocus = useCallback(() => setFocusFactId(void 0), [setFocusFactId]);
640
+ const reveal = useMemo(
641
+ () => focusFactId ? { rowId: keyOfId(focusFactId), done: clearFocus } : void 0,
642
+ [focusFactId, keyOfId, clearFocus]
643
+ );
644
+ const [savedViews, setSavedViews] = useSessionView(
645
+ `${VIEWS_KEY}.${workspaceId ?? ""}`,
646
+ NO_VIEWS
647
+ );
648
+ const initialViewId = request.viewId ?? null;
649
+ const views = useMemo(
650
+ () => ({
651
+ kind: "device",
652
+ views: savedViews,
653
+ ready: true,
654
+ storesLayout: true,
655
+ initialViewId,
656
+ save: async (name, state) => setSavedViews(savedViewsAfter(savedViews, name, state)),
657
+ remove: async (id) => setSavedViews(savedViews.filter((v) => v.id !== id))
658
+ }),
659
+ [savedViews, setSavedViews, initialViewId]
660
+ );
661
+ const layouts = useMemo(
662
+ () => [
663
+ TABLE_LAYOUT,
664
+ CALENDAR_LAYOUT,
665
+ GANTT_LAYOUT,
666
+ {
667
+ id: "smart_search",
668
+ label: "Smart Search",
669
+ icon: Search,
670
+ hidesToolbarRow: true,
671
+ render: () => /* @__PURE__ */ jsx(
672
+ ConnectedFactsSmartSearch,
673
+ {
674
+ selectedFactId: latest.current.composer.editingId,
675
+ onOpenFact: (id) => latest.current.openFactById(id),
676
+ chatFactIds: latest.current.chat.factIds
677
+ }
678
+ )
679
+ }
680
+ ],
681
+ []
682
+ );
683
+ const selectionStore = useRef(null);
684
+ selectionStore.current ??= createSelectionStore();
685
+ const store = selectionStore.current;
686
+ const exportRows = useCallback(async (format) => {
687
+ if (format !== "csv") return;
688
+ const { rows: shown, columns: all } = latest.current;
689
+ const picked = EXPORT_COLUMNS.flatMap((id) => all.find((c) => c.id === id) ?? []);
690
+ const lines = [
691
+ picked.map((c) => csvCell(c.name)).join(","),
692
+ ...shown.map(
693
+ (row) => picked.map((c) => csvCell(formatCell(row.values[c.id], c.type, void 0, row.titles))).join(",")
694
+ )
695
+ ];
696
+ downloadBlob(new Blob([lines.join("\n")], { type: "text/csv;charset=utf-8" }), "facts.csv");
697
+ }, []);
698
+ const meta = useMemo(
699
+ () => ({
700
+ id: SOURCE_ID,
701
+ name: options.name ?? "Facts",
702
+ icon: options.icon ?? Milestone,
703
+ description: options.description,
704
+ editable,
705
+ rowCount: notes.length,
706
+ workspaceId: workspaceId ?? void 0
707
+ }),
708
+ [options.name, options.icon, options.description, editable, notes.length, workspaceId]
709
+ );
710
+ const testIds = useMemo(
711
+ () => ({
712
+ page: "facts-page",
713
+ layoutPrefix: "facts-layout",
714
+ calendar: "facts-calendar",
715
+ gantt: "gantt",
716
+ table: "facts-table",
717
+ grid: "facts-grid",
718
+ addRow: "facts-page-new",
719
+ back: "facts-database-back",
720
+ row: () => void 0,
721
+ cell: (columnId, row) => {
722
+ const piece = CELL_TEST_ID[columnId];
723
+ const id = row.values[FACT_COLUMN.id];
724
+ return piece && typeof id === "string" ? `facts-grid-${piece}-${id}` : void 0;
725
+ }
726
+ }),
727
+ []
728
+ );
729
+ const budget = chat.budget && chat.factIds.length > 0 ? {
730
+ tokens: Math.round(chat.budget.used / CHARS_PER_TOKEN),
731
+ cap: Math.round(chat.budget.cap / CHARS_PER_TOKEN),
732
+ isOver: chat.budget.used > chat.budget.cap
733
+ } : null;
734
+ const scopeOptions = useMemo(
735
+ () => scopeOptionsOf(filters.labelTags, allNotes),
736
+ [filters.labelTags, allNotes]
737
+ );
738
+ const openLabels = () => openFieldsManagerIn(session, "label");
739
+ const slots = {
740
+ filters: /* @__PURE__ */ jsx(
741
+ FactsFilters,
742
+ {
743
+ scopeOptions,
744
+ scope,
745
+ onScopeChange,
746
+ total: allNotes.length,
747
+ onOpenLabels: openLabels,
748
+ selection: store,
749
+ notes: allNotes,
750
+ setFactTags: actions.setFactTags
751
+ }
752
+ ),
753
+ filterMenu: {
754
+ content: /* @__PURE__ */ jsx(FactsQuickFilters, { filters }),
755
+ activeCount: quickFilterCount(filters),
756
+ clear: () => clearQuickFilters(filters),
757
+ summary: quickFilterSummary(filters) || void 0
758
+ },
759
+ menuItems: /* @__PURE__ */ jsxs(DropdownMenuItem, { onSelect: openLabels, "data-testid": "facts-tags-button", children: [
760
+ /* @__PURE__ */ jsx(Tags, { className: "size-4" }),
761
+ "Manage labels"
762
+ ] }),
763
+ selectionBar: (selected, clear) => !editable ? null : /* @__PURE__ */ jsx(
764
+ FactsBulk,
765
+ {
766
+ facts: factsOf(selected),
767
+ clear,
768
+ chat,
769
+ canChangeSharing,
770
+ setShared: async (facts, shouldShare) => {
771
+ const targets = facts.filter((m) => (m.shared ?? false) !== shouldShare);
772
+ const count = targets.length;
773
+ if (count === 0) return;
774
+ const label = count === 1 ? "fact" : "facts";
775
+ const results = await Promise.allSettled(
776
+ targets.map(
777
+ (m) => updateFact.mutateAsync({ factId: m.external_id, patch: { shared: shouldShare } })
778
+ )
779
+ );
780
+ const failed = results.filter((r) => r.status === "rejected").length;
781
+ if (failed === 0)
782
+ notify(
783
+ shouldShare ? `Shared ${count} ${label} with this workspace` : `Made ${count} ${label} private to you`,
784
+ "success"
785
+ );
786
+ else
787
+ notify(
788
+ `${shouldShare ? "Shared" : "Made private"} ${count - failed} of ${count} ${label} \u2014 ${failed} failed`,
789
+ "error"
790
+ );
791
+ },
792
+ onDelete: async (facts) => {
793
+ const count = facts.length;
794
+ if (count === 0) return;
795
+ const label = count === 1 ? "fact" : "facts";
796
+ const ok = await confirm({
797
+ message: `Delete ${count} ${label}? The assistant will no longer recall ${count === 1 ? "it" : "them"}.`,
798
+ title: `Delete ${label}`
799
+ });
800
+ if (!ok) return;
801
+ try {
802
+ await deleteFacts(facts);
803
+ } catch {
804
+ }
805
+ clear();
806
+ },
807
+ selection: store,
808
+ onOpenLabels: openLabels
809
+ }
810
+ ),
811
+ status: budget ? /* @__PURE__ */ jsx(FactsBudget, { ...budget }) : void 0,
812
+ renderRowActions: (row) => {
813
+ const fact = byId.get(currentId(row.id));
814
+ if (!editable || !fact) return null;
815
+ const factNow = () => latest.current.byId.get(latest.current.currentId(row.id));
816
+ return /* @__PURE__ */ jsx(
817
+ FactRowActions,
818
+ {
819
+ onEdit: () => {
820
+ const f = factNow();
821
+ if (f) latest.current.openFactById(f.external_id);
822
+ },
823
+ canEdit: canRewrite(fact.created_by_ext_id) !== false,
824
+ onDelete: () => {
825
+ const f = factNow();
826
+ if (f) void latest.current.actions.remove(f);
827
+ }
828
+ }
829
+ );
830
+ },
831
+ // A workspace with no facts shows the empty table, as every other database; only a label with
832
+ // no facts says so (with the way back to every fact).
833
+ emptyState: notes.length === 0 && scope ? /* @__PURE__ */ jsx(
834
+ FactsScopeEmpty,
835
+ {
836
+ label: scopeLabelName(scopeOptions, scope),
837
+ onNewFact: composer.startNewFact,
838
+ onShowAll: onScopeChange ? () => onScopeChange(null) : void 0
839
+ }
840
+ ) : void 0,
841
+ renderRowPage: (ctx) => /* @__PURE__ */ jsx(
842
+ FactsRowPage,
843
+ {
844
+ row: ctx.row,
845
+ close: ctx.close,
846
+ composer,
847
+ actions,
848
+ collector,
849
+ documents,
850
+ currentId,
851
+ keyOfId,
852
+ isRewording: () => rewording.current.size > 0,
853
+ byId,
854
+ openEditIfAllowed,
855
+ columns,
856
+ cellSources,
857
+ rowOf,
858
+ updateCell,
859
+ canChangeSharing
860
+ }
861
+ )
862
+ };
863
+ if (!workspaceId || isLoading) return { status: "loading" };
864
+ if (isError && allNotes === NO_FACTS)
865
+ return {
866
+ status: "error",
867
+ error: error instanceof Error ? error : new Error("Could not load facts")
868
+ };
869
+ const source = {
870
+ meta,
871
+ capabilities: editable ? CAPABILITIES : READ_ONLY_CAPABILITIES,
872
+ columns,
873
+ data: { rows, total: rows.length, isLoading: false, truncated: false },
874
+ query: { search, filters: genericFilters },
875
+ setQuery,
876
+ cellSources,
877
+ updateCell,
878
+ isCellEditable,
879
+ ...editable ? { addRow, deleteRows, canDeleteRow } : {},
880
+ exportRows,
881
+ ...reveal ? { reveal } : {},
882
+ views,
883
+ layouts,
884
+ slots,
885
+ testIds,
886
+ gridId: FACTS_DATABASE_GRID_ID,
887
+ defaultColumns: DEFAULT_COLUMNS,
888
+ labels: LABELS
889
+ };
890
+ return { status: "ready", source };
891
+ }
892
+ function FactsBudget({ tokens, cap, isOver }) {
893
+ const assistant = useAssistantCopy();
894
+ return /* @__PURE__ */ jsx(
895
+ "span",
896
+ {
897
+ className: cn(
898
+ "shrink-0 text-xs tabular-nums",
899
+ isOver ? "text-destructive" : "text-muted-foreground"
900
+ ),
901
+ title: assistant.factsBudgetHint,
902
+ "data-testid": "facts-page-chat-budget",
903
+ children: DEFAULT_FACTS_BULK_BAR_LABELS.budget(tokens.toLocaleString(), cap.toLocaleString())
904
+ }
905
+ );
906
+ }
907
+ function FactsFilters({
908
+ scopeOptions,
909
+ scope,
910
+ onScopeChange,
911
+ total,
912
+ onOpenLabels,
913
+ selection,
914
+ notes,
915
+ setFactTags
916
+ }) {
917
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
918
+ onScopeChange && scope && /* @__PURE__ */ jsx(
919
+ FactsScopePicker,
920
+ {
921
+ options: scopeOptions,
922
+ total,
923
+ value: scope,
924
+ onChange: onScopeChange,
925
+ onManage: onOpenLabels,
926
+ className: "h-7 gap-1.5 px-2 text-sm font-normal text-foreground pointer-coarse:h-11"
927
+ }
928
+ ),
929
+ /* @__PURE__ */ jsx(FactsLabelsPanel, { selection, notes, setFactTags })
930
+ ] });
931
+ }
932
+ function FactsLabelsPanel({
933
+ selection,
934
+ notes,
935
+ setFactTags
936
+ }) {
937
+ const [ids, setIds] = useState(selection.get());
938
+ useEffect(() => {
939
+ setIds(selection.get());
940
+ return selection.subscribe(() => setIds(selection.get()));
941
+ }, [selection]);
942
+ const target = useMemo(() => {
943
+ const chosen = notes.filter((n) => ids.includes(n.external_id));
944
+ return {
945
+ noun: { singular: "fact", plural: "facts" },
946
+ ids: chosen.map((f) => f.external_id),
947
+ countFor: (tagId) => notes.filter((n) => n.tags.some((t) => t.tag_ext_id === tagId)).length,
948
+ apply: async (tagIds) => {
949
+ for (const f of chosen) {
950
+ const have = new Set(f.tags.map((t) => t.tag_ext_id));
951
+ const next = [...have, ...tagIds.filter((id) => !have.has(id))];
952
+ if (next.length !== have.size) await setFactTags(f, next);
953
+ }
954
+ },
955
+ clear: async (tagIds) => {
956
+ const drop = new Set(tagIds);
957
+ for (const f of chosen) {
958
+ const next = f.tags.map((t) => t.tag_ext_id).filter((id) => !drop.has(id));
959
+ if (next.length !== f.tags.length) await setFactTags(f, next);
960
+ }
961
+ }
962
+ };
963
+ }, [ids, notes, setFactTags]);
964
+ return /* @__PURE__ */ jsx(ConnectedFieldsManagerPanel, { target, labelsOnly: true, scope: "fact" });
965
+ }
966
+ function FactsBulk({
967
+ facts,
968
+ clear,
969
+ chat,
970
+ canChangeSharing,
971
+ setShared,
972
+ onDelete,
973
+ selection,
974
+ onOpenLabels
975
+ }) {
976
+ const [isExportOpen, setIsExportOpen] = useState(false);
977
+ const ids = facts.map((f) => f.external_id);
978
+ const idsKey = ids.join("\n");
979
+ useEffect(() => {
980
+ selection.set(idsKey ? idsKey.split("\n") : []);
981
+ return () => selection.set([]);
982
+ }, [selection, idsKey]);
983
+ const inChat = new Set(chat.factIds);
984
+ const allSelectedInChat = facts.length > 0 && facts.every((f) => inChat.has(f.external_id));
985
+ const exportItems = facts.map((f) => ({
986
+ extId: f.external_id,
987
+ label: f.text?.trim() || f.external_id
988
+ }));
989
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
990
+ /* @__PURE__ */ jsx(
991
+ FactsBulkBar,
992
+ {
993
+ count: facts.length,
994
+ onClear: clear,
995
+ allSelectedInChat,
996
+ onToggleInChat: () => {
997
+ if (facts.length === 0) return;
998
+ const changed = allSelectedInChat ? chat.remove(ids) : chat.add(facts);
999
+ if (changed > 0) clear();
1000
+ },
1001
+ onLabel: onOpenLabels,
1002
+ sharedToggle: /* @__PURE__ */ jsx(
1003
+ VisibilityToggle,
1004
+ {
1005
+ items: facts,
1006
+ onToggle: (shouldShare) => void setShared(facts, shouldShare),
1007
+ disabled: facts.length === 0 || !facts.every((f) => canChangeSharing(f.created_by_ext_id)),
1008
+ disabledTooltip: "Only the creator can change who can see this",
1009
+ showLabel: false,
1010
+ tooltipActive: "Shared with this workspace \u2014 click to make the selected facts private",
1011
+ tooltipInactive: "Private \u2014 click to share the selected facts with this workspace",
1012
+ "data-testid": "bulk-shared-facts-toggle"
1013
+ }
1014
+ ),
1015
+ onExport: () => setIsExportOpen(true),
1016
+ onDelete: () => void onDelete(facts),
1017
+ pluralNoun: "facts",
1018
+ budget: null
1019
+ }
1020
+ ),
1021
+ /* @__PURE__ */ jsx(
1022
+ ConnectedExportDialog,
1023
+ {
1024
+ open: isExportOpen,
1025
+ onOpenChange: setIsExportOpen,
1026
+ items: exportItems,
1027
+ entityType: "FACT",
1028
+ entityLabelPlural: getEntityLabel("FACT", "PLURAL"),
1029
+ testId: "export-facts-modal"
1030
+ }
1031
+ )
1032
+ ] });
1033
+ }
1034
+ const PAGE_COLUMNS = [
1035
+ FACT_COLUMN.text,
1036
+ FACT_COLUMN.date,
1037
+ FACT_COLUMN.labels,
1038
+ FACT_COLUMN.sources,
1039
+ FACT_COLUMN.confirmed,
1040
+ FACT_COLUMN.shared,
1041
+ FACT_COLUMN.inChat,
1042
+ FACT_COLUMN.createdBy,
1043
+ FACT_COLUMN.createdAt,
1044
+ FACT_COLUMN.updatedAt
1045
+ ];
1046
+ const WRITTEN_COLUMNS = /* @__PURE__ */ new Set([
1047
+ FACT_COLUMN.text,
1048
+ FACT_COLUMN.date,
1049
+ FACT_COLUMN.labels,
1050
+ FACT_COLUMN.sources,
1051
+ FACT_COLUMN.confirmed,
1052
+ FACT_COLUMN.shared
1053
+ ]);
1054
+ const NEW_ROW_ID = "fact:new";
1055
+ const SOURCES_SAVE_DELAY = 800;
1056
+ const PAGE_TEST_ID = "facts-page-composer";
1057
+ function FactsRowPage({
1058
+ row,
1059
+ close,
1060
+ composer,
1061
+ actions,
1062
+ collector,
1063
+ documents,
1064
+ currentId,
1065
+ keyOfId,
1066
+ isRewording,
1067
+ byId,
1068
+ openEditIfAllowed,
1069
+ columns,
1070
+ cellSources,
1071
+ rowOf,
1072
+ updateCell,
1073
+ canChangeSharing
1074
+ }) {
1075
+ const rowId = row?.id;
1076
+ const shownRow = useRef(false);
1077
+ useEffect(() => {
1078
+ shownRow.current = false;
1079
+ if (!rowId) return;
1080
+ const id = currentId(rowId);
1081
+ if (composer.composing && composer.editingId === id) return;
1082
+ const fact2 = byId.get(id);
1083
+ if (fact2 && !openEditIfAllowed(fact2)) close();
1084
+ }, [rowId]);
1085
+ useEffect(() => {
1086
+ if (!rowId) return;
1087
+ const id = composer.editingId;
1088
+ if (composer.composing && id && (id === currentId(rowId) || keyOfId(id) === rowId)) {
1089
+ shownRow.current = true;
1090
+ return;
1091
+ }
1092
+ if (!shownRow.current || isRewording()) return;
1093
+ shownRow.current = false;
1094
+ close();
1095
+ }, [rowId, composer.composing, composer.editingId]);
1096
+ const [panel, setPanel] = useState(null);
1097
+ const shown = useRef(null);
1098
+ const [pending, setPending] = useState({});
1099
+ const savedRow = shown.current?.row;
1100
+ const isSaved = !!composer.editingId;
1101
+ const citationsKey = JSON.stringify(composer.draftCitations ?? null);
1102
+ const sourcesBase = useRef({ stage: "", key: citationsKey });
1103
+ const stage = `${composer.composerSession}:${isSaved}`;
1104
+ if (sourcesBase.current.stage !== stage) sourcesBase.current = { stage, key: citationsKey };
1105
+ const sourcesChanged = isSaved && sourcesBase.current.key !== citationsKey;
1106
+ useEffect(() => {
1107
+ if (!sourcesChanged || !savedRow) return;
1108
+ const timer = setTimeout(() => {
1109
+ sourcesBase.current = { stage, key: citationsKey };
1110
+ void updateCell(savedRow, FACT_COLUMN.sources, composer.draftCitations ?? []).catch(
1111
+ () => void 0
1112
+ );
1113
+ }, SOURCES_SAVE_DELAY);
1114
+ return () => clearTimeout(timer);
1115
+ }, [sourcesChanged, citationsKey, stage]);
1116
+ const citedDocs = useMemo(() => {
1117
+ const wanted = new Set(docIdsOf(toFactCitations(composer.draftCitations)));
1118
+ return Object.fromEntries(
1119
+ documents.filter((d) => wanted.has(d.external_id)).map((d) => [d.external_id, d])
1120
+ );
1121
+ }, [composer.draftCitations, documents]);
1122
+ const pickerGroups = useMemo(
1123
+ () => [
1124
+ {
1125
+ id: "all",
1126
+ heading: "In this workspace",
1127
+ docs: documents.filter((d) => !d.parent_ext_id).map((d) => ({
1128
+ id: d.external_id,
1129
+ title: getDocumentTitle(d, d.file_name ?? void 0),
1130
+ fileName: d.file_name,
1131
+ pages: isImageDocument(d) ? null : d.n_pages ?? null,
1132
+ tokens: isImageDocument(d) ? null : d.tokens ?? null
1133
+ })).sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()))
1134
+ }
1135
+ ],
1136
+ [documents]
1137
+ );
1138
+ if (!composer.composing) return null;
1139
+ const fact = composer.editingId ? byId.get(composer.editingId) : void 0;
1140
+ if (fact) shown.current = { session: composer.composerSession, row: rowOf(fact) };
1141
+ else if (!composer.editingId || shown.current?.session !== composer.composerSession)
1142
+ shown.current = null;
1143
+ const saved = shown.current?.row;
1144
+ const creator = saved?.values[FACT_COLUMN.createdBy];
1145
+ const sharingLocked = !!saved && !canChangeSharing(typeof creator === "string" ? creator : null);
1146
+ const pageColumns = PAGE_COLUMNS.flatMap((id) => {
1147
+ const column = columns.find((c) => c.id === id);
1148
+ if (!column || !saved && !WRITTEN_COLUMNS.has(id)) return [];
1149
+ return [id === FACT_COLUMN.shared && sharingLocked ? { ...column, locked: true } : column];
1150
+ });
1151
+ const pageRow = saved ? { ...saved, values: { ...saved.values, ...pending } } : {
1152
+ id: NEW_ROW_ID,
1153
+ values: {
1154
+ [FACT_COLUMN.labels]: composer.draftTagIds,
1155
+ [FACT_COLUMN.confirmed]: composer.draftConfirmed,
1156
+ [FACT_COLUMN.shared]: composer.draftShared
1157
+ }
1158
+ };
1159
+ const changeField = (_row, columnId, value, extra) => {
1160
+ if (saved) {
1161
+ const shownNow = { [columnId]: value, ...extra };
1162
+ setPending((p) => ({ ...p, ...shownNow }));
1163
+ void (extra ? updateCell(saved, columnId, value, extra) : updateCell(saved, columnId, value)).catch(() => void 0).finally(
1164
+ () => setPending(
1165
+ (p) => Object.fromEntries(Object.entries(p).filter(([id]) => !(id in shownNow)))
1166
+ )
1167
+ );
1168
+ } else if (columnId === FACT_COLUMN.labels) {
1169
+ composer.setDraftTagIds(Array.isArray(value) ? value : []);
1170
+ } else if (columnId === FACT_COLUMN.confirmed) {
1171
+ composer.setDraftConfirmed(value === true);
1172
+ } else if (columnId === FACT_COLUMN.shared) {
1173
+ composer.setDraftShared(value === true);
1174
+ }
1175
+ };
1176
+ const leaveText = () => {
1177
+ if (!isSaved) {
1178
+ if (composer.draft.trim() && !composer.isSaving) void composer.saveComposer();
1179
+ return;
1180
+ }
1181
+ if (!saved || !composer.textDirty) return;
1182
+ const text = decodeWhitespaceEntities(composer.draft).trim();
1183
+ if (!text) {
1184
+ if (fact) composer.openEdit(fact);
1185
+ return;
1186
+ }
1187
+ void updateCell(saved, FACT_COLUMN.text, text).catch(() => void 0);
1188
+ };
1189
+ const cancel = () => {
1190
+ shownRow.current = false;
1191
+ composer.resetComposer();
1192
+ close();
1193
+ };
1194
+ const title = composer.editingId ? markdownToPlainText(String(saved?.values[FACT_COLUMN.text] ?? composer.draft)) : NEW_ROW;
1195
+ const fieldOf = (column, parts) => {
1196
+ switch (column.id) {
1197
+ case FACT_COLUMN.text:
1198
+ return { content: parts.editor, wide: true };
1199
+ case FACT_COLUMN.sources:
1200
+ return {
1201
+ content: parts.sources,
1202
+ wide: true,
1203
+ hint: /* @__PURE__ */ jsx(
1204
+ DetailHint,
1205
+ {
1206
+ label: DEFAULT_FACT_SOURCES_ROW_LABELS.hintButton,
1207
+ testId: "facts-source-hint",
1208
+ children: DEFAULT_FACT_SOURCES_ROW_LABELS.hint
1209
+ }
1210
+ )
1211
+ };
1212
+ case FACT_COLUMN.date:
1213
+ return saved ? void 0 : {
1214
+ content: /* @__PURE__ */ jsx(
1215
+ FactDateInput,
1216
+ {
1217
+ value: composer.draftDateFields,
1218
+ onChange: composer.setDraftDateFields,
1219
+ idPrefix: PAGE_TEST_ID
1220
+ }
1221
+ )
1222
+ };
1223
+ case FACT_COLUMN.confirmed:
1224
+ return {
1225
+ hint: /* @__PURE__ */ jsx(DetailHint, { label: "About Verified", children: "Ticked: a person has checked this fact." })
1226
+ };
1227
+ case FACT_COLUMN.shared:
1228
+ return {
1229
+ hint: /* @__PURE__ */ jsxs(DetailHint, { label: "About Sharing", children: [
1230
+ "Ticked: everyone in this workspace can see this fact. Not ticked: only you and your agents can.",
1231
+ sharingLocked ? " Only its creator can change this." : ""
1232
+ ] })
1233
+ };
1234
+ case FACT_COLUMN.inChat:
1235
+ return {
1236
+ hint: /* @__PURE__ */ jsx(DetailHint, { label: "About In chat", children: "Ticked: the open chat can use this fact." })
1237
+ };
1238
+ default:
1239
+ return void 0;
1240
+ }
1241
+ };
1242
+ return /* @__PURE__ */ jsx(
1243
+ "div",
1244
+ {
1245
+ ref: setPanel,
1246
+ className: "absolute inset-0 z-10 flex flex-col overflow-hidden rounded-lg border border-border md:static md:w-(--database-panel-width,420px) md:shrink-0",
1247
+ children: /* @__PURE__ */ jsx(
1248
+ FactMarkdownEditor,
1249
+ {
1250
+ resizable: true,
1251
+ editorKey: String(composer.composerSession),
1252
+ value: composer.draft,
1253
+ citations: composer.draftCitations,
1254
+ onChange: (text, citations) => {
1255
+ composer.setDraft(text);
1256
+ composer.setDraftCitations(citations);
1257
+ },
1258
+ onNormalized: composer.setBaselineText,
1259
+ onCiteDocument: (docExtId, opts) => composer.citeDocument(docExtId, composer.DRAFT_TARGET, opts),
1260
+ collector: { ...collector, collect: composer.setSourceCitationSession },
1261
+ citedDocs,
1262
+ viewingDocId: composer.displayedDocId,
1263
+ reserveSourcesSpace: false,
1264
+ citationContainer: panel,
1265
+ onLeave: leaveText,
1266
+ inlineSources: true,
1267
+ renderDocumentPicker: (onSelect, selectedIds, onOpen, sourcesToggle, sourcesOpen) => /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-wrap items-start gap-2", children: [
1268
+ sourcesToggle,
1269
+ /* @__PURE__ */ jsx("div", { className: "min-w-40 flex-1", children: /* @__PURE__ */ jsx(
1270
+ DocumentPicker,
1271
+ {
1272
+ groups: pickerGroups,
1273
+ value: "",
1274
+ onValueChange: onSelect,
1275
+ selectedIds,
1276
+ onOpenDocument: onOpen,
1277
+ viewingId: composer.displayedDocId,
1278
+ forceClosed: sourcesOpen,
1279
+ labels: { placeholder: "Search documents\u2026" }
1280
+ }
1281
+ ) })
1282
+ ] }),
1283
+ layout: (parts) => /* @__PURE__ */ jsx(
1284
+ DatabaseRowDetail,
1285
+ {
1286
+ row: pageRow,
1287
+ columns: pageColumns,
1288
+ title: /* @__PURE__ */ jsx("span", { className: "block truncate", title, children: title }),
1289
+ renderField: (column) => fieldOf(column, parts),
1290
+ sources: cellSources,
1291
+ onChange: changeField,
1292
+ onDelete: saved ? () => void composer.deleteEditingFact().then((deleted) => {
1293
+ if (!deleted) return;
1294
+ shownRow.current = false;
1295
+ close();
1296
+ }) : void 0,
1297
+ isDeleting: actions.isDeleting,
1298
+ onClose: cancel,
1299
+ className: "min-h-0 flex-1",
1300
+ testId: PAGE_TEST_ID,
1301
+ footer: !isSaved && composer.composerError ? /* @__PURE__ */ jsx(
1302
+ "p",
1303
+ {
1304
+ className: "text-xs text-destructive",
1305
+ role: "alert",
1306
+ "data-testid": `${PAGE_TEST_ID}-error`,
1307
+ children: composer.composerError
1308
+ }
1309
+ ) : void 0
1310
+ }
1311
+ )
1312
+ }
1313
+ )
1314
+ }
1315
+ );
1316
+ }
1317
+ export {
1318
+ createFactsSource
1319
+ };
1320
+ //# sourceMappingURL=factsSource.js.map