@protobase/ui 0.117.2 → 0.117.3

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 (219) hide show
  1. package/dist/account/messages.d.ts +2 -2
  2. package/dist/app/change-confirm/messages.d.ts +2 -2
  3. package/dist/app/charts/messages.d.ts +2 -2
  4. package/dist/app/confirm-sign-in-messages.d.ts +2 -2
  5. package/dist/app/conversation/messages.d.ts +2 -2
  6. package/dist/app/create/messages.d.ts +2 -2
  7. package/dist/app/delete/messages.d.ts +2 -2
  8. package/dist/app/displays/messages.d.ts +2 -2
  9. package/dist/app/embedded-list/messages.d.ts +2 -2
  10. package/dist/app/export/messages.d.ts +2 -2
  11. package/dist/app/field-messages.d.ts +2 -2
  12. package/dist/app/field-types/json/messages.d.ts +2 -2
  13. package/dist/app/field-types/runner-install/messages.d.ts +2 -2
  14. package/dist/app/field-types/workflow/definition.d.ts +1 -1
  15. package/dist/app/field-types/workflow/messages.d.ts +2 -2
  16. package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
  17. package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
  18. package/dist/app/file-viewers/messages.d.ts +2 -2
  19. package/dist/app/focus/messages.d.ts +2 -2
  20. package/dist/app/gallery/gallery-layout.d.ts +2 -2
  21. package/dist/app/gallery/messages.d.ts +2 -2
  22. package/dist/app/hand-order/messages.d.ts +2 -2
  23. package/dist/app/history/messages.d.ts +2 -2
  24. package/dist/app/import/messages.d.ts +2 -2
  25. package/dist/app/list-messages.d.ts +2 -2
  26. package/dist/app/messages.d.ts +2 -2
  27. package/dist/app/meta-gate-messages.d.ts +2 -2
  28. package/dist/app/new-version/messages.d.ts +2 -2
  29. package/dist/app/pages/guide/billing-config.d.ts +1 -1
  30. package/dist/app/pages/guide/billing-views.d.ts +1 -1
  31. package/dist/app/pages/messages.d.ts +2 -2
  32. package/dist/app/record-chart/messages.d.ts +2 -2
  33. package/dist/app/record-messages.d.ts +2 -2
  34. package/dist/app/record-row/messages.d.ts +2 -2
  35. package/dist/app/related-cards/messages.d.ts +2 -2
  36. package/dist/app/saved/messages.d.ts +2 -2
  37. package/dist/app/search/messages.d.ts +2 -2
  38. package/dist/app/searches/messages.d.ts +2 -2
  39. package/dist/app-shell/account-entry.js +1 -1
  40. package/dist/app-shell/app-shell.js +6 -5
  41. package/dist/app-shell/brand-bar.d.ts +4 -3
  42. package/dist/app-shell/brand-bar.js +4 -3
  43. package/dist/app-shell/drawer.js +6 -1
  44. package/dist/app-shell/leading-slot.d.ts +6 -2
  45. package/dist/app-shell/leading-slot.js +6 -2
  46. package/dist/app-shell/messages.d.ts +2 -2
  47. package/dist/app-shell/more-page.d.ts +6 -0
  48. package/dist/app-shell/more-page.js +7 -1
  49. package/dist/app-shell/profile-menu.js +6 -5
  50. package/dist/app-shell/top-bar.js +2 -2
  51. package/dist/assistant-dock/messages.d.ts +2 -2
  52. package/dist/auth/messages.d.ts +2 -2
  53. package/dist/calls/messages.d.ts +2 -2
  54. package/dist/chat/messages.d.ts +2 -2
  55. package/dist/compact-table/messages.d.ts +2 -2
  56. package/dist/data-grid/messages.d.ts +2 -2
  57. package/dist/filter-panel/messages.d.ts +2 -2
  58. package/dist/invitations/messages.d.ts +2 -2
  59. package/dist/live/messages.d.ts +2 -2
  60. package/dist/mentions/messages.d.ts +2 -2
  61. package/dist/mocks/orders.d.ts +2 -2
  62. package/dist/notifications/bell/messages.d.ts +2 -2
  63. package/dist/organizations/messages.d.ts +2 -2
  64. package/dist/package.js +1 -1
  65. package/dist/plugins/messages.d.ts +2 -2
  66. package/dist/primitives/avatar.js +3 -2
  67. package/dist/primitives/menu-surface.d.ts +2 -2
  68. package/dist/primitives/menu-surface.js +3 -2
  69. package/dist/primitives/popover-menu.js +1 -0
  70. package/dist/primitives/segmented.js +4 -3
  71. package/dist/primitives/sheet.d.ts +6 -1
  72. package/dist/primitives/sheet.js +19 -23
  73. package/dist/record-view/messages.d.ts +2 -2
  74. package/dist/shell/assets/{account-page-U7RldneI.js → account-page-CnXeVG2Y.js} +2 -2
  75. package/dist/shell/assets/{app-94a88jzE.js → app-Dhno5n-x.js} +11 -11
  76. package/dist/shell/assets/app-Dq5eubgK.css +2 -0
  77. package/dist/shell/assets/{assistant-shell-BJWCAwCu.js → assistant-shell-CiBgXc2G.js} +2 -2
  78. package/dist/shell/assets/{board-display-DSazq67h.js → board-display-CbDhUr3M.js} +2 -2
  79. package/dist/shell/assets/{calendar-display-CpqjM4oV.js → calendar-display-DYCeXWel.js} +2 -2
  80. package/dist/shell/assets/{call-rings-DnL8InVq.js → call-rings-DasjTYQQ.js} +2 -2
  81. package/dist/shell/assets/{calls-CTRygR5f.js → calls-CK0S2A1I.js} +2 -2
  82. package/dist/shell/assets/{circle-alert-B63XjMgn.js → circle-alert-DsS_wh95.js} +2 -2
  83. package/dist/shell/assets/{composed-page-BVm_6eWU.js → composed-page-DR1_Pmnm.js} +2 -2
  84. package/dist/shell/assets/{composer-section-DETU2Obd.js → composer-section-Drni_iH0.js} +2 -2
  85. package/dist/shell/assets/{connect-route-BILeY04q.js → connect-route-CWqZ4ZdQ.js} +2 -2
  86. package/dist/shell/assets/{copy-field-CmFjZmVI.js → copy-field-BEMhQB0i.js} +2 -2
  87. package/dist/shell/assets/{create-route-BT69PwsI.js → create-route-DcR4vO0R.js} +2 -2
  88. package/dist/shell/assets/{custom-step-container-field-CZDuNAGK.js → custom-step-container-field-CQNLXPAV.js} +2 -2
  89. package/dist/shell/assets/{embedded-list-C9U2ypuX.js → embedded-list-CUUg5UdE.js} +3 -3
  90. package/dist/shell/assets/{export-dialog-DoaQ8h-M.js → export-dialog-BF7ErysJ.js} +2 -2
  91. package/dist/shell/assets/{graph-view-COd5Mp2P.js → graph-view-CYY1Wxfn.js} +2 -2
  92. package/dist/shell/assets/{group-donut-DUBQuhYa.js → group-donut-BrPYdLB4.js} +2 -2
  93. package/dist/shell/assets/{guest-call-page-Bu41Ptk4.js → guest-call-page-vE_LtZb2.js} +3 -3
  94. package/dist/shell/assets/{html-viewer-Bz3ots0-.js → html-viewer-d5JaZY_d.js} +2 -2
  95. package/dist/shell/assets/{import-dialog-B0lJXEBq.js → import-dialog-Cwopdvpl.js} +2 -2
  96. package/dist/shell/assets/{import-table-dialog-CaZameXo.js → import-table-dialog-iJiIRDzs.js} +2 -2
  97. package/dist/shell/assets/{index-YZpQ8sMq.js → index-FlDNHH-7.js} +1 -1
  98. package/dist/shell/assets/{invitations-page-DPzcVGHk.js → invitations-page-C7lvsotm.js} +2 -2
  99. package/dist/shell/assets/{layout-grid-hoLv1QVh.js → layout-grid-CMNfsxPk.js} +2 -2
  100. package/dist/shell/assets/{legend-item-CU6Kt-GZ.js → legend-item-CcZfSPqr.js} +2 -2
  101. package/dist/shell/assets/{list-page-C8Z3OhmV.js → list-page-C1SSeT_l.js} +4 -4
  102. package/dist/shell/assets/{maplibre-BOVzS79J.js → maplibre-CZgGye8n.js} +2 -2
  103. package/dist/shell/assets/{markdown-content-BMDl_vl_.js → markdown-content-DqspuxI3.js} +2 -2
  104. package/dist/shell/assets/{members-page-O752tFj8.js → members-page-BFe1wo7t.js} +2 -2
  105. package/dist/shell/assets/{messages-TLh-JbDm.js → messages-Djmoh5Qy.js} +2 -2
  106. package/dist/shell/assets/{organization-page-DDwBkk8F.js → organization-page-BS5CBM7T.js} +2 -2
  107. package/dist/shell/assets/{organizations-page-DNYezYgw.js → organizations-page-D-2TFpDm.js} +2 -2
  108. package/dist/shell/assets/{pending-invitation-row-DRjEfn76.js → pending-invitation-row-MW_m7ClO.js} +2 -2
  109. package/dist/shell/assets/{period-chart-B_Vtp_OD.js → period-chart-D5Gmfn_N.js} +2 -2
  110. package/dist/shell/assets/{person-row-ehgAozYT.js → person-row-DixR2c5_.js} +2 -2
  111. package/dist/shell/assets/{public-form-page-JM_r4BIq.js → public-form-page-BD-0Pq4m.js} +2 -2
  112. package/dist/shell/assets/{record-lines-B8maPngL.js → record-lines-C61HlpSx.js} +2 -2
  113. package/dist/shell/assets/{record-map-BJI9HhZO.js → record-map-C-VFW3uK.js} +2 -2
  114. package/dist/shell/assets/{record-opens-BP2LRuAM.js → record-opens-0Hwj29eY.js} +2 -2
  115. package/dist/shell/assets/{record-page-DsLORKNo.js → record-page-DSlsKtND.js} +3 -3
  116. package/dist/shell/assets/{record-preview-BDMeb9qp.js → record-preview-9gB2HCqq.js} +2 -2
  117. package/dist/shell/assets/{records-map-D2IAAn9Z.js → records-map-CHzxxjrz.js} +2 -2
  118. package/dist/shell/assets/{render-node-CAL7-6hf.js → render-node-Bx2j3Z9N.js} +3 -3
  119. package/dist/shell/assets/{reorder-button-D9hO_nqd.js → reorder-button-BbnTcDWe.js} +2 -2
  120. package/dist/shell/assets/{run-trace-view-CqCld741.js → run-trace-view-BFoZdUL_.js} +2 -2
  121. package/dist/shell/assets/{runner-install-field-Cpd0yW2w.js → runner-install-field-oUIwmXJr.js} +2 -2
  122. package/dist/shell/assets/{runtime-update-Cg98ENel.js → runtime-update-C_nVK-Ib.js} +2 -2
  123. package/dist/shell/assets/{shared-protobase-ui-JVA65IEp.js → shared-protobase-ui-DK57grt-.js} +1 -1
  124. package/dist/shell/assets/{sheet-source-fKebPN-3.js → sheet-source-DPrt_4fp.js} +2 -2
  125. package/dist/shell/assets/{sign-in-policy-page-DtxdycdZ.js → sign-in-policy-page-OkYaQyjd.js} +2 -2
  126. package/dist/shell/assets/{start-block-queries-DIJZ-fEE.js → start-block-queries-BEWBUhWg.js} +2 -2
  127. package/dist/shell/assets/{step-catalog-DefIkvlp.js → step-catalog-B37ubHh0.js} +2 -2
  128. package/dist/shell/assets/{step-panel-DhFvGljv.js → step-panel-CLYTTuEx.js} +2 -2
  129. package/dist/shell/assets/{timeline-display-CsGry__i.js → timeline-display-Be98AAvH.js} +2 -2
  130. package/dist/shell/assets/{trash-B3Zy6Kx1.js → trash-B3AS7MZB.js} +2 -2
  131. package/dist/shell/assets/{update-set-C_skfvwV.js → update-set-LOqKj6_s.js} +2 -2
  132. package/dist/shell/assets/{use-calendar-move-CZtjDwpL.js → use-calendar-move-tAYNZeaf.js} +2 -2
  133. package/dist/shell/assets/{use-display-rows-DHVZ49lA.js → use-display-rows-BNTGJCuA.js} +2 -2
  134. package/dist/shell/assets/{use-paged-search-COK4rUdF.js → use-paged-search-zW8DC14J.js} +2 -2
  135. package/dist/shell/assets/{use-run-trace-CRPYmppF.js → use-run-trace-BfNKHhse.js} +2 -2
  136. package/dist/shell/assets/{use-workflow-page-NQnBpQBn.js → use-workflow-page-gk8rhqQH.js} +2 -2
  137. package/dist/shell/assets/{use-workflow-types-BONTV-ip.js → use-workflow-types-BY3B_Oaj.js} +2 -2
  138. package/dist/shell/assets/{workflow-canvas-wK7am90B.js → workflow-canvas-D2uLwFrs.js} +2 -2
  139. package/dist/shell/assets/{workflow-field-D4NB5B1z.js → workflow-field-QMvj5PMy.js} +3 -3
  140. package/dist/shell/assets/{workflow-graph-editor-CBPqhazd.js → workflow-graph-editor-DX7BUqLb.js} +2 -2
  141. package/dist/shell/assets/{workflow-run-field-C1N-mmHl.js → workflow-run-field-DF95Gx_P.js} +3 -3
  142. package/dist/shell/assets/{workflow-status-field-DEgDvkpV.js → workflow-status-field-COisBbne.js} +2 -2
  143. package/dist/shell/assets/{workflow-workbench-mJR1exSe.js → workflow-workbench-DG-OVltK.js} +2 -2
  144. package/dist/shell/index.html +4 -4
  145. package/dist/shell/protobase.shell.json +2 -2
  146. package/dist/shell/protobase.sw.js +2 -2
  147. package/dist/shell-source-maps/assets/{account-page-U7RldneI.js.map → account-page-CnXeVG2Y.js.map} +1 -1
  148. package/dist/shell-source-maps/assets/app-Dhno5n-x.js.map +1 -0
  149. package/dist/shell-source-maps/assets/{assistant-shell-BJWCAwCu.js.map → assistant-shell-CiBgXc2G.js.map} +1 -1
  150. package/dist/shell-source-maps/assets/{board-display-DSazq67h.js.map → board-display-CbDhUr3M.js.map} +1 -1
  151. package/dist/shell-source-maps/assets/{calendar-display-CpqjM4oV.js.map → calendar-display-DYCeXWel.js.map} +1 -1
  152. package/dist/shell-source-maps/assets/{call-rings-DnL8InVq.js.map → call-rings-DasjTYQQ.js.map} +1 -1
  153. package/dist/shell-source-maps/assets/{calls-CTRygR5f.js.map → calls-CK0S2A1I.js.map} +1 -1
  154. package/dist/shell-source-maps/assets/{circle-alert-B63XjMgn.js.map → circle-alert-DsS_wh95.js.map} +1 -1
  155. package/dist/shell-source-maps/assets/{composed-page-BVm_6eWU.js.map → composed-page-DR1_Pmnm.js.map} +1 -1
  156. package/dist/shell-source-maps/assets/{composer-section-DETU2Obd.js.map → composer-section-Drni_iH0.js.map} +1 -1
  157. package/dist/shell-source-maps/assets/{connect-route-BILeY04q.js.map → connect-route-CWqZ4ZdQ.js.map} +1 -1
  158. package/dist/shell-source-maps/assets/{copy-field-CmFjZmVI.js.map → copy-field-BEMhQB0i.js.map} +1 -1
  159. package/dist/shell-source-maps/assets/{create-route-BT69PwsI.js.map → create-route-DcR4vO0R.js.map} +1 -1
  160. package/dist/shell-source-maps/assets/{custom-step-container-field-CZDuNAGK.js.map → custom-step-container-field-CQNLXPAV.js.map} +1 -1
  161. package/dist/shell-source-maps/assets/{embedded-list-C9U2ypuX.js.map → embedded-list-CUUg5UdE.js.map} +1 -1
  162. package/dist/shell-source-maps/assets/{export-dialog-DoaQ8h-M.js.map → export-dialog-BF7ErysJ.js.map} +1 -1
  163. package/dist/shell-source-maps/assets/{graph-view-COd5Mp2P.js.map → graph-view-CYY1Wxfn.js.map} +1 -1
  164. package/dist/shell-source-maps/assets/{group-donut-DUBQuhYa.js.map → group-donut-BrPYdLB4.js.map} +1 -1
  165. package/dist/shell-source-maps/assets/{guest-call-page-Bu41Ptk4.js.map → guest-call-page-vE_LtZb2.js.map} +1 -1
  166. package/dist/shell-source-maps/assets/{html-viewer-Bz3ots0-.js.map → html-viewer-d5JaZY_d.js.map} +1 -1
  167. package/dist/shell-source-maps/assets/{import-dialog-B0lJXEBq.js.map → import-dialog-Cwopdvpl.js.map} +1 -1
  168. package/dist/shell-source-maps/assets/{import-table-dialog-CaZameXo.js.map → import-table-dialog-iJiIRDzs.js.map} +1 -1
  169. package/dist/shell-source-maps/assets/{invitations-page-DPzcVGHk.js.map → invitations-page-C7lvsotm.js.map} +1 -1
  170. package/dist/shell-source-maps/assets/{layout-grid-hoLv1QVh.js.map → layout-grid-CMNfsxPk.js.map} +1 -1
  171. package/dist/shell-source-maps/assets/{legend-item-CU6Kt-GZ.js.map → legend-item-CcZfSPqr.js.map} +1 -1
  172. package/dist/shell-source-maps/assets/{list-page-C8Z3OhmV.js.map → list-page-C1SSeT_l.js.map} +1 -1
  173. package/dist/shell-source-maps/assets/{maplibre-BOVzS79J.js.map → maplibre-CZgGye8n.js.map} +1 -1
  174. package/dist/shell-source-maps/assets/{markdown-content-BMDl_vl_.js.map → markdown-content-DqspuxI3.js.map} +1 -1
  175. package/dist/shell-source-maps/assets/{members-page-O752tFj8.js.map → members-page-BFe1wo7t.js.map} +1 -1
  176. package/dist/shell-source-maps/assets/{messages-TLh-JbDm.js.map → messages-Djmoh5Qy.js.map} +1 -1
  177. package/dist/shell-source-maps/assets/{organization-page-DDwBkk8F.js.map → organization-page-BS5CBM7T.js.map} +1 -1
  178. package/dist/shell-source-maps/assets/{organizations-page-DNYezYgw.js.map → organizations-page-D-2TFpDm.js.map} +1 -1
  179. package/dist/shell-source-maps/assets/{pending-invitation-row-DRjEfn76.js.map → pending-invitation-row-MW_m7ClO.js.map} +1 -1
  180. package/dist/shell-source-maps/assets/{period-chart-B_Vtp_OD.js.map → period-chart-D5Gmfn_N.js.map} +1 -1
  181. package/dist/shell-source-maps/assets/{person-row-ehgAozYT.js.map → person-row-DixR2c5_.js.map} +1 -1
  182. package/dist/shell-source-maps/assets/{public-form-page-JM_r4BIq.js.map → public-form-page-BD-0Pq4m.js.map} +1 -1
  183. package/dist/shell-source-maps/assets/{record-lines-B8maPngL.js.map → record-lines-C61HlpSx.js.map} +1 -1
  184. package/dist/shell-source-maps/assets/{record-map-BJI9HhZO.js.map → record-map-C-VFW3uK.js.map} +1 -1
  185. package/dist/shell-source-maps/assets/{record-opens-BP2LRuAM.js.map → record-opens-0Hwj29eY.js.map} +1 -1
  186. package/dist/shell-source-maps/assets/{record-page-DsLORKNo.js.map → record-page-DSlsKtND.js.map} +1 -1
  187. package/dist/shell-source-maps/assets/{record-preview-BDMeb9qp.js.map → record-preview-9gB2HCqq.js.map} +1 -1
  188. package/dist/shell-source-maps/assets/{records-map-D2IAAn9Z.js.map → records-map-CHzxxjrz.js.map} +1 -1
  189. package/dist/shell-source-maps/assets/{render-node-CAL7-6hf.js.map → render-node-Bx2j3Z9N.js.map} +1 -1
  190. package/dist/shell-source-maps/assets/{reorder-button-D9hO_nqd.js.map → reorder-button-BbnTcDWe.js.map} +1 -1
  191. package/dist/shell-source-maps/assets/{run-trace-view-CqCld741.js.map → run-trace-view-BFoZdUL_.js.map} +1 -1
  192. package/dist/shell-source-maps/assets/{runner-install-field-Cpd0yW2w.js.map → runner-install-field-oUIwmXJr.js.map} +1 -1
  193. package/dist/shell-source-maps/assets/{runtime-update-Cg98ENel.js.map → runtime-update-C_nVK-Ib.js.map} +1 -1
  194. package/dist/shell-source-maps/assets/{sheet-source-fKebPN-3.js.map → sheet-source-DPrt_4fp.js.map} +1 -1
  195. package/dist/shell-source-maps/assets/{sign-in-policy-page-DtxdycdZ.js.map → sign-in-policy-page-OkYaQyjd.js.map} +1 -1
  196. package/dist/shell-source-maps/assets/{start-block-queries-DIJZ-fEE.js.map → start-block-queries-BEWBUhWg.js.map} +1 -1
  197. package/dist/shell-source-maps/assets/{step-catalog-DefIkvlp.js.map → step-catalog-B37ubHh0.js.map} +1 -1
  198. package/dist/shell-source-maps/assets/{step-panel-DhFvGljv.js.map → step-panel-CLYTTuEx.js.map} +1 -1
  199. package/dist/shell-source-maps/assets/{timeline-display-CsGry__i.js.map → timeline-display-Be98AAvH.js.map} +1 -1
  200. package/dist/shell-source-maps/assets/{trash-B3Zy6Kx1.js.map → trash-B3AS7MZB.js.map} +1 -1
  201. package/dist/shell-source-maps/assets/{update-set-C_skfvwV.js.map → update-set-LOqKj6_s.js.map} +1 -1
  202. package/dist/shell-source-maps/assets/{use-calendar-move-CZtjDwpL.js.map → use-calendar-move-tAYNZeaf.js.map} +1 -1
  203. package/dist/shell-source-maps/assets/{use-display-rows-DHVZ49lA.js.map → use-display-rows-BNTGJCuA.js.map} +1 -1
  204. package/dist/shell-source-maps/assets/{use-paged-search-COK4rUdF.js.map → use-paged-search-zW8DC14J.js.map} +1 -1
  205. package/dist/shell-source-maps/assets/{use-run-trace-CRPYmppF.js.map → use-run-trace-BfNKHhse.js.map} +1 -1
  206. package/dist/shell-source-maps/assets/{use-workflow-page-NQnBpQBn.js.map → use-workflow-page-gk8rhqQH.js.map} +1 -1
  207. package/dist/shell-source-maps/assets/{use-workflow-types-BONTV-ip.js.map → use-workflow-types-BY3B_Oaj.js.map} +1 -1
  208. package/dist/shell-source-maps/assets/{workflow-canvas-wK7am90B.js.map → workflow-canvas-D2uLwFrs.js.map} +1 -1
  209. package/dist/shell-source-maps/assets/{workflow-field-D4NB5B1z.js.map → workflow-field-QMvj5PMy.js.map} +1 -1
  210. package/dist/shell-source-maps/assets/{workflow-graph-editor-CBPqhazd.js.map → workflow-graph-editor-DX7BUqLb.js.map} +1 -1
  211. package/dist/shell-source-maps/assets/{workflow-run-field-C1N-mmHl.js.map → workflow-run-field-DF95Gx_P.js.map} +1 -1
  212. package/dist/shell-source-maps/assets/{workflow-status-field-DEgDvkpV.js.map → workflow-status-field-COisBbne.js.map} +1 -1
  213. package/dist/shell-source-maps/assets/{workflow-workbench-mJR1exSe.js.map → workflow-workbench-DG-OVltK.js.map} +1 -1
  214. package/dist/status/messages.d.ts +2 -2
  215. package/dist/theme.css +2 -2
  216. package/dist/users/messages.d.ts +2 -2
  217. package/package.json +5 -5
  218. package/dist/shell/assets/app-BAQxWF5r.css +0 -2
  219. package/dist/shell-source-maps/assets/app-94a88jzE.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"record-preview-BDMeb9qp.js","names":["useMemo","useRef","useState","useCallback","useMemo","useCallback","n","a","t","__toESM","require_react","recordId","listLabels","seedTitleRows","createWhere","printFilter","recordKey","withLabels","listPhotos","withPhotos","encodeKey","useClient","keys","useQueryClient","useQuery","import_react","createPageCache","pages","index","pageSize","page","rows","maxPages","oldest","kept","pagesForRange","first","start","last","end","offset","pageLength","total","usePagedRows","cache","rowAt","loadRows","seeded","seed","cachedRows","version","setVersion","firstPage","lastPage","synchronous","latencyMs","length","store","current","cancelled","timers","shownRevision","revision","shown","searchAll","items","labels","pageToken","client","resource","params","relation","names","where","and","parts","given","part","text","value","groupByOwner","owners","owner","links","grouped","record","records","raw","field","linksOf","through","column","via","resources","key","row","loadRelatedColumn","load","target","values","loaded","fields","views","exactBelow","createGridLoader","relatedNames","related","pageKey","model","filter","orderBy","number","columns","photos","firstPageTotal","result","tokenBefore","cached","queryClient","fetchPage","token","ids","labelled","liveFirstPageQuery","options","useLiveRows","columnKey","relatedKey","loader","recordPreview","name","useSeedRecord"],"sources":["../../../src/data-grid/page-cache.ts","../../../src/data-grid/use-paged-rows.ts","../../../src/live/search-all.ts","../../../src/live/related-column-rows.ts","../../../src/live/grid-loader.ts","../../../src/live/use-live-rows.ts","../../../src/app/record-preview.ts"],"sourcesContent":["export type PageCache<T> = {\n get: (index: number) => T | undefined\n hasPage: (page: number) => boolean\n setPage: (page: number, rows: T[]) => void\n /** Forgets every page but `kept`. */\n keepOnly: (kept: number[]) => void\n readonly size: number\n}\n\n/** Holds fixed-size pages of rows; evicts the oldest pages beyond `maxPages`. */\nexport const createPageCache = <T>(pageSize: number, maxPages: number): PageCache<T> => {\n const pages = new Map<number, T[]>()\n return {\n get: (index) => pages.get(Math.floor(index / pageSize))?.[index % pageSize],\n hasPage: (page) => pages.has(page),\n setPage: (page, rows) => {\n pages.delete(page)\n pages.set(page, rows)\n if (pages.size <= maxPages) return\n const oldest = pages.keys().next()\n if (oldest.done) return\n pages.delete(oldest.value)\n },\n keepOnly: (kept) => {\n for (const page of [...pages.keys()]) if (!kept.includes(page)) pages.delete(page)\n },\n get size() {\n return pages.size\n },\n }\n}\n\nexport const pagesForRange = (start: number, end: number, pageSize: number) => {\n const first = Math.floor(start / pageSize)\n const last = Math.floor(end / pageSize)\n return Array.from({ length: last - first + 1 }, (_, offset) => first + offset)\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { GridRow } from './column-spec'\nimport { createPageCache, pagesForRange } from './page-cache'\nimport type { RowSource } from './row-source'\n\nexport const gridPageSize = 40\n\n/** How many rows of `total` the page holds: a whole page, but for the last. */\nconst pageLength = (total: number, page: number) => Math.max(0, Math.min(gridPageSize, total - page * gridPageSize))\n\ntype Loading = { total: number; rowAt?: (index: number) => GridRow; loadRows?: RowSource['loadRows']; cachedRows?: RowSource['cachedRows']; revision?: number; latencyMs: number }\n\n/**\n * Serves rows by absolute index. Mock sources compute rows (after `latencyMs`, or at once when 0);\n * live sources load pages through `loadRows`, starting from the pages `cachedRows` already holds, which show at once and\n * are loaded again in place. Unloaded rows read as undefined, so fast scrolling shows skeletons. A new `revision` loads\n * the pages on screen again, showing the rows they held until the new ones arrive.\n */\nexport const usePagedRows = ({ total, rowAt, loadRows, cachedRows, revision, latencyMs }: Loading, start: number, end: number) => {\n const cache = useMemo(() => createPageCache<GridRow>(gridPageSize, 60), [rowAt, loadRows])\n // The pages the cache held when they were first drawn, refreshed once by the effect below\n const seeded = useRef(new Set<number>())\n const seed = (index: number) => {\n const page = Math.floor(index / gridPageSize)\n if (!cachedRows || cache.hasPage(page)) return\n const rows = cachedRows(page * gridPageSize)\n if (!rows) return\n cache.setPage(page, rows)\n seeded.current.add(page)\n }\n const [version, setVersion] = useState(0)\n const firstPage = Math.floor(start / gridPageSize)\n const lastPage = Math.floor(end / gridPageSize)\n const synchronous = !loadRows && latencyMs === 0\n\n useEffect(() => {\n if (synchronous) return\n const pages = pagesForRange(firstPage * gridPageSize, lastPage * gridPageSize, gridPageSize).filter((page) => !cache.hasPage(page) || seeded.current.delete(page))\n const length = (page: number) => pageLength(total, page)\n const store = (page: number, rows: GridRow[]) => {\n cache.setPage(page, rows)\n setVersion((current) => current + 1)\n }\n if (loadRows) {\n let cancelled = false\n for (const page of pages) {\n void loadRows(page * gridPageSize, length(page)).then((rows) => {\n if (!cancelled) store(page, rows)\n })\n }\n return () => {\n cancelled = true\n }\n }\n const timers = pages.map((page) =>\n setTimeout(() => store(page, Array.from({ length: length(page) }, (_, offset) => rowAt!(page * gridPageSize + offset))), latencyMs),\n )\n return () => timers.forEach(clearTimeout)\n }, [cache, firstPage, lastPage, latencyMs, total, rowAt, loadRows, synchronous])\n\n const shownRevision = useRef(revision)\n useEffect(() => {\n if (!loadRows || revision === shownRevision.current) return\n shownRevision.current = revision\n const shown = pagesForRange(firstPage * gridPageSize, lastPage * gridPageSize, gridPageSize)\n cache.keepOnly(shown)\n // A page not loaded yet is loaded by the effect above. A scroll does not cancel the reload, or the page it left would\n // keep its old rows.\n for (const page of shown.filter((page) => cache.hasPage(page))) {\n void loadRows(page * gridPageSize, pageLength(total, page)).then((rows) => {\n cache.setPage(page, rows)\n setVersion((current) => current + 1)\n })\n }\n }, [cache, revision, loadRows, firstPage, lastPage, total])\n\n return useCallback(\n (index: number) => {\n if (synchronous) return rowAt!(index)\n seed(index)\n return cache.get(index)\n },\n [cache, synchronous, rowAt, version, cachedRows],\n )\n}\n","import type { Client, ListParams, RelatedLabels } from '@protobase/client'\n\n// The list API's largest page\nconst pageSize = 500\n\n/** Every record a search matches, page by page, so none is left out; with `labels`, the names of every page merged. */\nexport const searchAll = async (client: Client, resource: string, params: Omit<ListParams, 'pageSize' | 'pageToken'>) => {\n const items: Record<string, unknown>[] = []\n const labels: RelatedLabels = {}\n let pageToken: string | undefined\n do {\n const page = await client.search(resource, { ...params, pageSize, ...(pageToken && { pageToken }) })\n items.push(...(page.items as Record<string, unknown>[]))\n for (const [relation, names] of Object.entries(page.labels ?? {})) labels[relation] = { ...labels[relation], ...names }\n pageToken = page.nextPageToken || undefined\n } while (pageToken)\n return { items, labels }\n}\n","import { createWhere, printFilter, type RelatedColumnModel, type ResourceModel, type ViewModel } from '@protobase/schema'\nimport type { Client } from '@protobase/client'\nimport { listLabels, withLabels } from './relation-labels'\nimport { searchAll } from './search-all'\n\nconst where = createWhere()\n\n/** A related column the list loads with its rows, and the fields of its records it loads: those its dots and cards show. */\nexport type RelatedColumnLoad = { column: RelatedColumnModel; fields: string[] }\n\ntype Row = Record<string, unknown>\n\n// Both filters must hold; a single one stays as it is\nconst and = (...parts: Array<string | undefined>) => {\n const given = parts.filter((part): part is string => Boolean(part))\n return given.length === 1 ? given[0]! : given.map((part) => `(${part})`).join(' AND ')\n}\n\nconst text = (value: unknown) => (value === null || value === undefined ? undefined : String(value))\n\n/**\n * The records of each owner, in the order `records` come in: a record belongs to every owner one of whose `links`\n * (`[owner, value]`) holds its `field`'s value. A relation's value may come labelled as `{ id, name }`.\n */\nexport const groupByOwner = (links: Array<[string, string]>, records: Row[], field: string): Map<string, Row[]> => {\n const owners = new Map<string, Set<string>>()\n for (const [owner, value] of links) owners.set(value, (owners.get(value) ?? new Set()).add(owner))\n const grouped = new Map<string, Row[]>()\n for (const record of records) {\n const raw = record[field]\n const value = text(typeof raw === 'object' && raw !== null && 'id' in raw ? raw.id : raw)\n for (const owner of value === undefined ? [] : (owners.get(value) ?? [])) grouped.set(owner, [...(grouped.get(owner) ?? []), record])\n }\n return grouped\n}\n\n// The values the shown records' `field` is matched against, per owner: through the join records, or the owner's key itself\nconst linksOf = async (client: Client, resources: Record<string, ResourceModel>, column: RelatedColumnModel, owners: string[]): Promise<Array<[string, string]>> => {\n const through = column.through\n if (!through) return owners.map((owner) => [owner, owner])\n const via = resources[through.resource]\n const key = through.key ?? via?.primaryKey[0]\n if (!via || key === undefined) throw new Error(`The related column ${column.name} names a join resource the app does not have: ${through.resource}`)\n const joined = await searchAll(client, via.name, { filter: and(printFilter(where.in(through.field, owners)), through.filter), fields: [through.field, key] })\n return joined.items.flatMap((row) => {\n const owner = text(row[through.field])\n const value = text(row[key])\n return owner === undefined || value === undefined ? [] : [[owner, value] as [string, string]]\n })\n}\n\n/**\n * The records a related column shows for each of `owners`, the keys of one page of the list's rows: all its join records,\n * then all the records they pick, each read page by page so no dot is left out, in the column's order, their relations labelled.\n */\nexport const loadRelatedColumn = async ({ client, resources, views, load, owners }: { client: Client; resources: Record<string, ResourceModel>; views: Record<string, ViewModel>; load: RelatedColumnLoad; owners: string[] }) => {\n const { column, fields } = load\n const target = resources[column.resource]\n if (!target) throw new Error(`The related column ${column.name} shows a resource the app does not have: ${column.resource}`)\n if (owners.length === 0) return new Map<string, Row[]>()\n const links = await linksOf(client, resources, column, owners)\n const values = [...new Set(links.map(([, value]) => value))]\n if (values.length === 0) return new Map<string, Row[]>()\n const loaded = [...new Set([...target.primaryKey, column.field, column.status, ...fields])]\n const labels = listLabels(resources, views, target, loaded)\n const records = await searchAll(client, target.name, {\n filter: and(printFilter(where.in(column.field, values)), column.filter),\n ...(column.sort && { orderBy: column.sort }),\n fields: loaded,\n labels,\n })\n return groupByOwner(links, withLabels(resources, target, loaded, records.items, records.labels), column.field)\n}\n","import type { QueryClient } from '@tanstack/react-query'\nimport type { ResourceModel, ViewModel } from '@protobase/schema'\nimport type { Client } from '@protobase/client'\nimport type { GridRow } from '../data-grid'\nimport { gridPageSize } from '../data-grid'\nimport { keys } from '../data/query-keys'\nimport { recordId } from './model-helpers'\nimport { loadRelatedColumn, type RelatedColumnLoad } from './related-column-rows'\nimport { listLabels, withLabels } from './relation-labels'\nimport { listPhotos, withPhotos } from './row-photos'\nimport { seedTitleRows } from './title-rows'\n\nexport type GridLoaderOptions = {\n queryClient: QueryClient\n client: Client\n resources: Record<string, ResourceModel>\n views: Record<string, ViewModel>\n model: ResourceModel\n columns: string[]\n filter: string\n orderBy: string\n /** Related columns whose records each page loads with its rows, under the column's name. */\n related?: RelatedColumnLoad[]\n}\n\nconst exactBelow = 5000\n\n/** One cached page; `nextPageToken` continues to the page after it, so a later loader on the same cache keeps the cursor. */\nexport type LoadedPage = { rows: GridRow[]; total: number; nextPageToken: string }\n\n/**\n * Loads fixed-size pages by number. The page after a cached or loading one follows that page's `next_page_token`; a\n * jump to a page whose predecessor is neither asks `:seek` for the page at that row position, so the pages of one jump\n * are read on from a single seek. Every page is cached by TanStack Query, with the records of its related columns; the\n * fields the derived titles of the records its relations point at read are cached per record (see `seedTitleRows`).\n */\nexport const createGridLoader = ({ queryClient, client, resources, views, model, columns, filter, orderBy, related = [] }: GridLoaderOptions) => {\n // A page with related columns holds more than the same rows without, which an embedded list of them loads\n const relatedNames = related.map((load) => load.column.name).join(',')\n const pageKey = (number: number) => (related.length === 0 ? keys.page(model.name, filter, orderBy, gridPageSize, number) : [...keys.page(model.name, filter, orderBy, gridPageSize, number), relatedNames])\n const labels = listLabels(resources, views, model, columns)\n const photos = listPhotos(views[model.name])\n\n /** The server's total is a planner estimate, off by a lot for small results; settle those exactly. */\n const firstPageTotal = async (result: { items: unknown[]; nextPageToken: string; totalSizeEstimate: number }) => {\n if (result.nextPageToken === '') return result.items.length\n if (result.totalSizeEstimate > exactBelow) return result.totalSizeEstimate\n return (await client.list(model.name, { filter, orderBy, pageSize: 1, count: 'exact' })).totalSize ?? result.totalSizeEstimate\n }\n\n /** The token that continues after the page before `number`, or undefined when that page is neither cached nor loading. */\n const tokenBefore = async (number: number) => {\n if (number === 0) return ''\n const key = pageKey(number - 1)\n const cached = queryClient.getQueryData<LoadedPage>(key)\n if (cached) return cached.nextPageToken\n if (queryClient.getQueryState(key)?.fetchStatus !== 'fetching') return undefined\n return (await page(number - 1)).nextPageToken\n }\n\n const fetchPage = async (page: number): Promise<LoadedPage> => {\n const token = await tokenBefore(page)\n if (page > 0 && token === '') return { rows: [], total: 0, nextPageToken: '' }\n const params = { filter, orderBy, pageSize: gridPageSize, labels, photos }\n const result =\n token !== undefined\n ? await client.list(model.name, { ...params, pageToken: token })\n : await client.seek(model.name, { ...params, position: page * gridPageSize })\n if (result.items.length === 0 && page > 0) return { rows: [], total: 0, nextPageToken: '' }\n const ids = result.items.map((record) => recordId(model, record))\n const labelled = withLabels(resources, model, columns, withPhotos(model, result.items, result.photos), result.labels)\n const [shown] = await Promise.all([\n Promise.all(related.map((load) => loadRelatedColumn({ client, resources, views, load, owners: ids }))),\n seedTitleRows(queryClient, client, resources, views, model, columns, result.items),\n ])\n const rows = labelled.map((record, index) => ({\n ...record,\n ...Object.fromEntries(related.map((load, column) => [load.column.name, shown[column]!.get(ids[index]!) ?? []])),\n id: ids[index]!,\n }))\n return { rows, total: page === 0 ? await firstPageTotal(result) : result.totalSizeEstimate, nextPageToken: result.nextPageToken }\n }\n\n const page = (number: number): Promise<LoadedPage> =>\n queryClient.fetchQuery({ queryKey: pageKey(number), staleTime: 60_000, queryFn: () => fetchPage(number) })\n\n const loadRows = async (start: number) => (await page(Math.floor(start / gridPageSize))).rows\n\n const cachedRows = (start: number) => queryClient.getQueryData<LoadedPage>(pageKey(Math.floor(start / gridPageSize)))?.rows\n\n return { page, loadRows, cachedRows }\n}\n","import { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { useMemo } from 'react'\nimport type { ResourceModel, ViewModel } from '@protobase/schema'\nimport { useClient } from '../data/api-provider'\nimport { keys } from '../data/query-keys'\nimport type { RowSource } from '../data-grid'\nimport { createGridLoader, type GridLoaderOptions } from './grid-loader'\nimport type { RelatedColumnLoad } from './related-column-rows'\n\nexport type LiveRowsParams = {\n resources: Record<string, ResourceModel>\n views: Record<string, ViewModel>\n model: ResourceModel\n columns: string[]\n filter: string\n orderBy: string\n /** Related columns loaded with each page of rows. */\n related?: RelatedColumnLoad[]\n}\n\n/** The first page `useLiveRows` reads, as a query a page can start ahead of it; each fetch makes every page of the list stale first. */\nexport const liveFirstPageQuery = (options: GridLoaderOptions) => {\n const { queryClient, model, columns, filter, orderBy } = options\n return {\n queryKey: [...keys.first(model.name, filter, orderBy), columns.join(',')],\n queryFn: async () => {\n await queryClient.invalidateQueries({ queryKey: keys.pages(model.name, filter, orderBy), refetchType: 'none' })\n return createGridLoader(options).page(0)\n },\n }\n}\n\n/**\n * A grid row source backed by the API; `total` is the server's estimate from the first page. `page` loads one page of\n * the same rows by number, and `key` names them in the query cache, for list displays that page through them. Each\n * fetch of the first page, as on a return to the window, makes every page of the list stale and gives the source a new\n * `revision`, so the rows on screen are loaded again.\n */\nexport const useLiveRows = ({ resources, views, model, columns, filter, orderBy, related }: LiveRowsParams) => {\n const client = useClient()\n const queryClient = useQueryClient()\n const columnKey = columns.join(',')\n const relatedKey = JSON.stringify(related ?? [])\n const options = useMemo<GridLoaderOptions>(\n () => ({ queryClient, client, resources, views, model, columns, filter, orderBy, ...(related && { related }) }),\n [queryClient, client, resources, views, model, columnKey, filter, orderBy, relatedKey],\n )\n const loader = useMemo(() => createGridLoader(options), [options])\n const firstPage = liveFirstPageQuery(options)\n const first = useQuery(firstPage)\n const source = useMemo<RowSource | undefined>(\n () => (first.data ? { total: first.data.total, loadRows: loader.loadRows, cachedRows: loader.cachedRows, revision: first.dataUpdatedAt } : undefined),\n [first.data, first.dataUpdatedAt, loader],\n )\n return { source, error: first.error, isLoading: first.isLoading, page: loader.page, key: firstPage.queryKey }\n}\n","import { useQueryClient } from '@tanstack/react-query'\nimport { useCallback } from 'react'\nimport type { RecordPermissions } from '@protobase/client'\nimport type { ResourceModel } from '@protobase/schema'\nimport { encodeKey } from '@protobase/schema/internal'\nimport { keys } from '../data/query-keys'\nimport type { LiveRecord } from '../data/use-record'\nimport { recordKey } from '../live/model-helpers'\n\n/**\n * A record as far as a list row knows it: the fields the row loaded, its ETag and permissions as the list gives them.\n * `row` holds relations as their keys, as `displayRow` splits a loaded row.\n */\nexport const recordPreview = (model: ResourceModel, row: Record<string, unknown>): LiveRecord => ({\n record: Object.fromEntries(Object.entries(row).filter(([name]) => Object.hasOwn(model.fields, name))),\n etag: typeof row.etag === 'string' ? row.etag : '',\n ...(typeof row.permissions === 'object' && row.permissions !== null && { permissions: row.permissions as RecordPermissions }),\n})\n\n/**\n * Keeps what a list row knows of its record for the record's page, which shows it until the record has loaded\n * (`useRecord`), so a record opened from a list shows its fields at once.\n */\nexport const useSeedRecord = (model: ResourceModel) => {\n const queryClient = useQueryClient()\n return useCallback(\n (row: Record<string, unknown>) => queryClient.setQueryData(keys.recordPreview(model.name, encodeKey(recordKey(model, row))), recordPreview(model, row)),\n [queryClient, model],\n )\n}\n"],"mappings":"gvBAUa0B,GAAsB,EAAkB,IAAmC,CACtF,IAAMC,EAAQ,IAAI,IAClB,MAAO,CACL,IAAM,GAAUA,EAAM,IAAI,KAAK,MAAMC,EAAQC,CAAQ,CAAC,CAAC,GAAGD,EAAQC,GAClE,QAAU,GAASF,EAAM,IAAIG,CAAI,EACjC,SAAU,EAAM,IAAS,CAGvB,GAFAH,EAAM,OAAOG,CAAI,EACjBH,EAAM,IAAIG,EAAMC,CAAI,EAChBJ,EAAM,MAAQK,EAAU,OAC5B,IAAMC,EAASN,EAAM,KAAK,CAAC,CAAC,KAAK,EAC7BM,EAAO,MACXN,EAAM,OAAOM,EAAO,KAAK,CAC3B,EACA,SAAW,GAAS,CAClB,IAAK,IAAMH,IAAQ,CAAC,GAAGH,EAAM,KAAK,CAAC,EAAQO,EAAK,SAASJ,CAAI,GAAGH,EAAM,OAAOG,CAAI,CACnF,EACA,IAAI,MAAO,CACT,OAAOH,EAAM,IACf,CACF,CACF,EAEaQ,GAAiB,EAAe,EAAa,IAAqB,CAC7E,IAAMC,EAAQ,KAAK,MAAMC,EAAQR,CAAQ,EACnCS,EAAO,KAAK,MAAMC,EAAMV,CAAQ,EACtC,OAAO,MAAM,KAAK,CAAE,OAAQS,EAAOF,EAAQ,CAAE,GAAI,EAAG,IAAWA,EAAQI,CAAM,CAC/E,EC5BMC,GAAc,EAAe,IAAiB,KAAK,IAAI,EAAG,KAAK,IAAA,GAAkBC,EAAQZ,EAAA,EAAmB,CAAC,EAUtGa,GAA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CAACY,EAAalD,EAAQyB,EAAWS,EAAOM,EAAOkB,EAAWjB,EAAQC,EAASiB,CAAU,CACvF,EACMC,GAAA,EAAS5H,EAAAA,QAAAA,KAAcoG,EAAiBoB,CAAO,EAAG,CAACA,CAAO,CAAC,EAC3DxE,EAAYuE,EAAmBC,CAAO,EACtCxF,EAAQZ,EAAS4B,CAAS,EAKhC,MAAO,CAAE,QAAA,EAJMhD,EAAAA,QAAAA,KACNgC,EAAM,KAAO,CAAE,MAAOA,EAAM,KAAK,MAAO,SAAU4F,EAAO,SAAU,WAAYA,EAAO,WAAY,SAAU5F,EAAM,aAAc,EAAI,IAAA,GAC3I,CAACA,EAAM,KAAMA,EAAM,cAAe4F,CAAM,CAEjC,EAAQ,MAAO5F,EAAM,MAAO,UAAWA,EAAM,UAAW,KAAM4F,EAAO,KAAM,IAAK5E,EAAU,QAAS,CAC9G,EC1Ca6E,GAAiB,EAAsB,KAA8C,CAChG,OAAQ,OAAO,YAAY,OAAO,QAAQlC,CAAG,CAAC,CAAC,QAAQ,CAACmC,KAAU,OAAO,OAAOtB,EAAM,OAAQsB,CAAI,CAAC,CAAC,EACpG,KAAM,OAAOnC,EAAI,MAAS,SAAWA,EAAI,KAAO,GAChD,GAAI,OAAOA,EAAI,aAAgB,UAAYA,EAAI,cAAgB,MAAQ,CAAE,YAAaA,EAAI,WAAiC,CAC7H,GAMaoC,EAAiB,GAAyB,CACrD,IAAMb,EAAc/F,EAAe,EACnC,OAAA,EAAOlB,EAAAA,YAAAA,CACJ,GAAiCiH,EAAY,aAAahG,EAAK,cAAcsF,EAAM,KAAMxF,EAAUJ,EAAU4F,EAAOb,CAAG,CAAC,CAAC,EAAGkC,EAAcrB,EAAOb,CAAG,CAAC,EACtJ,CAACuB,EAAaV,CAAK,CACrB,CACF","debugId":"4331e6fd-aa90-493e-9a2e-c24d3bec5242"}
1
+ {"version":3,"file":"record-preview-9gB2HCqq.js","names":["useMemo","useRef","useState","useCallback","useMemo","useCallback","n","a","t","__toESM","require_react","recordId","listLabels","seedTitleRows","createWhere","printFilter","recordKey","withLabels","listPhotos","withPhotos","encodeKey","useClient","keys","useQueryClient","useQuery","import_react","createPageCache","pages","index","pageSize","page","rows","maxPages","oldest","kept","pagesForRange","first","start","last","end","offset","pageLength","total","usePagedRows","cache","rowAt","loadRows","seeded","seed","cachedRows","version","setVersion","firstPage","lastPage","synchronous","latencyMs","length","store","current","cancelled","timers","shownRevision","revision","shown","searchAll","items","labels","pageToken","client","resource","params","relation","names","where","and","parts","given","part","text","value","groupByOwner","owners","owner","links","grouped","record","records","raw","field","linksOf","through","column","via","resources","key","row","loadRelatedColumn","load","target","values","loaded","fields","views","exactBelow","createGridLoader","relatedNames","related","pageKey","model","filter","orderBy","number","columns","photos","firstPageTotal","result","tokenBefore","cached","queryClient","fetchPage","token","ids","labelled","liveFirstPageQuery","options","useLiveRows","columnKey","relatedKey","loader","recordPreview","name","useSeedRecord"],"sources":["../../../src/data-grid/page-cache.ts","../../../src/data-grid/use-paged-rows.ts","../../../src/live/search-all.ts","../../../src/live/related-column-rows.ts","../../../src/live/grid-loader.ts","../../../src/live/use-live-rows.ts","../../../src/app/record-preview.ts"],"sourcesContent":["export type PageCache<T> = {\n get: (index: number) => T | undefined\n hasPage: (page: number) => boolean\n setPage: (page: number, rows: T[]) => void\n /** Forgets every page but `kept`. */\n keepOnly: (kept: number[]) => void\n readonly size: number\n}\n\n/** Holds fixed-size pages of rows; evicts the oldest pages beyond `maxPages`. */\nexport const createPageCache = <T>(pageSize: number, maxPages: number): PageCache<T> => {\n const pages = new Map<number, T[]>()\n return {\n get: (index) => pages.get(Math.floor(index / pageSize))?.[index % pageSize],\n hasPage: (page) => pages.has(page),\n setPage: (page, rows) => {\n pages.delete(page)\n pages.set(page, rows)\n if (pages.size <= maxPages) return\n const oldest = pages.keys().next()\n if (oldest.done) return\n pages.delete(oldest.value)\n },\n keepOnly: (kept) => {\n for (const page of [...pages.keys()]) if (!kept.includes(page)) pages.delete(page)\n },\n get size() {\n return pages.size\n },\n }\n}\n\nexport const pagesForRange = (start: number, end: number, pageSize: number) => {\n const first = Math.floor(start / pageSize)\n const last = Math.floor(end / pageSize)\n return Array.from({ length: last - first + 1 }, (_, offset) => first + offset)\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { GridRow } from './column-spec'\nimport { createPageCache, pagesForRange } from './page-cache'\nimport type { RowSource } from './row-source'\n\nexport const gridPageSize = 40\n\n/** How many rows of `total` the page holds: a whole page, but for the last. */\nconst pageLength = (total: number, page: number) => Math.max(0, Math.min(gridPageSize, total - page * gridPageSize))\n\ntype Loading = { total: number; rowAt?: (index: number) => GridRow; loadRows?: RowSource['loadRows']; cachedRows?: RowSource['cachedRows']; revision?: number; latencyMs: number }\n\n/**\n * Serves rows by absolute index. Mock sources compute rows (after `latencyMs`, or at once when 0);\n * live sources load pages through `loadRows`, starting from the pages `cachedRows` already holds, which show at once and\n * are loaded again in place. Unloaded rows read as undefined, so fast scrolling shows skeletons. A new `revision` loads\n * the pages on screen again, showing the rows they held until the new ones arrive.\n */\nexport const usePagedRows = ({ total, rowAt, loadRows, cachedRows, revision, latencyMs }: Loading, start: number, end: number) => {\n const cache = useMemo(() => createPageCache<GridRow>(gridPageSize, 60), [rowAt, loadRows])\n // The pages the cache held when they were first drawn, refreshed once by the effect below\n const seeded = useRef(new Set<number>())\n const seed = (index: number) => {\n const page = Math.floor(index / gridPageSize)\n if (!cachedRows || cache.hasPage(page)) return\n const rows = cachedRows(page * gridPageSize)\n if (!rows) return\n cache.setPage(page, rows)\n seeded.current.add(page)\n }\n const [version, setVersion] = useState(0)\n const firstPage = Math.floor(start / gridPageSize)\n const lastPage = Math.floor(end / gridPageSize)\n const synchronous = !loadRows && latencyMs === 0\n\n useEffect(() => {\n if (synchronous) return\n const pages = pagesForRange(firstPage * gridPageSize, lastPage * gridPageSize, gridPageSize).filter((page) => !cache.hasPage(page) || seeded.current.delete(page))\n const length = (page: number) => pageLength(total, page)\n const store = (page: number, rows: GridRow[]) => {\n cache.setPage(page, rows)\n setVersion((current) => current + 1)\n }\n if (loadRows) {\n let cancelled = false\n for (const page of pages) {\n void loadRows(page * gridPageSize, length(page)).then((rows) => {\n if (!cancelled) store(page, rows)\n })\n }\n return () => {\n cancelled = true\n }\n }\n const timers = pages.map((page) =>\n setTimeout(() => store(page, Array.from({ length: length(page) }, (_, offset) => rowAt!(page * gridPageSize + offset))), latencyMs),\n )\n return () => timers.forEach(clearTimeout)\n }, [cache, firstPage, lastPage, latencyMs, total, rowAt, loadRows, synchronous])\n\n const shownRevision = useRef(revision)\n useEffect(() => {\n if (!loadRows || revision === shownRevision.current) return\n shownRevision.current = revision\n const shown = pagesForRange(firstPage * gridPageSize, lastPage * gridPageSize, gridPageSize)\n cache.keepOnly(shown)\n // A page not loaded yet is loaded by the effect above. A scroll does not cancel the reload, or the page it left would\n // keep its old rows.\n for (const page of shown.filter((page) => cache.hasPage(page))) {\n void loadRows(page * gridPageSize, pageLength(total, page)).then((rows) => {\n cache.setPage(page, rows)\n setVersion((current) => current + 1)\n })\n }\n }, [cache, revision, loadRows, firstPage, lastPage, total])\n\n return useCallback(\n (index: number) => {\n if (synchronous) return rowAt!(index)\n seed(index)\n return cache.get(index)\n },\n [cache, synchronous, rowAt, version, cachedRows],\n )\n}\n","import type { Client, ListParams, RelatedLabels } from '@protobase/client'\n\n// The list API's largest page\nconst pageSize = 500\n\n/** Every record a search matches, page by page, so none is left out; with `labels`, the names of every page merged. */\nexport const searchAll = async (client: Client, resource: string, params: Omit<ListParams, 'pageSize' | 'pageToken'>) => {\n const items: Record<string, unknown>[] = []\n const labels: RelatedLabels = {}\n let pageToken: string | undefined\n do {\n const page = await client.search(resource, { ...params, pageSize, ...(pageToken && { pageToken }) })\n items.push(...(page.items as Record<string, unknown>[]))\n for (const [relation, names] of Object.entries(page.labels ?? {})) labels[relation] = { ...labels[relation], ...names }\n pageToken = page.nextPageToken || undefined\n } while (pageToken)\n return { items, labels }\n}\n","import { createWhere, printFilter, type RelatedColumnModel, type ResourceModel, type ViewModel } from '@protobase/schema'\nimport type { Client } from '@protobase/client'\nimport { listLabels, withLabels } from './relation-labels'\nimport { searchAll } from './search-all'\n\nconst where = createWhere()\n\n/** A related column the list loads with its rows, and the fields of its records it loads: those its dots and cards show. */\nexport type RelatedColumnLoad = { column: RelatedColumnModel; fields: string[] }\n\ntype Row = Record<string, unknown>\n\n// Both filters must hold; a single one stays as it is\nconst and = (...parts: Array<string | undefined>) => {\n const given = parts.filter((part): part is string => Boolean(part))\n return given.length === 1 ? given[0]! : given.map((part) => `(${part})`).join(' AND ')\n}\n\nconst text = (value: unknown) => (value === null || value === undefined ? undefined : String(value))\n\n/**\n * The records of each owner, in the order `records` come in: a record belongs to every owner one of whose `links`\n * (`[owner, value]`) holds its `field`'s value. A relation's value may come labelled as `{ id, name }`.\n */\nexport const groupByOwner = (links: Array<[string, string]>, records: Row[], field: string): Map<string, Row[]> => {\n const owners = new Map<string, Set<string>>()\n for (const [owner, value] of links) owners.set(value, (owners.get(value) ?? new Set()).add(owner))\n const grouped = new Map<string, Row[]>()\n for (const record of records) {\n const raw = record[field]\n const value = text(typeof raw === 'object' && raw !== null && 'id' in raw ? raw.id : raw)\n for (const owner of value === undefined ? [] : (owners.get(value) ?? [])) grouped.set(owner, [...(grouped.get(owner) ?? []), record])\n }\n return grouped\n}\n\n// The values the shown records' `field` is matched against, per owner: through the join records, or the owner's key itself\nconst linksOf = async (client: Client, resources: Record<string, ResourceModel>, column: RelatedColumnModel, owners: string[]): Promise<Array<[string, string]>> => {\n const through = column.through\n if (!through) return owners.map((owner) => [owner, owner])\n const via = resources[through.resource]\n const key = through.key ?? via?.primaryKey[0]\n if (!via || key === undefined) throw new Error(`The related column ${column.name} names a join resource the app does not have: ${through.resource}`)\n const joined = await searchAll(client, via.name, { filter: and(printFilter(where.in(through.field, owners)), through.filter), fields: [through.field, key] })\n return joined.items.flatMap((row) => {\n const owner = text(row[through.field])\n const value = text(row[key])\n return owner === undefined || value === undefined ? [] : [[owner, value] as [string, string]]\n })\n}\n\n/**\n * The records a related column shows for each of `owners`, the keys of one page of the list's rows: all its join records,\n * then all the records they pick, each read page by page so no dot is left out, in the column's order, their relations labelled.\n */\nexport const loadRelatedColumn = async ({ client, resources, views, load, owners }: { client: Client; resources: Record<string, ResourceModel>; views: Record<string, ViewModel>; load: RelatedColumnLoad; owners: string[] }) => {\n const { column, fields } = load\n const target = resources[column.resource]\n if (!target) throw new Error(`The related column ${column.name} shows a resource the app does not have: ${column.resource}`)\n if (owners.length === 0) return new Map<string, Row[]>()\n const links = await linksOf(client, resources, column, owners)\n const values = [...new Set(links.map(([, value]) => value))]\n if (values.length === 0) return new Map<string, Row[]>()\n const loaded = [...new Set([...target.primaryKey, column.field, column.status, ...fields])]\n const labels = listLabels(resources, views, target, loaded)\n const records = await searchAll(client, target.name, {\n filter: and(printFilter(where.in(column.field, values)), column.filter),\n ...(column.sort && { orderBy: column.sort }),\n fields: loaded,\n labels,\n })\n return groupByOwner(links, withLabels(resources, target, loaded, records.items, records.labels), column.field)\n}\n","import type { QueryClient } from '@tanstack/react-query'\nimport type { ResourceModel, ViewModel } from '@protobase/schema'\nimport type { Client } from '@protobase/client'\nimport type { GridRow } from '../data-grid'\nimport { gridPageSize } from '../data-grid'\nimport { keys } from '../data/query-keys'\nimport { recordId } from './model-helpers'\nimport { loadRelatedColumn, type RelatedColumnLoad } from './related-column-rows'\nimport { listLabels, withLabels } from './relation-labels'\nimport { listPhotos, withPhotos } from './row-photos'\nimport { seedTitleRows } from './title-rows'\n\nexport type GridLoaderOptions = {\n queryClient: QueryClient\n client: Client\n resources: Record<string, ResourceModel>\n views: Record<string, ViewModel>\n model: ResourceModel\n columns: string[]\n filter: string\n orderBy: string\n /** Related columns whose records each page loads with its rows, under the column's name. */\n related?: RelatedColumnLoad[]\n}\n\nconst exactBelow = 5000\n\n/** One cached page; `nextPageToken` continues to the page after it, so a later loader on the same cache keeps the cursor. */\nexport type LoadedPage = { rows: GridRow[]; total: number; nextPageToken: string }\n\n/**\n * Loads fixed-size pages by number. The page after a cached or loading one follows that page's `next_page_token`; a\n * jump to a page whose predecessor is neither asks `:seek` for the page at that row position, so the pages of one jump\n * are read on from a single seek. Every page is cached by TanStack Query, with the records of its related columns; the\n * fields the derived titles of the records its relations point at read are cached per record (see `seedTitleRows`).\n */\nexport const createGridLoader = ({ queryClient, client, resources, views, model, columns, filter, orderBy, related = [] }: GridLoaderOptions) => {\n // A page with related columns holds more than the same rows without, which an embedded list of them loads\n const relatedNames = related.map((load) => load.column.name).join(',')\n const pageKey = (number: number) => (related.length === 0 ? keys.page(model.name, filter, orderBy, gridPageSize, number) : [...keys.page(model.name, filter, orderBy, gridPageSize, number), relatedNames])\n const labels = listLabels(resources, views, model, columns)\n const photos = listPhotos(views[model.name])\n\n /** The server's total is a planner estimate, off by a lot for small results; settle those exactly. */\n const firstPageTotal = async (result: { items: unknown[]; nextPageToken: string; totalSizeEstimate: number }) => {\n if (result.nextPageToken === '') return result.items.length\n if (result.totalSizeEstimate > exactBelow) return result.totalSizeEstimate\n return (await client.list(model.name, { filter, orderBy, pageSize: 1, count: 'exact' })).totalSize ?? result.totalSizeEstimate\n }\n\n /** The token that continues after the page before `number`, or undefined when that page is neither cached nor loading. */\n const tokenBefore = async (number: number) => {\n if (number === 0) return ''\n const key = pageKey(number - 1)\n const cached = queryClient.getQueryData<LoadedPage>(key)\n if (cached) return cached.nextPageToken\n if (queryClient.getQueryState(key)?.fetchStatus !== 'fetching') return undefined\n return (await page(number - 1)).nextPageToken\n }\n\n const fetchPage = async (page: number): Promise<LoadedPage> => {\n const token = await tokenBefore(page)\n if (page > 0 && token === '') return { rows: [], total: 0, nextPageToken: '' }\n const params = { filter, orderBy, pageSize: gridPageSize, labels, photos }\n const result =\n token !== undefined\n ? await client.list(model.name, { ...params, pageToken: token })\n : await client.seek(model.name, { ...params, position: page * gridPageSize })\n if (result.items.length === 0 && page > 0) return { rows: [], total: 0, nextPageToken: '' }\n const ids = result.items.map((record) => recordId(model, record))\n const labelled = withLabels(resources, model, columns, withPhotos(model, result.items, result.photos), result.labels)\n const [shown] = await Promise.all([\n Promise.all(related.map((load) => loadRelatedColumn({ client, resources, views, load, owners: ids }))),\n seedTitleRows(queryClient, client, resources, views, model, columns, result.items),\n ])\n const rows = labelled.map((record, index) => ({\n ...record,\n ...Object.fromEntries(related.map((load, column) => [load.column.name, shown[column]!.get(ids[index]!) ?? []])),\n id: ids[index]!,\n }))\n return { rows, total: page === 0 ? await firstPageTotal(result) : result.totalSizeEstimate, nextPageToken: result.nextPageToken }\n }\n\n const page = (number: number): Promise<LoadedPage> =>\n queryClient.fetchQuery({ queryKey: pageKey(number), staleTime: 60_000, queryFn: () => fetchPage(number) })\n\n const loadRows = async (start: number) => (await page(Math.floor(start / gridPageSize))).rows\n\n const cachedRows = (start: number) => queryClient.getQueryData<LoadedPage>(pageKey(Math.floor(start / gridPageSize)))?.rows\n\n return { page, loadRows, cachedRows }\n}\n","import { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { useMemo } from 'react'\nimport type { ResourceModel, ViewModel } from '@protobase/schema'\nimport { useClient } from '../data/api-provider'\nimport { keys } from '../data/query-keys'\nimport type { RowSource } from '../data-grid'\nimport { createGridLoader, type GridLoaderOptions } from './grid-loader'\nimport type { RelatedColumnLoad } from './related-column-rows'\n\nexport type LiveRowsParams = {\n resources: Record<string, ResourceModel>\n views: Record<string, ViewModel>\n model: ResourceModel\n columns: string[]\n filter: string\n orderBy: string\n /** Related columns loaded with each page of rows. */\n related?: RelatedColumnLoad[]\n}\n\n/** The first page `useLiveRows` reads, as a query a page can start ahead of it; each fetch makes every page of the list stale first. */\nexport const liveFirstPageQuery = (options: GridLoaderOptions) => {\n const { queryClient, model, columns, filter, orderBy } = options\n return {\n queryKey: [...keys.first(model.name, filter, orderBy), columns.join(',')],\n queryFn: async () => {\n await queryClient.invalidateQueries({ queryKey: keys.pages(model.name, filter, orderBy), refetchType: 'none' })\n return createGridLoader(options).page(0)\n },\n }\n}\n\n/**\n * A grid row source backed by the API; `total` is the server's estimate from the first page. `page` loads one page of\n * the same rows by number, and `key` names them in the query cache, for list displays that page through them. Each\n * fetch of the first page, as on a return to the window, makes every page of the list stale and gives the source a new\n * `revision`, so the rows on screen are loaded again.\n */\nexport const useLiveRows = ({ resources, views, model, columns, filter, orderBy, related }: LiveRowsParams) => {\n const client = useClient()\n const queryClient = useQueryClient()\n const columnKey = columns.join(',')\n const relatedKey = JSON.stringify(related ?? [])\n const options = useMemo<GridLoaderOptions>(\n () => ({ queryClient, client, resources, views, model, columns, filter, orderBy, ...(related && { related }) }),\n [queryClient, client, resources, views, model, columnKey, filter, orderBy, relatedKey],\n )\n const loader = useMemo(() => createGridLoader(options), [options])\n const firstPage = liveFirstPageQuery(options)\n const first = useQuery(firstPage)\n const source = useMemo<RowSource | undefined>(\n () => (first.data ? { total: first.data.total, loadRows: loader.loadRows, cachedRows: loader.cachedRows, revision: first.dataUpdatedAt } : undefined),\n [first.data, first.dataUpdatedAt, loader],\n )\n return { source, error: first.error, isLoading: first.isLoading, page: loader.page, key: firstPage.queryKey }\n}\n","import { useQueryClient } from '@tanstack/react-query'\nimport { useCallback } from 'react'\nimport type { RecordPermissions } from '@protobase/client'\nimport type { ResourceModel } from '@protobase/schema'\nimport { encodeKey } from '@protobase/schema/internal'\nimport { keys } from '../data/query-keys'\nimport type { LiveRecord } from '../data/use-record'\nimport { recordKey } from '../live/model-helpers'\n\n/**\n * A record as far as a list row knows it: the fields the row loaded, its ETag and permissions as the list gives them.\n * `row` holds relations as their keys, as `displayRow` splits a loaded row.\n */\nexport const recordPreview = (model: ResourceModel, row: Record<string, unknown>): LiveRecord => ({\n record: Object.fromEntries(Object.entries(row).filter(([name]) => Object.hasOwn(model.fields, name))),\n etag: typeof row.etag === 'string' ? row.etag : '',\n ...(typeof row.permissions === 'object' && row.permissions !== null && { permissions: row.permissions as RecordPermissions }),\n})\n\n/**\n * Keeps what a list row knows of its record for the record's page, which shows it until the record has loaded\n * (`useRecord`), so a record opened from a list shows its fields at once.\n */\nexport const useSeedRecord = (model: ResourceModel) => {\n const queryClient = useQueryClient()\n return useCallback(\n (row: Record<string, unknown>) => queryClient.setQueryData(keys.recordPreview(model.name, encodeKey(recordKey(model, row))), recordPreview(model, row)),\n [queryClient, model],\n )\n}\n"],"mappings":"gvBAUa0B,GAAsB,EAAkB,IAAmC,CACtF,IAAMC,EAAQ,IAAI,IAClB,MAAO,CACL,IAAM,GAAUA,EAAM,IAAI,KAAK,MAAMC,EAAQC,CAAQ,CAAC,CAAC,GAAGD,EAAQC,GAClE,QAAU,GAASF,EAAM,IAAIG,CAAI,EACjC,SAAU,EAAM,IAAS,CAGvB,GAFAH,EAAM,OAAOG,CAAI,EACjBH,EAAM,IAAIG,EAAMC,CAAI,EAChBJ,EAAM,MAAQK,EAAU,OAC5B,IAAMC,EAASN,EAAM,KAAK,CAAC,CAAC,KAAK,EAC7BM,EAAO,MACXN,EAAM,OAAOM,EAAO,KAAK,CAC3B,EACA,SAAW,GAAS,CAClB,IAAK,IAAMH,IAAQ,CAAC,GAAGH,EAAM,KAAK,CAAC,EAAQO,EAAK,SAASJ,CAAI,GAAGH,EAAM,OAAOG,CAAI,CACnF,EACA,IAAI,MAAO,CACT,OAAOH,EAAM,IACf,CACF,CACF,EAEaQ,GAAiB,EAAe,EAAa,IAAqB,CAC7E,IAAMC,EAAQ,KAAK,MAAMC,EAAQR,CAAQ,EACnCS,EAAO,KAAK,MAAMC,EAAMV,CAAQ,EACtC,OAAO,MAAM,KAAK,CAAE,OAAQS,EAAOF,EAAQ,CAAE,GAAI,EAAG,IAAWA,EAAQI,CAAM,CAC/E,EC5BMC,GAAc,EAAe,IAAiB,KAAK,IAAI,EAAG,KAAK,IAAA,GAAkBC,EAAQZ,EAAA,EAAmB,CAAC,EAUtGa,GAAgB,CAAE,QAAO,QAAO,WAAU,aAAY,WAAU,aAAsB,EAAe,IAAgB,CAChI,IAAMC,GAAA,EAAQ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GAAA,EAAS5H,EAAAA,QAAAA,KAAcoG,EAAiBoB,CAAO,EAAG,CAACA,CAAO,CAAC,EAC3DxE,EAAYuE,EAAmBC,CAAO,EACtCxF,EAAQZ,EAAS4B,CAAS,EAKhC,MAAO,CAAE,QAAA,EAJMhD,EAAAA,QAAAA,KACNgC,EAAM,KAAO,CAAE,MAAOA,EAAM,KAAK,MAAO,SAAU4F,EAAO,SAAU,WAAYA,EAAO,WAAY,SAAU5F,EAAM,aAAc,EAAI,IAAA,GAC3I,CAACA,EAAM,KAAMA,EAAM,cAAe4F,CAAM,CAEjC,EAAQ,MAAO5F,EAAM,MAAO,UAAWA,EAAM,UAAW,KAAM4F,EAAO,KAAM,IAAK5E,EAAU,QAAS,CAC9G,EC1Ca6E,GAAiB,EAAsB,KAA8C,CAChG,OAAQ,OAAO,YAAY,OAAO,QAAQlC,CAAG,CAAC,CAAC,QAAQ,CAACmC,KAAU,OAAO,OAAOtB,EAAM,OAAQsB,CAAI,CAAC,CAAC,EACpG,KAAM,OAAOnC,EAAI,MAAS,SAAWA,EAAI,KAAO,GAChD,GAAI,OAAOA,EAAI,aAAgB,UAAYA,EAAI,cAAgB,MAAQ,CAAE,YAAaA,EAAI,WAAiC,CAC7H,GAMaoC,EAAiB,GAAyB,CACrD,IAAMb,EAAc/F,EAAe,EACnC,OAAA,EAAOlB,EAAAA,YAAAA,CACJ,GAAiCiH,EAAY,aAAahG,EAAK,cAAcsF,EAAM,KAAMxF,EAAUJ,EAAU4F,EAAOb,CAAG,CAAC,CAAC,EAAGkC,EAAcrB,EAAOb,CAAG,CAAC,EACtJ,CAACuB,EAAaV,CAAK,CACrB,CACF","debugId":"3d801d87-0aaa-49d1-8a32-bed59b6cee80"}
@@ -1 +1 @@
1
- {"version":3,"file":"records-map-D2IAAn9Z.js","names":["useRef","useState","n","a","t","__toESM","require_react","require_jsx_runtime","cn","cachedFormat","groupPoints","MapLayerSwitch","MapPin","mapLib","Map","Marker","Source","NavigationControl","Layer","import_react","worldPixels","mercatorLimit","fadeFrom","zooms","zoom","positionsOf","geometry","mercatorY","radians","latitude","zoomZeroSpan","positions","longitudes","longitude","ys","width","height","areaFeatures","features","points","point","kind","selected","feature","fadeIn","full","import_jsx_runtime","areaLayerId","polygons","lines","chosen","yes","no","PositionAreas","data","color","colors","themeColor","probe","token","element","resolved","canvas","context","red","green","blue","alpha","groupRadius","fitOptions","bucketOptions","markerHeight","compact","tag","corners","bounds","RecordsMap","ref","groups","setGroups","setColors","byKey","pointKeys","fitKey","fit","regroup","map","report","center","onMove","fitNow","onFitted","chosenAt","group","key","at","covered","open","y","style","initial","container","onClear","buckets","bucket","bucketLabel","event","approximate","markerLabel","onSelect"],"sources":["../../../src/app/map/area-features.ts","../../../src/app/map/position-areas.tsx","../../../src/app/map/theme-color.ts","../../../src/app/map/records-map.tsx"],"sourcesContent":["import type { ExpressionSpecification } from 'maplibre-gl'\nimport type { MapPoint } from '../displays/map-groups'\nimport type { AreaGeometry } from './approximate-position'\n\n/** An area as the map's GeoJSON source holds it: whose it is, whether it is filled or a line, its size, and whether its record is chosen. */\nexport type AreaFeature = {\n type: 'Feature'\n geometry: AreaGeometry\n properties: { key: string; kind: 'polygon' | 'line'; span: number; chosen: boolean }\n}\n\n// MapLibre draws the whole world 512 pixels across at zoom 0, each zoom level twice as wide as the one before.\nconst worldPixels = 512\n// The furthest north and south Web Mercator draws.\nconst mercatorLimit = 85.051129\n// An area fades in as it grows from about half a marker to a marker and a half across, smaller it says nothing the marker does not.\nconst fadeFrom = 16\nconst fadeTo = 48\nconst zooms = Array.from({ length: 23 }, (_, zoom) => zoom)\n\nconst positionsOf = (geometry: AreaGeometry): [number, number][] => {\n if (geometry.type === 'LineString') return geometry.coordinates\n if (geometry.type === 'MultiPolygon') return geometry.coordinates.flat(2)\n return geometry.coordinates.flat()\n}\n\n// How far down the world a latitude is drawn, from 0 at the top to 1 at the bottom.\nconst mercatorY = (latitude: number) => {\n const radians = (Math.max(-mercatorLimit, Math.min(mercatorLimit, latitude)) * Math.PI) / 180\n return 0.5 - Math.log(Math.tan(Math.PI / 4 + radians / 2)) / (2 * Math.PI)\n}\n\n/** How many pixels across the area is drawn at zoom 0, the larger of its width and height; twice as many each zoom level in. */\nexport const zoomZeroSpan = (geometry: AreaGeometry) => {\n const positions = positionsOf(geometry)\n const longitudes = positions.map(([longitude]) => longitude)\n const ys = positions.map(([, latitude]) => mercatorY(latitude))\n const width = ((Math.max(...longitudes) - Math.min(...longitudes)) / 360) * worldPixels\n const height = (Math.max(...ys) - Math.min(...ys)) * worldPixels\n return Math.max(width, height)\n}\n\n/** The areas of the points that have one, those of the chosen records last so they are drawn on top. */\nexport const areaFeatures = (points: MapPoint[], selected: string[] | undefined): { type: 'FeatureCollection'; features: AreaFeature[] } => {\n const features = points.flatMap((point): AreaFeature[] => {\n if (!point.area) return []\n const kind = point.area.type === 'LineString' || point.area.type === 'MultiLineString' ? 'line' : 'polygon'\n return [{ type: 'Feature', geometry: point.area, properties: { key: point.key, kind, span: zoomZeroSpan(point.area), chosen: selected?.includes(point.key) ?? false } }]\n })\n return { type: 'FeatureCollection', features: [...features.filter((feature) => !feature.properties.chosen), ...features.filter((feature) => feature.properties.chosen)] }\n}\n\n/**\n * An opacity of `full` for an area drawn large enough to mean something at the zoom, fading in as it grows to that\n * size: at each whole zoom level its share of `full` follows from its span, and MapLibre blends between the levels.\n */\nexport const fadeIn = (full: number | ExpressionSpecification): ExpressionSpecification =>\n [\n 'interpolate',\n ['linear'],\n ['zoom'],\n ...zooms.flatMap((zoom) => [zoom, ['*', full, ['min', 1, ['max', 0, ['/', ['-', ['*', ['get', 'span'], 2 ** zoom], fadeFrom], fadeTo - fadeFrom]]]]]),\n ] as ExpressionSpecification\n","import type { ExpressionSpecification, FilterSpecification } from 'maplibre-gl'\nimport { Layer, Source } from 'react-map-gl/maplibre'\nimport type { MapPoint } from '../displays/map-groups'\nimport { areaFeatures, fadeIn } from './area-features'\n\n/** The colours of the areas, as MapLibre reads them: the markers' own, and the chosen marker's. */\nexport type AreaColors = { area: string; chosen: string }\n\n/** The areas' lowest layer, which a layer of tiles goes under. */\nexport const areaLayerId = 'position-area-fills'\n\nconst polygons: FilterSpecification = ['==', ['get', 'kind'], 'polygon']\nconst lines: FilterSpecification = ['==', ['get', 'kind'], 'line']\nconst chosen = (yes: number, no: number): ExpressionSpecification => ['case', ['get', 'chosen'], yes, no]\n\n/**\n * The areas around the approximate positions among `points`, drawn under the markers in the markers' colour: a polygon\n * filled faintly within a dashed outline, a line such as a street as a wide stroke. Each fades in as the map zooms close\n * enough for it to be larger than a marker, and the chosen records' areas are drawn darker. Nothing without areas.\n */\nexport const PositionAreas = ({ points, selected, colors }: { points: MapPoint[]; selected: string[] | undefined; colors: AreaColors }) => {\n const data = areaFeatures(points, selected)\n if (data.features.length === 0) return null\n const color: ExpressionSpecification = ['case', ['get', 'chosen'], colors.chosen, colors.area]\n return (\n <Source id=\"position-areas\" type=\"geojson\" data={data}>\n <Layer id={areaLayerId} type=\"fill\" filter={polygons} paint={{ 'fill-color': color, 'fill-opacity': fadeIn(chosen(0.15, 0.1)) }} />\n <Layer id=\"position-area-outlines\" type=\"line\" filter={polygons} paint={{ 'line-color': color, 'line-width': 1.5, 'line-dasharray': [3, 2], 'line-opacity': fadeIn(0.8) }} />\n <Layer id=\"position-area-lines\" type=\"line\" filter={lines} layout={{ 'line-cap': 'round', 'line-join': 'round' }} paint={{ 'line-color': color, 'line-width': 6, 'line-opacity': fadeIn(chosen(0.6, 0.35)) }} />\n </Source>\n )\n}\n","/**\n * The colour a theme token such as `--primary` holds where `element` is, as `rgba()`, which MapLibre's paint reads\n * whatever the theme writes it in: the browser resolves the token, and a pixel painted with it gives its channels.\n */\nexport const themeColor = (element: HTMLElement, token: string) => {\n const probe = document.createElement('span')\n probe.style.color = `var(${token})`\n element.append(probe)\n const resolved = getComputedStyle(probe).color\n probe.remove()\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n const context = canvas.getContext('2d', { willReadFrequently: true })\n if (!context) return resolved\n context.fillStyle = resolved\n context.fillRect(0, 0, 1, 1)\n const [red, green, blue, alpha] = context.getImageData(0, 0, 1, 1).data\n return `rgba(${red}, ${green}, ${blue}, ${alpha! / 255})`\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { MapPin } from 'lucide-react'\nimport { Map, Marker, NavigationControl, type MapRef } from 'react-map-gl/maplibre'\nimport type { MapBounds, MapBucket, MapLayerModel } from '@protobase/client'\nimport type { MapView } from '@protobase/schema'\nimport { cn } from '../../lib/cn'\nimport { groupPoints, type MapGroup, type MapPoint } from '../displays/map-groups'\nimport type { MapArea } from './map-area'\nimport { MapLayerSwitch } from './map-layer-switch'\nimport { mapLib } from './maplibre'\nimport { areaLayerId, PositionAreas, type AreaColors } from './position-areas'\nimport { themeColor } from './theme-color'\nimport { cachedFormat } from '../../format/intl-cache'\n\n// How close, in pixels, records are drawn under one marker, about a marker's width.\nconst groupRadius = 28\nconst fitOptions = { padding: 48, maxZoom: 15, duration: 0 }\n// A bucket opens far enough in for the server to send its records: it does from zoom 16 on.\nconst bucketOptions = { padding: 48, maxZoom: 16, duration: 300 }\nconst markerHeight = 32\nconst compact = () => cachedFormat('compact', (tag) => new Intl.NumberFormat(tag, { notation: 'compact', maximumFractionDigits: 1 }))\n\nconst corners = (bounds: MapBounds): [[number, number], [number, number]] => [\n [bounds.west, bounds.south],\n [bounds.east, bounds.north],\n]\n\ntype RecordsMapProps = {\n style: string\n /** The layers the map may switch to in place of the style's. */\n layers?: MapLayerModel[]\n /** Where the map looks when it opens; the whole world without it. */\n initial: MapView | undefined\n points: MapPoint[]\n /** Counts of records in parts of the map, drawn as circles in place of their records. */\n buckets: MapBucket[]\n /** Bounds to move the map to, each time they change; `onFitted` says it moved there. */\n fit: MapBounds | undefined\n onFitted: () => void\n /** The map's area and view, each time it comes to rest. */\n onMove: (area: MapArea, view: MapView) => void\n /** The records whose marker is chosen, if any. */\n selected: string[] | undefined\n /** How many pixels at the map's bottom something covers, such as the chosen record's card. */\n covered: number\n onSelect: (keys: string[]) => void\n onClear: () => void\n /** What a marker for these records says to a screen reader. */\n markerLabel: (keys: string[]) => string\n /** What a bucket of this many records says to a screen reader. */\n bucketLabel: (count: number) => string\n}\n\n/**\n * A map of `style` with a marker for each group of records that lie close together at the zoom, showing how many it\n * stands for, and a circle with the count of each bucket, which zooms in on its records when chosen. A marker whose\n * records' positions are all approximate is drawn hollow with a dashed edge, over the areas around them. Choosing a\n * marker selects its records; choosing the map elsewhere clears the selection. A chosen marker the covered bottom would\n * hide moves up into the open part of the map.\n */\nexport const RecordsMap = ({ style, layers, initial, points, buckets, fit, onFitted, onMove, selected, covered, onSelect, onClear, markerLabel, bucketLabel }: RecordsMapProps) => {\n const ref = useRef<MapRef>(null)\n const [groups, setGroups] = useState<MapGroup[]>([])\n const [colors, setColors] = useState<AreaColors>()\n const byKey = new globalThis.Map(points.map((point) => [point.key, point]))\n const pointKeys = points.map((point) => point.key).join(',')\n const fitKey = fit && JSON.stringify(fit)\n\n // The groups as the map is drawn now: only the zoom changes which records lie close together\n const regroup = () => {\n const map = ref.current?.getMap()\n if (!map) return\n setGroups(\n groupPoints(\n points.map((point) => ({ key: point.key, ...map.project([point.longitude, point.latitude]) })),\n groupRadius,\n ),\n )\n }\n\n const report = () => {\n const map = ref.current?.getMap()\n if (!map) return\n const bounds = map.getBounds()\n const center = map.getCenter()\n onMove({ bounds: { south: bounds.getSouth(), west: bounds.getWest(), north: bounds.getNorth(), east: bounds.getEast() }, zoom: map.getZoom() }, { latitude: center.lat, longitude: center.lng, zoom: map.getZoom() })\n }\n\n const fitNow = () => {\n const map = ref.current?.getMap()\n if (!map || !fit) return\n map.fitBounds(corners(fit), fitOptions)\n onFitted()\n report()\n }\n\n // Other records are grouped at the zoom the map is at\n useEffect(regroup, [pointKeys])\n useEffect(fitNow, [fitKey])\n\n // The chosen marker in view above what covers the map's bottom\n const chosenAt = groups.find((group) => selected !== undefined && group.keys.some((key) => selected.includes(key)))?.at\n useEffect(() => {\n const map = ref.current?.getMap()\n const at = chosenAt === undefined ? undefined : byKey.get(chosenAt)\n if (!map || !at || covered === 0) return\n const { y } = map.project([at.longitude, at.latitude])\n const open = map.getContainer().clientHeight - covered\n if (y > markerHeight && y < open) return\n map.easeTo({ center: [at.longitude, at.latitude], offset: [0, (markerHeight - covered) / 2], duration: 300 })\n // A new choice or a new cover moves the map, not every new group\n }, [chosenAt, covered])\n\n return (\n <Map\n ref={ref}\n mapLib={mapLib}\n mapStyle={style}\n initialViewState={initial ?? { latitude: 0, longitude: 0, zoom: 1 }}\n style={{ width: '100%', height: '100%' }}\n onLoad={() => {\n const container = ref.current!.getMap().getContainer()\n setColors({ area: themeColor(container, '--primary'), chosen: themeColor(container, '--foreground') })\n regroup()\n if (fit) fitNow()\n else report()\n }}\n onZoomEnd={regroup}\n onMoveEnd={report}\n onClick={onClear}\n >\n <NavigationControl showCompass={false} />\n <MapLayerSwitch layers={layers} below={areaLayerId} />\n {colors && <PositionAreas points={points} selected={selected} colors={colors} />}\n {buckets.map((bucket) => (\n <Marker key={`${bucket.latitude},${bucket.longitude}`} latitude={bucket.latitude} longitude={bucket.longitude} anchor=\"center\">\n <button\n type=\"button\"\n aria-label={bucketLabel(bucket.count)}\n className=\"flex size-10 cursor-pointer items-center justify-center rounded-full border-2 border-background bg-primary text-xs font-semibold text-primary-foreground tabular-nums shadow\"\n onClick={(event) => {\n event.stopPropagation()\n ref.current?.getMap().fitBounds(corners(bucket.bounds), bucketOptions)\n }}\n >\n {compact().format(bucket.count)}\n </button>\n </Marker>\n ))}\n {groups.map((group) => {\n const at = byKey.get(group.at)\n if (!at) return null\n const chosen = selected !== undefined && group.keys.some((key) => selected.includes(key))\n const approximate = group.keys.every((key) => byKey.get(key)?.approximate)\n return (\n <Marker key={group.at} latitude={at.latitude} longitude={at.longitude} anchor=\"bottom\" style={{ zIndex: chosen ? 1 : 0 }}>\n <button\n type=\"button\"\n aria-label={markerLabel(group.keys)}\n aria-pressed={chosen}\n className=\"relative block cursor-pointer\"\n onClick={(event) => {\n event.stopPropagation()\n onSelect(group.keys)\n }}\n >\n <MapPin\n aria-hidden\n data-approximate={approximate || undefined}\n className={cn('size-8 drop-shadow', approximate ? (chosen ? 'fill-background text-foreground' : 'fill-background text-primary') : chosen ? 'fill-foreground text-background' : 'fill-primary text-primary-foreground')}\n strokeWidth={approximate ? 2 : 1.5}\n strokeDasharray={approximate ? '3 2' : undefined}\n />\n {group.keys.length > 1 && (\n <span className=\"absolute -right-2 -top-1 min-w-5 rounded-full border border-background bg-foreground px-1 text-center text-[0.6875rem] font-medium leading-4 text-background tabular-nums\">\n {group.keys.length}\n </span>\n )}\n </button>\n </Marker>\n )\n })}\n </Map>\n )\n}\n"],"mappings":"wzBAYMoB,EAAc,IAEdC,EAAgB,UAEhBC,EAAW,GAEXC,EAAQ,MAAM,KAAK,CAAE,OAAQ,EAAG,GAAI,EAAG,IAASC,CAAI,EAEpDC,EAAe,GACfC,EAAS,OAAS,aAAqBA,EAAS,YAChDA,EAAS,OAAS,eAAuBA,EAAS,YAAY,KAAK,CAAC,EACjEA,EAAS,YAAY,KAAK,EAI7BC,EAAa,GAAqB,CACtC,IAAMC,EAAW,KAAK,IAAI,WAAgB,KAAK,IAAIP,EAAeQ,CAAQ,CAAC,EAAI,KAAK,GAAM,IAC1F,MAAO,IAAM,KAAK,IAAI,KAAK,IAAI,KAAK,GAAK,EAAID,EAAU,CAAC,CAAC,GAAK,EAAI,KAAK,GACzE,EAGaE,EAAgB,GAA2B,CACtD,IAAMC,EAAYN,EAAYC,CAAQ,EAChCM,EAAaD,EAAU,KAAK,CAACE,KAAeA,CAAS,EACrDC,EAAKH,EAAU,KAAK,EAAGF,KAAcF,EAAUE,CAAQ,CAAC,EACxDM,GAAU,KAAK,IAAI,GAAGH,CAAU,EAAI,KAAK,IAAI,GAAGA,CAAU,GAAK,IAAOZ,EACtEgB,GAAU,KAAK,IAAI,GAAGF,CAAE,EAAI,KAAK,IAAI,GAAG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T,EACA1B,EAAO,IAAK,GAAU,CACrB,IAAMiB,EAAKd,EAAM,IAAIY,EAAM,EAAE,EAC7B,GAAI,CAACE,EAAI,OAAO,KAChB,IAAM7C,EAASR,IAAa,IAAA,IAAamD,EAAM,KAAK,KAAM,GAAQnD,EAAS,SAASoD,CAAG,CAAC,EAClFa,EAAcd,EAAM,KAAK,MAAO,GAAQZ,EAAM,IAAIa,CAAG,CAAC,EAAE,WAAW,EACzE,OACE,EAAAhD,EAAA,IAAA,CAAC/B,EAAD,CAAuB,SAAUgF,EAAG,SAAU,UAAWA,EAAG,UAAW,OAAO,SAAS,MAAO,CAAE,OAAQ,IAAe,EACrH,UAAA,EAAAjD,EAAA,KAAA,CAAC,SAAD,CACE,KAAK,SACL,aAAY8D,EAAYf,EAAM,IAAI,EAClC,eAAc3C,EACd,UAAU,gCACV,QAAU,GAAU,CAClBwD,EAAM,gBAAgB,EACtBG,EAAShB,EAAM,IAAI,CACrB,EARF,SAAA,EAUE,EAAA/C,EAAA,IAAA,CAAClC,EAAD,CACE,cAAA,GACA,mBAAkB+F,GAAe,IAAA,GACjC,UAAWnG,EAAG,qBAAsBmG,EAAezD,EAAS,kCAAoC,+BAAkCA,EAAS,kCAAoC,sCAAsC,EACrN,YAAayD,EAAc,EAAI,IAC/B,gBAAiBA,EAAc,MAAQ,IAAA,EACxC,CAAA,EACAd,EAAM,KAAK,OAAS,IACnB,EAAA/C,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,4KACb,SAAA+C,EAAM,KAAK,MACR,CAAA,CAEF,GACF,EAxBKA,EAAM,EAwBX,CAEZ,CAAC,CACE,GAET","debugId":"f6200027-f59e-434e-859b-02ab961e525b"}
1
+ {"version":3,"file":"records-map-CHzxxjrz.js","names":["useRef","useState","n","a","t","__toESM","require_react","require_jsx_runtime","cn","cachedFormat","groupPoints","MapLayerSwitch","MapPin","mapLib","Map","Marker","Source","NavigationControl","Layer","import_react","worldPixels","mercatorLimit","fadeFrom","zooms","zoom","positionsOf","geometry","mercatorY","radians","latitude","zoomZeroSpan","positions","longitudes","longitude","ys","width","height","areaFeatures","features","points","point","kind","selected","feature","fadeIn","full","import_jsx_runtime","areaLayerId","polygons","lines","chosen","yes","no","PositionAreas","data","color","colors","themeColor","probe","token","element","resolved","canvas","context","red","green","blue","alpha","groupRadius","fitOptions","bucketOptions","markerHeight","compact","tag","corners","bounds","RecordsMap","ref","groups","setGroups","setColors","byKey","pointKeys","fitKey","fit","regroup","map","report","center","onMove","fitNow","onFitted","chosenAt","group","key","at","covered","open","y","style","initial","container","onClear","buckets","bucket","bucketLabel","event","approximate","markerLabel","onSelect"],"sources":["../../../src/app/map/area-features.ts","../../../src/app/map/position-areas.tsx","../../../src/app/map/theme-color.ts","../../../src/app/map/records-map.tsx"],"sourcesContent":["import type { ExpressionSpecification } from 'maplibre-gl'\nimport type { MapPoint } from '../displays/map-groups'\nimport type { AreaGeometry } from './approximate-position'\n\n/** An area as the map's GeoJSON source holds it: whose it is, whether it is filled or a line, its size, and whether its record is chosen. */\nexport type AreaFeature = {\n type: 'Feature'\n geometry: AreaGeometry\n properties: { key: string; kind: 'polygon' | 'line'; span: number; chosen: boolean }\n}\n\n// MapLibre draws the whole world 512 pixels across at zoom 0, each zoom level twice as wide as the one before.\nconst worldPixels = 512\n// The furthest north and south Web Mercator draws.\nconst mercatorLimit = 85.051129\n// An area fades in as it grows from about half a marker to a marker and a half across, smaller it says nothing the marker does not.\nconst fadeFrom = 16\nconst fadeTo = 48\nconst zooms = Array.from({ length: 23 }, (_, zoom) => zoom)\n\nconst positionsOf = (geometry: AreaGeometry): [number, number][] => {\n if (geometry.type === 'LineString') return geometry.coordinates\n if (geometry.type === 'MultiPolygon') return geometry.coordinates.flat(2)\n return geometry.coordinates.flat()\n}\n\n// How far down the world a latitude is drawn, from 0 at the top to 1 at the bottom.\nconst mercatorY = (latitude: number) => {\n const radians = (Math.max(-mercatorLimit, Math.min(mercatorLimit, latitude)) * Math.PI) / 180\n return 0.5 - Math.log(Math.tan(Math.PI / 4 + radians / 2)) / (2 * Math.PI)\n}\n\n/** How many pixels across the area is drawn at zoom 0, the larger of its width and height; twice as many each zoom level in. */\nexport const zoomZeroSpan = (geometry: AreaGeometry) => {\n const positions = positionsOf(geometry)\n const longitudes = positions.map(([longitude]) => longitude)\n const ys = positions.map(([, latitude]) => mercatorY(latitude))\n const width = ((Math.max(...longitudes) - Math.min(...longitudes)) / 360) * worldPixels\n const height = (Math.max(...ys) - Math.min(...ys)) * worldPixels\n return Math.max(width, height)\n}\n\n/** The areas of the points that have one, those of the chosen records last so they are drawn on top. */\nexport const areaFeatures = (points: MapPoint[], selected: string[] | undefined): { type: 'FeatureCollection'; features: AreaFeature[] } => {\n const features = points.flatMap((point): AreaFeature[] => {\n if (!point.area) return []\n const kind = point.area.type === 'LineString' || point.area.type === 'MultiLineString' ? 'line' : 'polygon'\n return [{ type: 'Feature', geometry: point.area, properties: { key: point.key, kind, span: zoomZeroSpan(point.area), chosen: selected?.includes(point.key) ?? false } }]\n })\n return { type: 'FeatureCollection', features: [...features.filter((feature) => !feature.properties.chosen), ...features.filter((feature) => feature.properties.chosen)] }\n}\n\n/**\n * An opacity of `full` for an area drawn large enough to mean something at the zoom, fading in as it grows to that\n * size: at each whole zoom level its share of `full` follows from its span, and MapLibre blends between the levels.\n */\nexport const fadeIn = (full: number | ExpressionSpecification): ExpressionSpecification =>\n [\n 'interpolate',\n ['linear'],\n ['zoom'],\n ...zooms.flatMap((zoom) => [zoom, ['*', full, ['min', 1, ['max', 0, ['/', ['-', ['*', ['get', 'span'], 2 ** zoom], fadeFrom], fadeTo - fadeFrom]]]]]),\n ] as ExpressionSpecification\n","import type { ExpressionSpecification, FilterSpecification } from 'maplibre-gl'\nimport { Layer, Source } from 'react-map-gl/maplibre'\nimport type { MapPoint } from '../displays/map-groups'\nimport { areaFeatures, fadeIn } from './area-features'\n\n/** The colours of the areas, as MapLibre reads them: the markers' own, and the chosen marker's. */\nexport type AreaColors = { area: string; chosen: string }\n\n/** The areas' lowest layer, which a layer of tiles goes under. */\nexport const areaLayerId = 'position-area-fills'\n\nconst polygons: FilterSpecification = ['==', ['get', 'kind'], 'polygon']\nconst lines: FilterSpecification = ['==', ['get', 'kind'], 'line']\nconst chosen = (yes: number, no: number): ExpressionSpecification => ['case', ['get', 'chosen'], yes, no]\n\n/**\n * The areas around the approximate positions among `points`, drawn under the markers in the markers' colour: a polygon\n * filled faintly within a dashed outline, a line such as a street as a wide stroke. Each fades in as the map zooms close\n * enough for it to be larger than a marker, and the chosen records' areas are drawn darker. Nothing without areas.\n */\nexport const PositionAreas = ({ points, selected, colors }: { points: MapPoint[]; selected: string[] | undefined; colors: AreaColors }) => {\n const data = areaFeatures(points, selected)\n if (data.features.length === 0) return null\n const color: ExpressionSpecification = ['case', ['get', 'chosen'], colors.chosen, colors.area]\n return (\n <Source id=\"position-areas\" type=\"geojson\" data={data}>\n <Layer id={areaLayerId} type=\"fill\" filter={polygons} paint={{ 'fill-color': color, 'fill-opacity': fadeIn(chosen(0.15, 0.1)) }} />\n <Layer id=\"position-area-outlines\" type=\"line\" filter={polygons} paint={{ 'line-color': color, 'line-width': 1.5, 'line-dasharray': [3, 2], 'line-opacity': fadeIn(0.8) }} />\n <Layer id=\"position-area-lines\" type=\"line\" filter={lines} layout={{ 'line-cap': 'round', 'line-join': 'round' }} paint={{ 'line-color': color, 'line-width': 6, 'line-opacity': fadeIn(chosen(0.6, 0.35)) }} />\n </Source>\n )\n}\n","/**\n * The colour a theme token such as `--primary` holds where `element` is, as `rgba()`, which MapLibre's paint reads\n * whatever the theme writes it in: the browser resolves the token, and a pixel painted with it gives its channels.\n */\nexport const themeColor = (element: HTMLElement, token: string) => {\n const probe = document.createElement('span')\n probe.style.color = `var(${token})`\n element.append(probe)\n const resolved = getComputedStyle(probe).color\n probe.remove()\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n const context = canvas.getContext('2d', { willReadFrequently: true })\n if (!context) return resolved\n context.fillStyle = resolved\n context.fillRect(0, 0, 1, 1)\n const [red, green, blue, alpha] = context.getImageData(0, 0, 1, 1).data\n return `rgba(${red}, ${green}, ${blue}, ${alpha! / 255})`\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { MapPin } from 'lucide-react'\nimport { Map, Marker, NavigationControl, type MapRef } from 'react-map-gl/maplibre'\nimport type { MapBounds, MapBucket, MapLayerModel } from '@protobase/client'\nimport type { MapView } from '@protobase/schema'\nimport { cn } from '../../lib/cn'\nimport { groupPoints, type MapGroup, type MapPoint } from '../displays/map-groups'\nimport type { MapArea } from './map-area'\nimport { MapLayerSwitch } from './map-layer-switch'\nimport { mapLib } from './maplibre'\nimport { areaLayerId, PositionAreas, type AreaColors } from './position-areas'\nimport { themeColor } from './theme-color'\nimport { cachedFormat } from '../../format/intl-cache'\n\n// How close, in pixels, records are drawn under one marker, about a marker's width.\nconst groupRadius = 28\nconst fitOptions = { padding: 48, maxZoom: 15, duration: 0 }\n// A bucket opens far enough in for the server to send its records: it does from zoom 16 on.\nconst bucketOptions = { padding: 48, maxZoom: 16, duration: 300 }\nconst markerHeight = 32\nconst compact = () => cachedFormat('compact', (tag) => new Intl.NumberFormat(tag, { notation: 'compact', maximumFractionDigits: 1 }))\n\nconst corners = (bounds: MapBounds): [[number, number], [number, number]] => [\n [bounds.west, bounds.south],\n [bounds.east, bounds.north],\n]\n\ntype RecordsMapProps = {\n style: string\n /** The layers the map may switch to in place of the style's. */\n layers?: MapLayerModel[]\n /** Where the map looks when it opens; the whole world without it. */\n initial: MapView | undefined\n points: MapPoint[]\n /** Counts of records in parts of the map, drawn as circles in place of their records. */\n buckets: MapBucket[]\n /** Bounds to move the map to, each time they change; `onFitted` says it moved there. */\n fit: MapBounds | undefined\n onFitted: () => void\n /** The map's area and view, each time it comes to rest. */\n onMove: (area: MapArea, view: MapView) => void\n /** The records whose marker is chosen, if any. */\n selected: string[] | undefined\n /** How many pixels at the map's bottom something covers, such as the chosen record's card. */\n covered: number\n onSelect: (keys: string[]) => void\n onClear: () => void\n /** What a marker for these records says to a screen reader. */\n markerLabel: (keys: string[]) => string\n /** What a bucket of this many records says to a screen reader. */\n bucketLabel: (count: number) => string\n}\n\n/**\n * A map of `style` with a marker for each group of records that lie close together at the zoom, showing how many it\n * stands for, and a circle with the count of each bucket, which zooms in on its records when chosen. A marker whose\n * records' positions are all approximate is drawn hollow with a dashed edge, over the areas around them. Choosing a\n * marker selects its records; choosing the map elsewhere clears the selection. A chosen marker the covered bottom would\n * hide moves up into the open part of the map.\n */\nexport const RecordsMap = ({ style, layers, initial, points, buckets, fit, onFitted, onMove, selected, covered, onSelect, onClear, markerLabel, bucketLabel }: RecordsMapProps) => {\n const ref = useRef<MapRef>(null)\n const [groups, setGroups] = useState<MapGroup[]>([])\n const [colors, setColors] = useState<AreaColors>()\n const byKey = new globalThis.Map(points.map((point) => [point.key, point]))\n const pointKeys = points.map((point) => point.key).join(',')\n const fitKey = fit && JSON.stringify(fit)\n\n // The groups as the map is drawn now: only the zoom changes which records lie close together\n const regroup = () => {\n const map = ref.current?.getMap()\n if (!map) return\n setGroups(\n groupPoints(\n points.map((point) => ({ key: point.key, ...map.project([point.longitude, point.latitude]) })),\n groupRadius,\n ),\n )\n }\n\n const report = () => {\n const map = ref.current?.getMap()\n if (!map) return\n const bounds = map.getBounds()\n const center = map.getCenter()\n onMove({ bounds: { south: bounds.getSouth(), west: bounds.getWest(), north: bounds.getNorth(), east: bounds.getEast() }, zoom: map.getZoom() }, { latitude: center.lat, longitude: center.lng, zoom: map.getZoom() })\n }\n\n const fitNow = () => {\n const map = ref.current?.getMap()\n if (!map || !fit) return\n map.fitBounds(corners(fit), fitOptions)\n onFitted()\n report()\n }\n\n // Other records are grouped at the zoom the map is at\n useEffect(regroup, [pointKeys])\n useEffect(fitNow, [fitKey])\n\n // The chosen marker in view above what covers the map's bottom\n const chosenAt = groups.find((group) => selected !== undefined && group.keys.some((key) => selected.includes(key)))?.at\n useEffect(() => {\n const map = ref.current?.getMap()\n const at = chosenAt === undefined ? undefined : byKey.get(chosenAt)\n if (!map || !at || covered === 0) return\n const { y } = map.project([at.longitude, at.latitude])\n const open = map.getContainer().clientHeight - covered\n if (y > markerHeight && y < open) return\n map.easeTo({ center: [at.longitude, at.latitude], offset: [0, (markerHeight - covered) / 2], duration: 300 })\n // A new choice or a new cover moves the map, not every new group\n }, [chosenAt, covered])\n\n return (\n <Map\n ref={ref}\n mapLib={mapLib}\n mapStyle={style}\n initialViewState={initial ?? { latitude: 0, longitude: 0, zoom: 1 }}\n style={{ width: '100%', height: '100%' }}\n onLoad={() => {\n const container = ref.current!.getMap().getContainer()\n setColors({ area: themeColor(container, '--primary'), chosen: themeColor(container, '--foreground') })\n regroup()\n if (fit) fitNow()\n else report()\n }}\n onZoomEnd={regroup}\n onMoveEnd={report}\n onClick={onClear}\n >\n <NavigationControl showCompass={false} />\n <MapLayerSwitch layers={layers} below={areaLayerId} />\n {colors && <PositionAreas points={points} selected={selected} colors={colors} />}\n {buckets.map((bucket) => (\n <Marker key={`${bucket.latitude},${bucket.longitude}`} latitude={bucket.latitude} longitude={bucket.longitude} anchor=\"center\">\n <button\n type=\"button\"\n aria-label={bucketLabel(bucket.count)}\n className=\"flex size-10 cursor-pointer items-center justify-center rounded-full border-2 border-background bg-primary text-xs font-semibold text-primary-foreground tabular-nums shadow\"\n onClick={(event) => {\n event.stopPropagation()\n ref.current?.getMap().fitBounds(corners(bucket.bounds), bucketOptions)\n }}\n >\n {compact().format(bucket.count)}\n </button>\n </Marker>\n ))}\n {groups.map((group) => {\n const at = byKey.get(group.at)\n if (!at) return null\n const chosen = selected !== undefined && group.keys.some((key) => selected.includes(key))\n const approximate = group.keys.every((key) => byKey.get(key)?.approximate)\n return (\n <Marker key={group.at} latitude={at.latitude} longitude={at.longitude} anchor=\"bottom\" style={{ zIndex: chosen ? 1 : 0 }}>\n <button\n type=\"button\"\n aria-label={markerLabel(group.keys)}\n aria-pressed={chosen}\n className=\"relative block cursor-pointer\"\n onClick={(event) => {\n event.stopPropagation()\n onSelect(group.keys)\n }}\n >\n <MapPin\n aria-hidden\n data-approximate={approximate || undefined}\n className={cn('size-8 drop-shadow', approximate ? (chosen ? 'fill-background text-foreground' : 'fill-background text-primary') : chosen ? 'fill-foreground text-background' : 'fill-primary text-primary-foreground')}\n strokeWidth={approximate ? 2 : 1.5}\n strokeDasharray={approximate ? '3 2' : undefined}\n />\n {group.keys.length > 1 && (\n <span className=\"absolute -right-2 -top-1 min-w-5 rounded-full border border-background bg-foreground px-1 text-center text-[0.6875rem] font-medium leading-4 text-background tabular-nums\">\n {group.keys.length}\n </span>\n )}\n </button>\n </Marker>\n )\n })}\n </Map>\n )\n}\n"],"mappings":"wzBAYMoB,EAAc,IAEdC,EAAgB,UAEhBC,EAAW,GAEXC,EAAQ,MAAM,KAAK,CAAE,OAAQ,EAAG,GAAI,EAAG,IAASC,CAAI,EAEpDC,EAAe,GACfC,EAAS,OAAS,aAAqBA,EAAS,YAChDA,EAAS,OAAS,eAAuBA,EAAS,YAAY,KAAK,CAAC,EACjEA,EAAS,YAAY,KAAK,EAI7BC,EAAa,GAAqB,CACtC,IAAMC,EAAW,KAAK,IAAI,WAAgB,KAAK,IAAIP,EAAeQ,CAAQ,CAAC,EAAI,KAAK,GAAM,IAC1F,MAAO,IAAM,KAAK,IAAI,KAAK,IAAI,KAAK,GAAK,EAAID,EAAU,CAAC,CAAC,GAAK,EAAI,KAAK,GACzE,EAGaE,EAAgB,GAA2B,CACtD,IAAMC,EAAYN,EAAYC,CAAQ,EAChCM,EAAaD,EAAU,KAAK,CAACE,KAAeA,CAAS,EACrDC,EAAKH,EAAU,KAAK,EAAGF,KAAcF,EAAUE,CAAQ,CAAC,EACxDM,GAAU,KAAK,IAAI,GAAGH,CAAU,EAAI,KAAK,IAAI,GAAGA,CAAU,GAAK,IAAOZ,EACtEgB,GAAU,KAAK,IAAI,GAAGF,CAAE,EAAI,KAAK,IAAI,GAAGA,CAAE,GAAKd,EACrD,OAAO,KAAK,IAA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