@nivaro/react 0.3.113 → 0.3.115

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 (285) hide show
  1. package/dist/components/ScreenShareHost.js +24 -0
  2. package/dist/full.css +50 -2
  3. package/dist/hooks/useSessionRecorder.js +61 -60
  4. package/dist/index.d.ts +1727 -19
  5. package/dist/index.js +1091 -950
  6. package/dist/shared/components/ActivityEntry.js +209 -97
  7. package/dist/shared/components/AgentPresenceChip.js +51 -0
  8. package/dist/shared/components/AnnouncementBanner.js +56 -41
  9. package/dist/shared/components/AutolinkedText.js +98 -85
  10. package/dist/shared/components/BroadcastView.js +149 -141
  11. package/dist/shared/components/CacheStamp.js +78 -30
  12. package/dist/shared/components/CollectionBrowserView.js +4088 -3592
  13. package/dist/shared/components/ConfigChangeStrip.js +63 -0
  14. package/dist/shared/components/ConfigReachNote.js +107 -0
  15. package/dist/shared/components/ConformanceView.js +389 -319
  16. package/dist/shared/components/DataTable.js +544 -504
  17. package/dist/shared/components/DelegateCoverLine.js +164 -0
  18. package/dist/shared/components/EnvironmentNotice.js +56 -65
  19. package/dist/shared/components/FilePreviewLightbox.js +89 -43
  20. package/dist/shared/components/FindingFixedMark.js +23 -0
  21. package/dist/shared/components/GridPresenceLine.js +100 -0
  22. package/dist/shared/components/IdleReloadWatcher.js +82 -43
  23. package/dist/shared/components/InStep.js +46 -0
  24. package/dist/shared/components/ItemEditForm.js +5504 -4889
  25. package/dist/shared/components/LiveAnnouncer.js +62 -0
  26. package/dist/shared/components/LiveCount.js +54 -0
  27. package/dist/shared/components/LiveFigure.js +28 -0
  28. package/dist/shared/components/LiveListControls.js +114 -0
  29. package/dist/shared/components/LiveNewMatchesPill.js +25 -0
  30. package/dist/shared/components/LiveOffNote.js +44 -0
  31. package/dist/shared/components/LivePreferenceHost.js +42 -0
  32. package/dist/shared/components/LiveRowMark.js +25 -20
  33. package/dist/shared/components/LiveTraceView.js +257 -0
  34. package/dist/shared/components/MapView.js +30 -29
  35. package/dist/shared/components/MatrixEditor.js +497 -462
  36. package/dist/shared/components/MyWorkView.js +346 -272
  37. package/dist/shared/components/NotificationBell.js +215 -201
  38. package/dist/shared/components/PageRenderer.js +636 -599
  39. package/dist/shared/components/PresenceDot.js +21 -0
  40. package/dist/shared/components/ProfileView.js +656 -536
  41. package/dist/shared/components/RealtimeStatusBanner.js +25 -25
  42. package/dist/shared/components/RecentRecordsRail.js +51 -48
  43. package/dist/shared/components/RecordCompare.js +241 -150
  44. package/dist/shared/components/RecordDrilldownSheet.js +66 -64
  45. package/dist/shared/components/RecordGridEditor.js +350 -311
  46. package/dist/shared/components/RecordHoverCard.js +147 -0
  47. package/dist/shared/components/RecordPeekHost.js +111 -0
  48. package/dist/shared/components/RecordReadView.js +414 -412
  49. package/dist/shared/components/RelativeTime.js +16 -0
  50. package/dist/shared/components/ReportView.js +1396 -1304
  51. package/dist/shared/components/ScreenRefreshButton.js +77 -0
  52. package/dist/shared/components/TabCountHost.js +10 -0
  53. package/dist/shared/components/TickerNumber.js +19 -18
  54. package/dist/shared/components/TipLayer.js +70 -58
  55. package/dist/shared/components/WidgetImageMenu.js +59 -0
  56. package/dist/shared/components/WidgetSlot.js +571 -524
  57. package/dist/shared/components/activity/RecordActivityStream.js +317 -0
  58. package/dist/shared/components/bulk/BulkSelectionNotices.js +220 -0
  59. package/dist/shared/components/cbv/approval-changed.js +20 -0
  60. package/dist/shared/components/cbv/changed-by-others.js +251 -0
  61. package/dist/shared/components/cbv/column-totals.js +75 -67
  62. package/dist/shared/components/change-proposals/ChangeProposalsPanel.js +320 -0
  63. package/dist/shared/components/change-proposals/ProposalValue.js +28 -0
  64. package/dist/shared/components/change-proposals/ProposeChangeButton.js +44 -0
  65. package/dist/shared/components/change-proposals/ProposeChangeDialog.js +359 -0
  66. package/dist/shared/components/change-proposals/types.js +4 -0
  67. package/dist/shared/components/chat/ChatPanel.js +1571 -1528
  68. package/dist/shared/components/chat/Composer.js +276 -298
  69. package/dist/shared/components/chat/room-due.js +13 -0
  70. package/dist/shared/components/collections-directory/CollectionRow.js +76 -75
  71. package/dist/shared/components/collections-directory/CollectionsDirectory.js +415 -395
  72. package/dist/shared/components/collections-directory/directory-data.js +75 -63
  73. package/dist/shared/components/imports/ImportConsole.js +159 -155
  74. package/dist/shared/components/imports/ImportDuplicatesNotice.js +46 -31
  75. package/dist/shared/components/integrations/SendStatus.js +202 -0
  76. package/dist/shared/components/integrations/console/IntegrationsConsole.js +45 -36
  77. package/dist/shared/components/integrations/console/ReadyToSendView.js +453 -0
  78. package/dist/shared/components/integrations/console/api.js +161 -117
  79. package/dist/shared/components/integrations/console/tone.js +15 -12
  80. package/dist/shared/components/item-edit/CatalogPickerField.js +1353 -1245
  81. package/dist/shared/components/item-edit/ChangedAfterApprovalBadge.js +162 -0
  82. package/dist/shared/components/item-edit/CloneDialog.js +208 -206
  83. package/dist/shared/components/item-edit/DerivedCauseNote.js +57 -0
  84. package/dist/shared/components/item-edit/DraftRecoveryBanner.js +81 -70
  85. package/dist/shared/components/item-edit/DuplicateNotice.js +169 -101
  86. package/dist/shared/components/item-edit/FieldAffordances.js +294 -385
  87. package/dist/shared/components/item-edit/FieldComments.js +159 -116
  88. package/dist/shared/components/item-edit/FieldPointer.js +132 -0
  89. package/dist/shared/components/item-edit/FieldRenderer.js +277 -273
  90. package/dist/shared/components/item-edit/FieldRow.js +519 -439
  91. package/dist/shared/components/item-edit/FieldSourceBadge.js +88 -0
  92. package/dist/shared/components/item-edit/FilePickerField.js +454 -369
  93. package/dist/shared/components/item-edit/GroupSection.js +618 -567
  94. package/dist/shared/components/item-edit/HeldEditsChip.js +113 -0
  95. package/dist/shared/components/item-edit/InlineTableField.js +2891 -2723
  96. package/dist/shared/components/item-edit/ListNeighborNav.js +79 -0
  97. package/dist/shared/components/item-edit/LiveTraceSheet.js +26 -0
  98. package/dist/shared/components/item-edit/M2MCombobox.js +284 -273
  99. package/dist/shared/components/item-edit/OutboxReviewTray.js +313 -0
  100. package/dist/shared/components/item-edit/PickerBadges.js +52 -0
  101. package/dist/shared/components/item-edit/PlanGrid.js +434 -439
  102. package/dist/shared/components/item-edit/RecalcValue.js +55 -0
  103. package/dist/shared/components/item-edit/RecordChatActions.js +76 -64
  104. package/dist/shared/components/item-edit/RecordChatMentionsChip.js +103 -0
  105. package/dist/shared/components/item-edit/RecordGrantTools.js +87 -86
  106. package/dist/shared/components/item-edit/RecordHelpChip.js +70 -0
  107. package/dist/shared/components/item-edit/RecordLiveSync.js +230 -217
  108. package/dist/shared/components/item-edit/RecordOutbox.js +53 -52
  109. package/dist/shared/components/item-edit/RecordRecapStrip.js +109 -36
  110. package/dist/shared/components/item-edit/RelationCombobox.js +229 -217
  111. package/dist/shared/components/item-edit/RelationGroupedCombobox.js +105 -100
  112. package/dist/shared/components/item-edit/RemoteChangeUi.js +454 -0
  113. package/dist/shared/components/item-edit/RemoteUploads.js +55 -0
  114. package/dist/shared/components/item-edit/RemovedLineNote.js +92 -0
  115. package/dist/shared/components/item-edit/RichTextEditorImpl.js +298 -223
  116. package/dist/shared/components/item-edit/ScheduledChangeChip.js +244 -0
  117. package/dist/shared/components/item-edit/SectionPresence.js +78 -0
  118. package/dist/shared/components/item-edit/SplitLinesButton.js +166 -0
  119. package/dist/shared/components/item-edit/catalog-line-watch.js +94 -0
  120. package/dist/shared/components/item-edit/coedit/collab.js +84 -0
  121. package/dist/shared/components/item-edit/coedit/context.js +24 -0
  122. package/dist/shared/components/item-edit/coedit/cursors.js +103 -0
  123. package/dist/shared/components/item-edit/coedit/safe-link.js +15 -0
  124. package/dist/shared/components/item-edit/coedit/session.js +382 -0
  125. package/dist/shared/components/item-edit/coedit/useCoedit.js +49 -0
  126. package/dist/shared/components/item-edit/file-live.js +77 -0
  127. package/dist/shared/components/item-edit/file-processing.js +87 -0
  128. package/dist/shared/components/item-edit/layout-switch.js +148 -0
  129. package/dist/shared/components/item-edit/live-related.js +23 -0
  130. package/dist/shared/components/item-edit/live-title.js +66 -0
  131. package/dist/shared/components/item-edit/partner-needs.js +142 -0
  132. package/dist/shared/components/item-edit/removed-line.js +58 -0
  133. package/dist/shared/components/item-edit/render-stability.js +70 -59
  134. package/dist/shared/components/layout-editor/ChangeNote.js +36 -34
  135. package/dist/shared/components/layout-editor/CollabParts.js +72 -70
  136. package/dist/shared/components/layout-editor/LayoutEditor.js +306 -303
  137. package/dist/shared/components/list/InlineEdit.js +504 -208
  138. package/dist/shared/components/list/ListViewers.js +81 -0
  139. package/dist/shared/components/merge/MergeRecordsDialog.js +1227 -0
  140. package/dist/shared/components/merge/MergeWithFlow.js +290 -0
  141. package/dist/shared/components/merge/merge-values.js +110 -0
  142. package/dist/shared/components/monitoring/InactiveUserLinksView.js +285 -258
  143. package/dist/shared/components/notifications/NotificationCenterView.js +388 -321
  144. package/dist/shared/components/notifications/NotificationDetailBits.js +205 -130
  145. package/dist/shared/components/notifications/NotificationRulesEditor.js +72 -52
  146. package/dist/shared/components/notifications/bundles.js +21 -19
  147. package/dist/shared/components/notifications/resolved-line.js +25 -0
  148. package/dist/shared/components/ops/OpsTasksView.js +45 -44
  149. package/dist/shared/components/panels/AccessGrantedNote.js +85 -0
  150. package/dist/shared/components/panels/AlertBanners.js +132 -0
  151. package/dist/shared/components/panels/AsyncUserPicker.js +54 -45
  152. package/dist/shared/components/panels/BranchLanes.js +82 -54
  153. package/dist/shared/components/panels/CommentAwareness.js +332 -0
  154. package/dist/shared/components/panels/CommentImages.js +219 -0
  155. package/dist/shared/components/panels/CommentPanel.js +649 -530
  156. package/dist/shared/components/panels/ExternalRequestsChip.js +98 -80
  157. package/dist/shared/components/panels/NewSinceChip.js +16 -0
  158. package/dist/shared/components/panels/OwnerOpenedLine.js +85 -0
  159. package/dist/shared/components/panels/PipelinePanel.js +1644 -1494
  160. package/dist/shared/components/panels/ResubmissionDiff.js +293 -0
  161. package/dist/shared/components/panels/SlaBreachBanner.js +30 -29
  162. package/dist/shared/components/panels/SlaClock.js +130 -99
  163. package/dist/shared/components/panels/TaskPanel.js +308 -287
  164. package/dist/shared/components/panels/unseen-move-check.js +101 -0
  165. package/dist/shared/components/pipeline/OwnerMatrix.js +80 -71
  166. package/dist/shared/components/pipeline/OwnerMatrixSheet.js +495 -0
  167. package/dist/shared/components/pipeline/PipelineEditorView.js +1855 -1771
  168. package/dist/shared/components/profile/AgentNameField.js +141 -0
  169. package/dist/shared/components/profile/AgentsPanel.js +55 -46
  170. package/dist/shared/components/profile/PersonAccess.js +398 -330
  171. package/dist/shared/components/profile/PersonAdminTools.js +127 -113
  172. package/dist/shared/components/profile/PersonProfile.js +81 -73
  173. package/dist/shared/components/profile/SignInTroubleshooter.js +361 -0
  174. package/dist/shared/components/queue/QueueBulkBar.js +101 -84
  175. package/dist/shared/components/queue/QueueItemSheet.js +66 -66
  176. package/dist/shared/components/queue/QueueTeamStrip.js +279 -0
  177. package/dist/shared/components/queue/QueueWorklist.js +2076 -1686
  178. package/dist/shared/components/queue/queue-totals.js +92 -0
  179. package/dist/shared/components/queue/worklist-helpers.js +18 -14
  180. package/dist/shared/components/send-view/SendViewButton.js +136 -0
  181. package/dist/shared/components/send-view/SentViewCards.js +147 -0
  182. package/dist/shared/components/support/ReportProblem.js +1 -0
  183. package/dist/shared/components/support/ScreenShare.js +554 -0
  184. package/dist/shared/components/support/SupportView.js +160 -129
  185. package/dist/shared/components/support/TicketDetailSheet.js +101 -89
  186. package/dist/shared/components/watch-list/WatchDock.js +1044 -0
  187. package/dist/shared/components/watch-list/WatchExtras.js +723 -0
  188. package/dist/shared/components/watch-list/WatchListButton.js +46 -0
  189. package/dist/shared/components/watch-list/WatchPinButton.js +67 -0
  190. package/dist/shared/components/watch-list/WatchRows.js +348 -0
  191. package/dist/shared/lib/activity-sentence.js +87 -75
  192. package/dist/shared/lib/agent-presence.js +46 -0
  193. package/dist/shared/lib/approval-progress.js +49 -0
  194. package/dist/shared/lib/attention-prefs.js +27 -0
  195. package/dist/shared/lib/cell-locks.js +56 -0
  196. package/dist/shared/lib/co-edit.js +166 -0
  197. package/dist/shared/lib/coedit-registry.js +44 -0
  198. package/dist/shared/lib/comment-awareness.js +124 -0
  199. package/dist/shared/lib/comment-images.js +45 -0
  200. package/dist/shared/lib/config-watch.js +94 -0
  201. package/dist/shared/lib/copy-rules.js +65 -0
  202. package/dist/shared/lib/count-step.js +30 -0
  203. package/dist/shared/lib/deadline-ticker.js +68 -0
  204. package/dist/shared/lib/derived-causes.js +115 -0
  205. package/dist/shared/lib/draft-store.js +114 -85
  206. package/dist/shared/lib/error-hints.js +1 -0
  207. package/dist/shared/lib/field-merge.js +126 -0
  208. package/dist/shared/lib/filter-sentence.js +10 -10
  209. package/dist/shared/lib/focus-mode.js +16 -12
  210. package/dist/shared/lib/grid-cursors.js +77 -0
  211. package/dist/shared/lib/grid-presence.js +182 -0
  212. package/dist/shared/lib/idle-reload.js +100 -73
  213. package/dist/shared/lib/in-step.js +45 -0
  214. package/dist/shared/lib/integration-chip.js +19 -18
  215. package/dist/shared/lib/line-locks.js +141 -0
  216. package/dist/shared/lib/line-split.js +41 -0
  217. package/dist/shared/lib/linked-changes.js +150 -0
  218. package/dist/shared/lib/list-link.js +56 -50
  219. package/dist/shared/lib/list-return.js +231 -0
  220. package/dist/shared/lib/list-viewers.js +52 -0
  221. package/dist/shared/lib/live-announcer.js +86 -0
  222. package/dist/shared/lib/live-counts.js +85 -0
  223. package/dist/shared/lib/live-data-changed.js +108 -0
  224. package/dist/shared/lib/live-deltas.js +81 -0
  225. package/dist/shared/lib/live-findings.js +113 -0
  226. package/dist/shared/lib/live-groups.js +122 -0
  227. package/dist/shared/lib/live-link-labels.js +162 -0
  228. package/dist/shared/lib/live-list-flow.js +334 -0
  229. package/dist/shared/lib/live-list.js +143 -129
  230. package/dist/shared/lib/live-moves.js +51 -0
  231. package/dist/shared/lib/live-ops.js +26 -26
  232. package/dist/shared/lib/live-pickers.js +7 -0
  233. package/dist/shared/lib/live-preference.js +184 -0
  234. package/dist/shared/lib/live-queries.js +226 -181
  235. package/dist/shared/lib/live-screen.js +333 -0
  236. package/dist/shared/lib/live-search.js +108 -0
  237. package/dist/shared/lib/live-seen.js +35 -0
  238. package/dist/shared/lib/live-views.js +100 -0
  239. package/dist/shared/lib/live.js +159 -133
  240. package/dist/shared/lib/missed-updates.js +198 -0
  241. package/dist/shared/lib/newer-file.js +56 -0
  242. package/dist/shared/lib/notification-sound.js +42 -20
  243. package/dist/shared/lib/own-writes.js +59 -41
  244. package/dist/shared/lib/picker-badges.js +94 -0
  245. package/dist/shared/lib/presence-signals.js +131 -84
  246. package/dist/shared/lib/realtime.js +49 -24
  247. package/dist/shared/lib/record-gaps.js +85 -0
  248. package/dist/shared/lib/record-outbox.js +369 -222
  249. package/dist/shared/lib/record-peek.js +75 -0
  250. package/dist/shared/lib/record-tabs.js +92 -72
  251. package/dist/shared/lib/relative-ticker.js +42 -0
  252. package/dist/shared/lib/request-gate.js +119 -119
  253. package/dist/shared/lib/rollup-recalc.js +107 -0
  254. package/dist/shared/lib/room-gaps.js +40 -36
  255. package/dist/shared/lib/rum.js +137 -87
  256. package/dist/shared/lib/save-progress.js +20 -0
  257. package/dist/shared/lib/scheduled-countdown.js +67 -0
  258. package/dist/shared/lib/screen-refresh.js +160 -0
  259. package/dist/shared/lib/screen-share.js +234 -0
  260. package/dist/shared/lib/seen-since.js +74 -0
  261. package/dist/shared/lib/selection-watch.js +205 -0
  262. package/dist/shared/lib/send-status.js +132 -0
  263. package/dist/shared/lib/send-view.js +23 -0
  264. package/dist/shared/lib/socket-liveness.js +155 -0
  265. package/dist/shared/lib/socket-realtime.js +168 -140
  266. package/dist/shared/lib/state-census.js +53 -0
  267. package/dist/shared/lib/summary-mode.js +61 -39
  268. package/dist/shared/lib/tab-attention.js +143 -32
  269. package/dist/shared/lib/table-density.js +64 -0
  270. package/dist/shared/lib/track-travel.js +40 -0
  271. package/dist/shared/lib/unseen-changes.js +68 -0
  272. package/dist/shared/lib/upload-file.js +33 -0
  273. package/dist/shared/lib/upload-presence.js +127 -0
  274. package/dist/shared/lib/urgent-chime.js +65 -0
  275. package/dist/shared/lib/use-online-users.js +32 -11
  276. package/dist/shared/lib/user-sync.js +155 -39
  277. package/dist/shared/lib/waiting-count.js +44 -0
  278. package/dist/shared/lib/watch-desktop.js +83 -0
  279. package/dist/shared/lib/watch-list.js +447 -0
  280. package/dist/shared/lib/widget-image-render.js +64 -0
  281. package/dist/shared/lib/widget-image.js +111 -0
  282. package/dist/shared/lib/worker-socket.js +130 -104
  283. package/dist/shared/lib/write-to-screen.js +133 -0
  284. package/package.json +1 -1
  285. package/styles.css +49 -1
@@ -1,604 +1,630 @@
1
- import { jsxs as f, jsx as d, Fragment as ye } from "react/jsx-runtime";
2
- import { useQueryClient as st, useQuery as Z } from "@tanstack/react-query";
3
- import { Loader2 as Qe, ChevronRight as Ie } from "lucide-react";
4
- import { useState as ee, useRef as Pe, useEffect as he, useMemo as N } from "react";
5
- import { useNivaroClient as lt } from "../context.js";
6
- import { get as te, post as Be, patch as at } from "../lib/commands.js";
7
- import { evaluateNumeric as nt } from "../lib/expression.js";
8
- import { userErrorMessage as ot } from "../lib/safe-error.js";
9
- import { cn as $ } from "../lib/utils.js";
10
- import { RelationCombobox as it } from "./item-edit/RelationCombobox.js";
11
- import { colorPair as ct } from "./QueryTable.js";
12
- const W = "__uncat__", J = "__bucket__";
13
- function xe(t, y) {
1
+ import { jsxs as b, jsx as d, Fragment as we } from "react/jsx-runtime";
2
+ import { useQueryClient as ft, useQuery as re } from "@tanstack/react-query";
3
+ import { Loader2 as rt, ChevronRight as lt } from "lucide-react";
4
+ import { useState as le, useRef as de, useEffect as ve, useMemo as g } from "react";
5
+ import { useNivaroClient as ht } from "../context.js";
6
+ import { get as se, post as st, patch as xt } from "../lib/commands.js";
7
+ import { evaluateNumeric as _t } from "../lib/expression.js";
8
+ import { gridPageKey as yt, useGridPresence as kt, gridPresenceCell as vt } from "../lib/grid-presence.js";
9
+ import { userErrorMessage as Nt } from "../lib/safe-error.js";
10
+ import { cn as S } from "../lib/utils.js";
11
+ import { GridPresenceLine as gt } from "./GridPresenceLine.js";
12
+ import { RelationCombobox as wt } from "./item-edit/RelationCombobox.js";
13
+ import { useRecordLabels as $t } from "./item-edit/useRecordLabels.js";
14
+ import { colorPair as St } from "./QueryTable.js";
15
+ const J = "__uncat__", V = "__bucket__";
16
+ function Ne(t, _) {
14
17
  if (!t) return;
15
- const w = (h) => typeof h == "string" && h.startsWith("$scope.") ? y[h.slice(7)] : Array.isArray(h) ? h.map(w) : h && typeof h == "object" ? Object.fromEntries(
16
- Object.entries(h).map(([v, x]) => [v, w(x)])
17
- ) : h;
18
- return w(t);
18
+ const $ = (f) => typeof f == "string" && f.startsWith("$scope.") ? _[f.slice(7)] : Array.isArray(f) ? f.map($) : f && typeof f == "object" ? Object.fromEntries(
19
+ Object.entries(f).map(([N, h]) => [N, $(h)])
20
+ ) : f;
21
+ return $(t);
19
22
  }
20
- function ke(t) {
21
- return t === void 0 ? !0 : Array.isArray(t) ? t.some(ke) : t && typeof t == "object" ? Object.values(t).some(ke) : !1;
23
+ function $e(t) {
24
+ return t === void 0 ? !0 : Array.isArray(t) ? t.some($e) : t && typeof t == "object" ? Object.values(t).some($e) : !1;
22
25
  }
23
- function re(t, y) {
26
+ function ae(t, _) {
24
27
  if (t && typeof t == "object") {
25
- const v = y.replace(/\[\d+\]/g, "");
26
- if (v in t)
27
- return t[v] ?? null;
28
+ const N = _.replace(/\[\d+\]/g, "");
29
+ if (N in t)
30
+ return t[N] ?? null;
28
31
  }
29
- const w = y.split(".").flatMap((v) => {
30
- const x = /^(\w+)\[(\d+)\]$/.exec(v);
31
- return x ? [x[1], Number(x[2])] : [v];
32
+ const $ = _.split(".").flatMap((N) => {
33
+ const h = /^(\w+)\[(\d+)\]$/.exec(N);
34
+ return h ? [h[1], Number(h[2])] : [N];
32
35
  });
33
- let h = t;
34
- for (const v of w) {
35
- if (h == null || typeof h != "object") return null;
36
- h = h[v];
36
+ let f = t;
37
+ for (const N of $) {
38
+ if (f == null || typeof f != "object") return null;
39
+ f = f[N];
37
40
  }
38
- return h ?? null;
41
+ return f ?? null;
39
42
  }
40
- function _e(t, y) {
41
- return t.replace(/\{\{\s*([\w.[\]]+)\s*\}\}/g, (w, h) => {
42
- const v = re(y, h);
43
- return v == null ? "" : String(v);
43
+ function ge(t, _) {
44
+ return t.replace(/\{\{\s*([\w.[\]]+)\s*\}\}/g, ($, f) => {
45
+ const N = ae(_, f);
46
+ return N == null ? "" : String(N);
44
47
  });
45
48
  }
46
- function O(t, y) {
47
- const w = Number(t);
48
- return t == null || t === "" || !Number.isFinite(w) ? "—" : y === "currency" ? w.toLocaleString("en-US", { style: "currency", currency: "USD" }) : w.toLocaleString("en-US", { maximumFractionDigits: 2 });
49
+ function L(t, _) {
50
+ const $ = Number(t);
51
+ return t == null || t === "" || !Number.isFinite($) ? "—" : _ === "currency" ? $.toLocaleString("en-US", { style: "currency", currency: "USD" }) : $.toLocaleString("en-US", { maximumFractionDigits: 2 });
49
52
  }
50
- function vt({
53
+ function Ut({
51
54
  config: t,
52
- initialScope: y,
53
- lockScope: w = !1
55
+ initialScope: _,
56
+ lockScope: $ = !1
54
57
  }) {
55
- var Ge, Ue, We, Je, Ve, De;
56
- const h = lt(), v = st(), [x, oe] = ee(y ?? {}), ve = Pe(y);
57
- he(() => {
58
- ve.current !== y && (ve.current = y, y && oe((e) => ({ ...e, ...y })));
59
- }, [y]);
60
- const [L, V] = ee({}), [Ne, we] = ee(!1), [ge, ie] = ee(null), [$e, Se] = ee(/* @__PURE__ */ new Set()), R = t.scope_fields.every(
61
- (e) => x[e.field] !== null && x[e.field] !== void 0 && x[e.field] !== ""
62
- ), P = t.option_label ?? "name", z = JSON.stringify(x), p = t.group, je = N(() => {
63
- var r, l;
58
+ var Be, Ie, He, Xe, Ye, Ze, et;
59
+ const f = ht(), N = ft(), [h, ue] = le(_ ?? {}), Se = de(_);
60
+ ve(() => {
61
+ Se.current !== _ && (Se.current = _, _ && ue((e) => ({ ...e, ..._ })));
62
+ }, [_]);
63
+ const [K, D] = le({}), [je, Ce] = le(!1), [qe, me] = le(null), [Oe, Le] = le(/* @__PURE__ */ new Set()), F = t.scope_fields.every(
64
+ (e) => h[e.field] !== null && h[e.field] !== void 0 && h[e.field] !== ""
65
+ ), Fe = de(null), M = t.scope_fields[0], Q = M && F ? String(h[M.field]) : null, nt = yt(
66
+ "matrix",
67
+ t.target_collection,
68
+ ...t.scope_fields.slice(1).map((e) => String(h[e.field] ?? ""))
69
+ ), Me = g(() => Q ? [Q] : [], [Q]), { editors: pe } = kt({
70
+ page: nt,
71
+ collection: M == null ? void 0 : M.collection,
72
+ items: Me,
73
+ containerRef: Fe,
74
+ enabled: !!Q
75
+ }), ot = $t(
76
+ M == null ? void 0 : M.collection,
77
+ Me,
78
+ pe.length > 0
79
+ ), Re = de(/* @__PURE__ */ new Map()), X = t.option_label ?? "name", T = JSON.stringify(h), m = t.group, ze = g(() => {
80
+ var r, s;
64
81
  const e = [
65
82
  t.option_label_template,
66
83
  (r = t.option_section) == null ? void 0 : r.label_template,
67
- (l = t.option_section) == null ? void 0 : l.row_label_template
84
+ (s = t.option_section) == null ? void 0 : s.row_label_template
68
85
  ].filter((a) => !!a);
69
- if (e.length === 0) return `id,${P}`;
70
- const s = e.flatMap(
86
+ if (e.length === 0) return `id,${X}`;
87
+ const l = e.flatMap(
71
88
  (a) => [...a.matchAll(/\{\{\s*([\w.[\]]+)\s*\}\}/g)].map((o) => o[1].replace(/\[\d+\]/g, ""))
72
89
  );
73
- return t.option_label_template || s.push(P), ["id", ...new Set(s)].join(",");
74
- }, [t.option_label_template, t.option_section, P]), { data: qe = [], isLoading: Xe } = Z({
75
- queryKey: ["matrix-options", t.option_collection, je, z],
90
+ return t.option_label_template || l.push(X), ["id", ...new Set(l)].join(",");
91
+ }, [t.option_label_template, t.option_section, X]), { data: Ke = [], isLoading: it } = re({
92
+ queryKey: ["matrix-options", t.option_collection, ze, T],
76
93
  queryFn: () => {
77
- const e = xe(t.option_filter, x);
78
- return h.request(
79
- te(`/items/${t.option_collection}`, {
94
+ const e = Ne(t.option_filter, h);
95
+ return f.request(
96
+ se(`/items/${t.option_collection}`, {
80
97
  limit: 500,
81
- fields: je,
98
+ fields: ze,
82
99
  ...e ? { filter: JSON.stringify(e) } : {}
83
100
  })
84
- ).then((s) => s.data ?? []);
101
+ ).then((l) => l.data ?? []);
85
102
  },
86
- enabled: R,
103
+ enabled: F,
87
104
  staleTime: 3e4
88
- }), { data: T = [] } = Z({
89
- queryKey: ["matrix-groups", p == null ? void 0 : p.collection, z],
105
+ }), { data: E = [] } = re({
106
+ queryKey: ["matrix-groups", m == null ? void 0 : m.collection, T],
90
107
  queryFn: () => {
91
- const e = xe(p == null ? void 0 : p.filter, x);
92
- return h.request(
93
- te(`/items/${p.collection}`, {
108
+ const e = Ne(m == null ? void 0 : m.filter, h);
109
+ return f.request(
110
+ se(`/items/${m.collection}`, {
94
111
  limit: 200,
95
112
  fields: [
96
113
  "id",
97
- p.label_field ?? "name",
114
+ m.label_field ?? "name",
98
115
  ...Object.values(t.group_seeds ?? {})
99
116
  ].join(","),
100
117
  ...e ? { filter: JSON.stringify(e) } : {}
101
118
  })
102
- ).then((s) => s.data ?? []);
119
+ ).then((l) => l.data ?? []);
103
120
  },
104
- enabled: R && !!p,
121
+ enabled: F && !!m,
105
122
  staleTime: 3e4
106
- }), Ye = N(() => {
107
- var s;
123
+ }), ct = g(() => {
124
+ var l;
108
125
  const e = ["id", t.key_field, t.value_field];
109
- return p && e.push(p.field), (s = t.specials) != null && s.bucket && e.push(t.specials.bucket.flag_field), e.join(",");
110
- }, [t, p]), { data: Ce = [], isLoading: ce } = Z({
111
- queryKey: ["matrix-targets", t.target_collection, z],
126
+ return m && e.push(m.field), (l = t.specials) != null && l.bucket && e.push(t.specials.bucket.flag_field), e.join(",");
127
+ }, [t, m]), { data: Te = [], isLoading: be } = re({
128
+ queryKey: ["matrix-targets", t.target_collection, T],
112
129
  queryFn: () => {
113
130
  const e = {};
114
- for (const s of t.scope_fields) e[s.field] = { _eq: x[s.field] };
115
- return h.request(
116
- te(`/items/${t.target_collection}`, {
131
+ for (const l of t.scope_fields) e[l.field] = { _eq: h[l.field] };
132
+ return f.request(
133
+ se(`/items/${t.target_collection}`, {
117
134
  limit: 2e3,
118
- fields: Ye,
135
+ fields: ct,
119
136
  filter: JSON.stringify(e)
120
137
  })
121
- ).then((s) => s.data ?? []);
138
+ ).then((l) => l.data ?? []);
122
139
  },
123
- enabled: R,
140
+ enabled: F,
124
141
  staleTime: 0
125
- }), B = N(() => {
142
+ }), Y = g(() => {
126
143
  var r;
127
- const e = /* @__PURE__ */ new Map(), s = (l) => {
128
- if (typeof l != "string") return;
129
- const a = /^\$(\w+)\.(.+)$/.exec(l);
144
+ const e = /* @__PURE__ */ new Map(), l = (s) => {
145
+ if (typeof s != "string") return;
146
+ const a = /^\$(\w+)\.(.+)$/.exec(s);
130
147
  if (!a || a[1] === "scope") return;
131
148
  const o = e.get(a[1]) ?? /* @__PURE__ */ new Set();
132
149
  o.add(a[2].replace(/\[\d+\]/g, "")), e.set(a[1], o);
133
150
  };
134
- for (const l of Object.values(t.scope_seeds ?? {})) s(l);
135
- for (const l of Object.values(t.scope_defaults ?? {})) s(l);
136
- for (const l of Object.values(((r = t.metrics) == null ? void 0 : r.params) ?? {})) s(l);
151
+ for (const s of Object.values(t.scope_seeds ?? {})) l(s);
152
+ for (const s of Object.values(t.scope_defaults ?? {})) l(s);
153
+ for (const s of Object.values(((r = t.metrics) == null ? void 0 : r.params) ?? {})) l(s);
137
154
  if (t.cap) {
138
- const l = e.get(t.cap.scope_field) ?? /* @__PURE__ */ new Set();
139
- l.add(t.cap.field), e.set(t.cap.scope_field, l);
155
+ const s = e.get(t.cap.scope_field) ?? /* @__PURE__ */ new Set();
156
+ s.add(t.cap.field), e.set(t.cap.scope_field, s);
140
157
  }
141
158
  return e;
142
- }, [t.scope_seeds, t.scope_defaults, t.metrics, t.cap]), { data: E = {} } = Z({
143
- queryKey: ["matrix-scope-records", z, [...B.keys()].join(",")],
159
+ }, [t.scope_seeds, t.scope_defaults, t.metrics, t.cap]), { data: G = {} } = re({
160
+ queryKey: ["matrix-scope-records", T, [...Y.keys()].join(",")],
144
161
  queryFn: async () => {
145
162
  const e = {};
146
- for (const [s, r] of B) {
147
- const l = t.scope_fields.find((i) => i.field === s), a = x[s];
148
- if (!l || a == null) continue;
149
- const o = [...r].filter((i) => !i.includes(".")), n = [...r].filter((i) => i.includes(".")), u = await h.request(
150
- te(`/items/${l.collection}/${a}`, { fields: ["id", ...o].join(",") })
151
- ).then((i) => i.data).catch(() => null);
163
+ for (const [l, r] of Y) {
164
+ const s = t.scope_fields.find((n) => n.field === l), a = h[l];
165
+ if (!s || a == null) continue;
166
+ const o = [...r].filter((n) => !n.includes(".")), i = [...r].filter((n) => n.includes(".")), u = await f.request(
167
+ se(`/items/${s.collection}/${a}`, { fields: ["id", ...o].join(",") })
168
+ ).then((n) => n.data).catch(() => null);
152
169
  if (u) {
153
- if (n.length > 0) {
154
- const i = await h.request(
155
- te(`/items/${l.collection}/${a}/resolve-paths`, { paths: n.join(",") })
156
- ).then((b) => b.data ?? {}).catch(() => ({}));
157
- for (const [b, c] of Object.entries(i))
158
- u[b] = c != null && c.ids && c.ids.length > 0 ? c.ids[0] : (c == null ? void 0 : c.value) ?? null;
170
+ if (i.length > 0) {
171
+ const n = await f.request(
172
+ se(`/items/${s.collection}/${a}/resolve-paths`, { paths: i.join(",") })
173
+ ).then((p) => p.data ?? {}).catch(() => ({}));
174
+ for (const [p, c] of Object.entries(n))
175
+ u[p] = c != null && c.ids && c.ids.length > 0 ? c.ids[0] : (c == null ? void 0 : c.value) ?? null;
159
176
  }
160
- e[s] = u;
177
+ e[l] = u;
161
178
  }
162
179
  }
163
180
  return e;
164
181
  },
165
182
  // Per-field, not scopeReady — scope_defaults must resolve while other
166
183
  // pickers are still empty (project → default sub type).
167
- enabled: B.size > 0 && [...B.keys()].some(
168
- (e) => x[e] !== null && x[e] !== void 0 && x[e] !== ""
184
+ enabled: Y.size > 0 && [...Y.keys()].some(
185
+ (e) => h[e] !== null && h[e] !== void 0 && h[e] !== ""
169
186
  ),
170
187
  staleTime: 3e4
171
188
  });
172
- he(() => {
189
+ ve(() => {
173
190
  if (t.scope_defaults)
174
- for (const [e, s] of Object.entries(t.scope_defaults)) {
175
- if (x[e] != null && x[e] !== "") continue;
176
- const r = /^\$(\w+)\.(.+)$/.exec(s);
191
+ for (const [e, l] of Object.entries(t.scope_defaults)) {
192
+ if (h[e] != null && h[e] !== "") continue;
193
+ const r = /^\$(\w+)\.(.+)$/.exec(l);
177
194
  if (!r) continue;
178
- const l = re(E[r[1]] ?? {}, r[2]);
179
- l != null && l !== "" && oe((a) => ({ ...a, [e]: l }));
195
+ const s = ae(G[r[1]] ?? {}, r[2]);
196
+ s != null && s !== "" && ue((a) => ({ ...a, [e]: s }));
180
197
  }
181
- }, [E, t.scope_defaults, x]);
182
- const { data: se = [] } = Z({
198
+ }, [G, t.scope_defaults, h]);
199
+ const { data: ne = [] } = re({
183
200
  queryKey: [
184
201
  "matrix-metrics",
185
- (Ge = t.metrics) == null ? void 0 : Ge.query_slug,
186
- z,
187
- Object.keys(E).length
202
+ (Be = t.metrics) == null ? void 0 : Be.query_slug,
203
+ T,
204
+ Object.keys(G).length
188
205
  ],
189
206
  queryFn: () => {
190
207
  var e;
191
- return h.request(
192
- Be(`/custom-queries/${t.metrics.query_slug}/execute`, {
208
+ return f.request(
209
+ st(`/custom-queries/${t.metrics.query_slug}/execute`, {
193
210
  params: Object.fromEntries(
194
- Object.entries(((e = t.metrics) == null ? void 0 : e.params) ?? {}).map(([s, r]) => {
211
+ Object.entries(((e = t.metrics) == null ? void 0 : e.params) ?? {}).map(([l, r]) => {
195
212
  if (typeof r == "string" && r.startsWith("$scope."))
196
- return [s, x[r.slice(7)]];
213
+ return [l, h[r.slice(7)]];
197
214
  if (typeof r == "string" && r.startsWith("$")) {
198
- const l = /^\$(\w+)\.(.+)$/.exec(r);
199
- if (l) return [s, re(E[l[1]] ?? {}, l[2])];
215
+ const s = /^\$(\w+)\.(.+)$/.exec(r);
216
+ if (s) return [l, ae(G[s[1]] ?? {}, s[2])];
200
217
  }
201
- return [s, r];
218
+ return [l, r];
202
219
  })
203
220
  )
204
221
  })
205
- ).then((s) => s.data ?? []);
222
+ ).then((l) => l.data ?? []);
206
223
  },
207
- enabled: R && !!t.metrics && (B.size === 0 || Object.keys(E).length > 0),
224
+ enabled: F && !!t.metrics && (Y.size === 0 || Object.keys(G).length > 0),
208
225
  staleTime: 3e4
209
- }), Ze = (e) => {
226
+ }), dt = (e) => {
210
227
  var a;
211
- const s = p ? String(e[p.field] ?? "") : "", r = (a = t.specials) == null ? void 0 : a.bucket;
228
+ const l = m ? String(e[m.field] ?? "") : "", r = (a = t.specials) == null ? void 0 : a.bucket;
212
229
  if (r && (e[r.flag_field] === !0 || e[r.flag_field] === 1))
213
- return `${s}|${J}`;
214
- const l = e[t.key_field];
215
- return `${s}|${l == null ? W : String(l)}`;
216
- }, k = N(() => {
230
+ return `${l}|${V}`;
231
+ const s = e[t.key_field];
232
+ return `${l}|${s == null ? J : String(s)}`;
233
+ }, y = g(() => {
217
234
  const e = /* @__PURE__ */ new Map();
218
- for (const s of Ce) {
219
- const r = Ze(s), l = e.get(r) ?? { ids: [], total: 0 };
220
- l.ids.push(s.id), l.total += Number(s[t.value_field]) || 0, e.set(r, l);
235
+ for (const l of Te) {
236
+ const r = dt(l), s = e.get(r) ?? { ids: [], total: 0 };
237
+ s.ids.push(l.id), s.total += Number(l[t.value_field]) || 0, e.set(r, s);
221
238
  }
222
239
  return e;
223
- }, [Ce, t.value_field]), le = (e, s) => {
224
- var o, n, u, i;
225
- const r = t.metrics, l = {};
226
- if (!r) return l;
227
- const a = s === W ? ((n = (o = t.specials) == null ? void 0 : o.uncategorized) == null ? void 0 : n.metric_value) ?? null : s === J ? ((i = (u = t.specials) == null ? void 0 : u.bucket) == null ? void 0 : i.metric_value) ?? null : s;
228
- for (const b of se) {
229
- if (r.match_group_field && String(b[r.match_group_field] ?? "") !== e) continue;
230
- const c = b[r.match_option_field], _ = a === null || a === 0 || a === "0", g = c == null || c === 0 || c === "0" || c === "";
231
- if (_ ? g : String(c ?? "") === String(a))
232
- for (const m of r.columns)
233
- l[m.field] = (l[m.field] ?? 0) + (Number(b[m.field]) || 0);
240
+ }, [Te, t.value_field]), oe = (e, l) => {
241
+ var o, i, u, n;
242
+ const r = t.metrics, s = {};
243
+ if (!r) return s;
244
+ const a = l === J ? ((i = (o = t.specials) == null ? void 0 : o.uncategorized) == null ? void 0 : i.metric_value) ?? null : l === V ? ((n = (u = t.specials) == null ? void 0 : u.bucket) == null ? void 0 : n.metric_value) ?? null : l;
245
+ for (const p of ne) {
246
+ if (r.match_group_field && String(p[r.match_group_field] ?? "") !== e) continue;
247
+ const c = p[r.match_option_field], k = a === null || a === 0 || a === "0", v = c == null || c === 0 || c === "0" || c === "";
248
+ if (k ? v : String(c ?? "") === String(a))
249
+ for (const x of r.columns)
250
+ s[x.field] = (s[x.field] ?? 0) + (Number(p[x.field]) || 0);
234
251
  }
235
- return l;
236
- }, S = N(() => {
237
- const e = (r) => t.option_label_template ? _e(t.option_label_template, r) : String(r[P] ?? r.id), s = t.option_section;
238
- return [...qe].map((r) => {
239
- const l = e(r), a = s ? _e(s.label_template, r) : "", o = s != null && s.row_label_template && _e(s.row_label_template, r) || l;
240
- return { key: String(r.id), label: s ? o : l, section: a };
241
- }).sort((r, l) => r.section.localeCompare(l.section) || r.label.localeCompare(l.label));
242
- }, [qe, t.option_label_template, t.option_section, P]), ae = N(() => {
252
+ return s;
253
+ }, j = g(() => {
254
+ const e = (r) => t.option_label_template ? ge(t.option_label_template, r) : String(r[X] ?? r.id), l = t.option_section;
255
+ return [...Ke].map((r) => {
256
+ const s = e(r), a = l ? ge(l.label_template, r) : "", o = l != null && l.row_label_template && ge(l.row_label_template, r) || s;
257
+ return { key: String(r.id), label: l ? o : s, section: a };
258
+ }).sort((r, s) => r.section.localeCompare(s.section) || r.label.localeCompare(s.label));
259
+ }, [Ke, t.option_label_template, t.option_section, X]), ie = g(() => {
243
260
  if (!t.option_section) return [];
244
261
  const e = /* @__PURE__ */ new Map();
245
- for (const s of S) {
246
- const r = e.get(s.section) ?? [];
247
- r.push(s), e.set(s.section, r);
262
+ for (const l of j) {
263
+ const r = e.get(l.section) ?? [];
264
+ r.push(l), e.set(l.section, r);
248
265
  }
249
- return [...e.entries()].map(([s, r]) => ({ name: s, rows: r }));
250
- }, [S, t.option_section]), Oe = Pe(null);
251
- he(() => {
252
- if (!p || T.length === 0 || ce) return;
253
- const e = `${z}#${t.option_section && ae.length > 0 ? 1 : 0}`;
254
- if (Oe.current === e) return;
255
- Oe.current = e;
256
- const s = new Set([...k.keys()].map((l) => l.split("|")[0])), r = new Set(T.map((l) => String(l.id)).filter((l) => !s.has(l)));
266
+ return [...e.entries()].map(([l, r]) => ({ name: l, rows: r }));
267
+ }, [j, t.option_section]), Ee = de(null);
268
+ ve(() => {
269
+ if (!m || E.length === 0 || be) return;
270
+ const e = `${T}#${t.option_section && ie.length > 0 ? 1 : 0}`;
271
+ if (Ee.current === e) return;
272
+ Ee.current = e;
273
+ const l = new Set([...y.keys()].map((s) => s.split("|")[0])), r = new Set(E.map((s) => String(s.id)).filter((s) => !l.has(s)));
257
274
  if (t.option_section) {
258
- const l = new Set(k.keys());
259
- for (const a of T) {
275
+ const s = new Set(y.keys());
276
+ for (const a of E) {
260
277
  const o = String(a.id);
261
- for (const n of ae)
262
- n.rows.some((u) => l.has(`${o}|${u.key}`)) || r.add(`s:${o}|${n.name}`);
278
+ for (const i of ie)
279
+ i.rows.some((u) => s.has(`${o}|${u.key}`)) || r.add(`s:${o}|${i.name}`);
263
280
  }
264
281
  }
265
- Se(r);
266
- }, [T, k, ce, z, p, ae, t.option_section]);
267
- const j = N(() => p ? [...T].map((e) => ({ id: String(e.id), label: String(e[p.label_field ?? "name"] ?? e.id) })).sort((e, s) => e.label.localeCompare(s.label)) : [{ id: "", label: "" }], [T, p]), Fe = N(() => {
268
- var s, r;
282
+ Le(r);
283
+ }, [E, y, be, T, m, ie, t.option_section]);
284
+ const q = g(() => m ? [...E].map((e) => ({ id: String(e.id), label: String(e[m.label_field ?? "name"] ?? e.id) })).sort((e, l) => e.label.localeCompare(l.label)) : [{ id: "", label: "" }], [E, m]), Ge = g(() => {
285
+ var l, r;
269
286
  const e = /* @__PURE__ */ new Set();
270
- for (const l of j) {
271
- for (const a of S) e.add(`${l.id}|${a.key}`);
272
- (s = t.specials) != null && s.uncategorized && e.add(`${l.id}|${W}`), (r = t.specials) != null && r.bucket && e.add(`${l.id}|${J}`);
287
+ for (const s of q) {
288
+ for (const a of j) e.add(`${s.id}|${a.key}`);
289
+ (l = t.specials) != null && l.uncategorized && e.add(`${s.id}|${J}`), (r = t.specials) != null && r.bucket && e.add(`${s.id}|${V}`);
273
290
  }
274
291
  return e;
275
- }, [j, S, t.specials]), K = N(() => {
292
+ }, [q, j, t.specials]), A = g(() => {
276
293
  let e = 0;
277
- for (const [s, r] of k) Fe.has(s) || (e += r.total);
294
+ for (const [l, r] of y) Ge.has(l) || (e += r.total);
278
295
  return e;
279
- }, [k, Fe]), D = t.cap ? Number(re(E[t.cap.scope_field] ?? {}, t.cap.field)) || 0 : null, de = N(() => [...k.values()].reduce((e, s) => e + s.total, 0), [k]), Me = N(() => {
280
- var s, r, l;
281
- let e = K;
282
- for (const a of j) {
296
+ }, [y, Ge]), B = t.cap ? Number(ae(G[t.cap.scope_field] ?? {}, t.cap.field)) || 0 : null, fe = g(() => [...y.values()].reduce((e, l) => e + l.total, 0), [y]), Ae = g(() => {
297
+ var l, r, s;
298
+ let e = A;
299
+ for (const a of q) {
283
300
  const o = [
284
- ...S.map((n) => n.key),
285
- ...(s = t.specials) != null && s.uncategorized ? [W] : [],
286
- ...(r = t.specials) != null && r.bucket ? [J] : []
301
+ ...j.map((i) => i.key),
302
+ ...(l = t.specials) != null && l.uncategorized ? [J] : [],
303
+ ...(r = t.specials) != null && r.bucket ? [V] : []
287
304
  ];
288
- for (const n of o) {
289
- const u = `${a.id}|${n}`, i = L[u];
290
- i !== void 0 && i.trim() !== "" && !Number.isNaN(Number(i)) ? e += Number(i) : e += ((l = k.get(u)) == null ? void 0 : l.total) ?? 0;
305
+ for (const i of o) {
306
+ const u = `${a.id}|${i}`, n = K[u];
307
+ n !== void 0 && n.trim() !== "" && !Number.isNaN(Number(n)) ? e += Number(n) : e += ((s = y.get(u)) == null ? void 0 : s.total) ?? 0;
291
308
  }
292
309
  }
293
310
  return e;
294
- }, [L, k, j, S, K, t.specials]), ue = D !== null ? D - Me : null, H = (e) => {
311
+ }, [K, y, q, j, A, t.specials]), he = B !== null ? B - Ae : null, Z = (e) => {
295
312
  var r;
296
- const s = L[e];
297
- return s !== void 0 && s.trim() !== "" && !Number.isNaN(Number(s)) ? Number(s) : ((r = k.get(e)) == null ? void 0 : r.total) ?? 0;
313
+ const l = K[e];
314
+ return l !== void 0 && l.trim() !== "" && !Number.isNaN(Number(l)) ? Number(l) : ((r = y.get(e)) == null ? void 0 : r.total) ?? 0;
298
315
  };
299
- function et(e, s) {
316
+ function ut(e, l) {
300
317
  var o;
301
- const r = s.trim();
318
+ const r = l.trim();
302
319
  if (r === "") {
303
- V((n) => ({ ...n, [e]: s }));
320
+ D((i) => ({ ...i, [e]: l }));
304
321
  return;
305
322
  }
306
- const l = /^[+-]/.test(r) && r !== "-" && r !== "+";
323
+ const s = /^[+-]/.test(r) && r !== "-" && r !== "+";
307
324
  let a = Number(r);
308
325
  if (Number.isNaN(a)) {
309
- V((n) => ({ ...n, [e]: s }));
326
+ D((i) => ({ ...i, [e]: l }));
310
327
  return;
311
328
  }
312
- if (l && (a = (((o = k.get(e)) == null ? void 0 : o.total) ?? 0) + a), a < 0 && (a = 0), D !== null) {
313
- const n = Me - H(e), u = Math.max(0, D - n);
329
+ if (s && (a = (((o = y.get(e)) == null ? void 0 : o.total) ?? 0) + a), a < 0 && (a = 0), B !== null) {
330
+ const i = Ae - Z(e), u = Math.max(0, B - i);
314
331
  a = Math.min(a, u);
315
332
  }
316
- V((n) => ({ ...n, [e]: l ? String(a) : s }));
333
+ D((i) => ({ ...i, [e]: s ? String(a) : l }));
317
334
  }
318
- async function tt() {
335
+ async function mt() {
319
336
  var r;
320
- we(!0), ie(null);
321
- let e = 0, s = 0;
337
+ Ce(!0), me(null);
338
+ let e = 0, l = 0;
322
339
  try {
323
- const l = {};
340
+ const s = {};
324
341
  for (const [a, o] of Object.entries(t.scope_seeds ?? {})) {
325
- const n = /^\$(\w+)\.(.+)$/.exec(o);
326
- n && (l[a] = re(E[n[1]] ?? {}, n[2]));
342
+ const i = /^\$(\w+)\.(.+)$/.exec(o);
343
+ i && (s[a] = ae(G[i[1]] ?? {}, i[2]));
327
344
  }
328
- for (const [a, o] of Object.entries(L)) {
345
+ for (const [a, o] of Object.entries(K)) {
329
346
  if (o.trim() === "") continue;
330
- const n = Number(o);
331
- if (Number.isNaN(n) || n < 0) continue;
332
- const u = k.get(a);
333
- if (!(u && u.total === n))
347
+ const i = Number(o);
348
+ if (Number.isNaN(i) || i < 0) continue;
349
+ const u = y.get(a);
350
+ if (!(u && u.total === i))
334
351
  if (u)
335
- await h.request(
336
- at(`/items/${t.target_collection}/${u.ids[0]}`, {
337
- [t.value_field]: n
352
+ await f.request(
353
+ xt(`/items/${t.target_collection}/${u.ids[0]}`, {
354
+ [t.value_field]: i
338
355
  })
339
356
  ), e++;
340
357
  else {
341
- const [i, b] = a.split("|"), c = { [t.value_field]: n, ...l };
342
- for (const _ of t.scope_fields) c[_.field] = x[_.field];
343
- if (p && i) {
344
- c[p.field] = i;
345
- const _ = T.find((g) => String(g.id) === i);
346
- for (const [g, q] of Object.entries(t.group_seeds ?? {})) {
347
- const m = _ == null ? void 0 : _[q];
348
- m != null && (c[g] = m);
358
+ const [n, p] = a.split("|"), c = { [t.value_field]: i, ...s };
359
+ for (const k of t.scope_fields) c[k.field] = h[k.field];
360
+ if (m && n) {
361
+ c[m.field] = n;
362
+ const k = E.find((v) => String(v.id) === n);
363
+ for (const [v, C] of Object.entries(t.group_seeds ?? {})) {
364
+ const x = k == null ? void 0 : k[C];
365
+ x != null && (c[v] = x);
349
366
  }
350
367
  }
351
- b === J && ((r = t.specials) != null && r.bucket) ? (c[t.key_field] = null, c[t.specials.bucket.flag_field] = !0) : b === W ? c[t.key_field] = null : c[t.key_field] = b, await h.request(Be(`/items/${t.target_collection}`, c)), s++;
368
+ p === V && ((r = t.specials) != null && r.bucket) ? (c[t.key_field] = null, c[t.specials.bucket.flag_field] = !0) : p === J ? c[t.key_field] = null : c[t.key_field] = p, await f.request(st(`/items/${t.target_collection}`, c)), l++;
352
369
  }
353
370
  }
354
- V({}), await v.invalidateQueries({ queryKey: ["matrix-targets", t.target_collection] }), ie(`Saved — ${e} updated, ${s} created`);
355
- } catch (l) {
356
- ie(`Save failed: ${ot(l, "unknown error")}`);
371
+ D({}), await N.invalidateQueries({ queryKey: ["matrix-targets", t.target_collection] }), me(`Saved — ${e} updated, ${l} created`);
372
+ } catch (s) {
373
+ me(`Save failed: ${Nt(s, "unknown error")}`);
357
374
  } finally {
358
- we(!1);
375
+ Ce(!1);
359
376
  }
360
377
  }
361
- const Le = Object.values(L).some((e) => e.trim() !== ""), F = ((Ue = t.metrics) == null ? void 0 : Ue.columns) ?? [], A = ((We = t.metrics) == null ? void 0 : We.derived) ?? [], Re = t.value_label ?? t.value_field;
362
- 1 + F.length + A.length + 1;
363
- const G = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", U = (e, s, r) => {
364
- const a = r && typeof s == "number" && s < 0 ? r : e;
378
+ const Ue = Object.values(K).some((e) => e.trim() !== ""), R = ((Ie = t.metrics) == null ? void 0 : Ie.columns) ?? [], U = ((He = t.metrics) == null ? void 0 : He.derived) ?? [], Pe = t.value_label ?? t.value_field;
379
+ 1 + R.length + U.length + 1;
380
+ const P = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", W = (e, l, r) => {
381
+ const a = r && typeof l == "number" && l < 0 ? r : e;
365
382
  if (!a) return;
366
- const [o, n] = ct(a);
367
- return { "--qtc": o, "--qtcd": n };
368
- }, me = t.value_color ?? "info", Q = ((Je = t.metrics) == null ? void 0 : Je.unmatched) === !1 ? null : ((Ve = t.metrics) == null ? void 0 : Ve.unmatched) ?? {}, M = N(() => {
369
- var i, b;
370
- const e = /* @__PURE__ */ new Map(), s = {};
383
+ const [o, i] = St(a);
384
+ return { "--qtc": o, "--qtcd": i };
385
+ }, xe = t.value_color ?? "info", I = ((Xe = t.metrics) == null ? void 0 : Xe.unmatched) === !1 ? null : ((Ye = t.metrics) == null ? void 0 : Ye.unmatched) ?? {}, z = g(() => {
386
+ var n, p;
387
+ const e = /* @__PURE__ */ new Map(), l = {};
371
388
  let r = 0;
372
- const l = t.metrics;
373
- if (!l || !Q) return { perGroup: e, otherGroup: s, otherGroupCount: r };
374
- const a = new Set(j.map((c) => c.id)), o = new Set(S.map((c) => c.key)), n = /* @__PURE__ */ new Set(), u = (c) => c == null || c === 0 || c === "0" || c === "" ? "" : String(c);
375
- (i = t.specials) != null && i.uncategorized && n.add(u(t.specials.uncategorized.metric_value)), (b = t.specials) != null && b.bucket && n.add(u(t.specials.bucket.metric_value));
376
- for (const c of se) {
377
- const _ = l.match_group_field ? String(c[l.match_group_field] ?? "") : "", g = c[l.match_option_field], q = o.has(String(g ?? "")) || n.has(u(g)), m = !p || a.has(_) ? q ? null : e.get(_) ?? {} : s;
378
- if (m) {
379
- for (const C of l.columns)
380
- m[C.field] = (m[C.field] ?? 0) + (Number(c[C.field]) || 0);
381
- !p || a.has(_) ? e.set(_, m) : r++;
389
+ const s = t.metrics;
390
+ if (!s || !I) return { perGroup: e, otherGroup: l, otherGroupCount: r };
391
+ const a = new Set(q.map((c) => c.id)), o = new Set(j.map((c) => c.key)), i = /* @__PURE__ */ new Set(), u = (c) => c == null || c === 0 || c === "0" || c === "" ? "" : String(c);
392
+ (n = t.specials) != null && n.uncategorized && i.add(u(t.specials.uncategorized.metric_value)), (p = t.specials) != null && p.bucket && i.add(u(t.specials.bucket.metric_value));
393
+ for (const c of ne) {
394
+ const k = s.match_group_field ? String(c[s.match_group_field] ?? "") : "", v = c[s.match_option_field], C = o.has(String(v ?? "")) || i.has(u(v)), x = !m || a.has(k) ? C ? null : e.get(k) ?? {} : l;
395
+ if (x) {
396
+ for (const O of s.columns)
397
+ x[O.field] = (x[O.field] ?? 0) + (Number(c[O.field]) || 0);
398
+ !m || a.has(k) ? e.set(k, x) : r++;
382
399
  }
383
400
  }
384
- return { perGroup: e, otherGroup: s, otherGroupCount: r };
385
- }, [se, t.metrics, t.specials, j, S, p, Q]), ze = (e, s, r) => A.map(
386
- (l) => nt(
387
- l.formula,
388
- { ...r, __current__: e, __new__: s },
401
+ return { perGroup: e, otherGroup: l, otherGroupCount: r };
402
+ }, [ne, t.metrics, t.specials, q, j, m, I]), We = (e, l, r) => U.map(
403
+ (s) => _t(
404
+ s.formula,
405
+ { ...r, __current__: e, __new__: l },
389
406
  { missing: "zero" }
390
407
  )
391
- ), pe = (e) => {
392
- const s = {};
408
+ ), _e = (e) => {
409
+ const l = {};
393
410
  for (const r of e)
394
- for (const l of F) s[l.field] = (s[l.field] ?? 0) + (r[l.field] ?? 0);
395
- return s;
396
- }, Te = () => {
397
- var e, s;
411
+ for (const s of R) l[s.field] = (l[s.field] ?? 0) + (r[s.field] ?? 0);
412
+ return l;
413
+ }, Je = () => {
414
+ var e, l;
398
415
  return [
399
- ...S.map((r) => r.key),
400
- ...(e = t.specials) != null && e.uncategorized ? [W] : [],
401
- ...(s = t.specials) != null && s.bucket ? [J] : []
416
+ ...j.map((r) => r.key),
417
+ ...(e = t.specials) != null && e.uncategorized ? [J] : [],
418
+ ...(l = t.specials) != null && l.bucket ? [V] : []
402
419
  ];
403
- }, I = N(() => {
404
- var l;
405
- let e = 0, s = 0;
420
+ }, H = g(() => {
421
+ var s;
422
+ let e = 0, l = 0;
406
423
  const r = [];
407
- for (const a of j) {
408
- for (const n of Te()) {
409
- const u = `${a.id}|${n}`;
410
- e += ((l = k.get(u)) == null ? void 0 : l.total) ?? 0, s += H(u), r.push(le(a.id, n));
424
+ for (const a of q) {
425
+ for (const i of Je()) {
426
+ const u = `${a.id}|${i}`;
427
+ e += ((s = y.get(u)) == null ? void 0 : s.total) ?? 0, l += Z(u), r.push(oe(a.id, i));
411
428
  }
412
- const o = M.perGroup.get(a.id);
429
+ const o = z.perGroup.get(a.id);
413
430
  o && r.push(o);
414
431
  }
415
- return r.push(M.otherGroup), e += K, s += K, { current: e, next: s, metrics: pe(r) };
432
+ return r.push(z.otherGroup), e += A, l += A, { current: e, next: l, metrics: _e(r) };
416
433
  }, [
434
+ q,
417
435
  j,
418
- S,
419
- k,
420
- L,
421
- se,
436
+ y,
422
437
  K,
423
- M,
438
+ ne,
439
+ A,
440
+ z,
424
441
  t.specials
425
- ]), X = (e, s, r) => {
426
- const l = r != null && r.tone ? void 0 : U(r == null ? void 0 : r.role, e, r == null ? void 0 : r.negRole);
442
+ ]), ee = (e, l, r) => {
443
+ const s = r != null && r.tone ? void 0 : W(r == null ? void 0 : r.role, e, r == null ? void 0 : r.negRole);
427
444
  return /* @__PURE__ */ d(
428
445
  "td",
429
446
  {
430
- className: $(
447
+ className: S(
431
448
  "py-1.5 pr-3 text-right tabular-nums",
432
449
  r != null && r.strong ? "font-semibold" : "",
433
- l ? G : r != null && r.strong ? "text-slate-800 dark:text-slate-100" : "text-slate-600 dark:text-slate-300",
450
+ s ? P : r != null && r.strong ? "text-slate-800 dark:text-slate-100" : "text-slate-600 dark:text-slate-300",
434
451
  (r == null ? void 0 : r.tone) === "muted" && "text-slate-400 dark:text-slate-500",
435
452
  (r == null ? void 0 : r.tone) === "neg" && "text-red-600 dark:text-red-400"
436
453
  ),
437
- style: l,
438
- children: O(e, s)
454
+ style: s,
455
+ children: L(e, l)
439
456
  }
440
457
  );
441
- }, be = (e, s, r, l) => {
442
- const a = ze(e, s, r);
443
- return /* @__PURE__ */ f(ye, { children: [
444
- X(e, t.value_format, { strong: l, role: me }),
445
- F.map((o) => /* @__PURE__ */ d(
458
+ }, ye = (e, l, r, s) => {
459
+ const a = We(e, l, r);
460
+ return /* @__PURE__ */ b(we, { children: [
461
+ ee(e, t.value_format, { strong: s, role: xe }),
462
+ R.map((o) => /* @__PURE__ */ d(
446
463
  "td",
447
464
  {
448
- className: $(
465
+ className: S(
449
466
  "py-1.5 pr-3 text-right tabular-nums",
450
- l && "font-semibold",
451
- G
467
+ s && "font-semibold",
468
+ P
452
469
  ),
453
- style: U(o.color ?? "ink"),
454
- children: O(r[o.field], o.format)
470
+ style: W(o.color ?? "ink"),
471
+ children: L(r[o.field], o.format)
455
472
  },
456
473
  o.field
457
474
  )),
458
- A.map((o, n) => {
459
- const u = a[n];
475
+ U.map((o, i) => {
476
+ const u = a[i];
460
477
  return /* @__PURE__ */ d(
461
478
  "td",
462
479
  {
463
- className: $(
480
+ className: S(
464
481
  "py-1.5 pr-3 text-right tabular-nums",
465
- l && "font-semibold",
466
- G
482
+ s && "font-semibold",
483
+ P
467
484
  ),
468
- style: U(o.color ?? "positive", u, o.color_negative ?? "negative"),
469
- children: O(u, o.format ?? t.value_format)
485
+ style: W(o.color ?? "positive", u, o.color_negative ?? "negative"),
486
+ children: L(u, o.format ?? t.value_format)
470
487
  },
471
488
  o.label
472
489
  );
473
490
  }),
474
- X(s, t.value_format, {
475
- strong: l,
476
- tone: s !== e ? void 0 : "muted"
491
+ ee(l, t.value_format, {
492
+ strong: s,
493
+ tone: l !== e ? void 0 : "muted"
477
494
  })
478
495
  ] });
479
- }, ne = (e, s, r, l = !1, a = 0) => {
480
- var q;
481
- const o = `${e}|${s}`, n = ((q = k.get(o)) == null ? void 0 : q.total) ?? 0, u = le(e, s), i = L[o] ?? "", b = H(o), c = i.trim() !== "" && !Number.isNaN(Number(i)), _ = c ? b - n : 0, g = ze(n, b, u);
482
- return /* @__PURE__ */ f(
496
+ }, ce = (e, l, r, s = !1, a = 0) => {
497
+ var O, te;
498
+ const o = `${e}|${l}`, i = `${e}:${l}`, u = e ? (O = q.find((w) => w.id === e)) == null ? void 0 : O.label : null;
499
+ Re.current.set(i, u ? `${u} · ${r}` : r);
500
+ const n = ((te = y.get(o)) == null ? void 0 : te.total) ?? 0, p = oe(e, l), c = K[o] ?? "", k = Z(o), v = c.trim() !== "" && !Number.isNaN(Number(c)), C = v ? k - n : 0, x = We(n, k, p);
501
+ return /* @__PURE__ */ b(
483
502
  "tr",
484
503
  {
485
- className: $(
504
+ className: S(
486
505
  "border-b border-slate-100 dark:border-border/50",
487
- c && "bg-nvr-cyan/[0.04]"
506
+ v && "bg-nvr-cyan/[0.04]"
488
507
  ),
489
508
  children: [
490
509
  /* @__PURE__ */ d(
491
510
  "td",
492
511
  {
493
- className: $(
512
+ className: S(
494
513
  "py-1 pr-3 text-slate-700 dark:text-slate-200",
495
- l && "italic text-slate-500"
514
+ s && "italic text-slate-500"
496
515
  ),
497
516
  style: a ? { paddingLeft: a * 18 } : void 0,
498
517
  children: r
499
518
  }
500
519
  ),
501
- X(n, t.value_format, n === 0 ? { tone: "muted" } : { role: me }),
502
- F.map((m) => fe(m.field, u[m.field], m.format, m.color ?? "ink")),
503
- A.map((m, C) => {
504
- const Y = g[C];
520
+ ee(n, t.value_format, n === 0 ? { tone: "muted" } : { role: xe }),
521
+ R.map((w) => ke(w.field, p[w.field], w.format, w.color ?? "ink")),
522
+ U.map((w, bt) => {
523
+ const tt = x[bt];
505
524
  return /* @__PURE__ */ d(
506
525
  "td",
507
526
  {
508
- className: $("py-1.5 pr-3 text-right tabular-nums", G),
509
- style: U(m.color ?? "positive", Y, m.color_negative ?? "negative"),
510
- children: O(Y, m.format ?? t.value_format)
527
+ className: S("py-1.5 pr-3 text-right tabular-nums", P),
528
+ style: W(w.color ?? "positive", tt, w.color_negative ?? "negative"),
529
+ children: L(tt, w.format ?? t.value_format)
511
530
  },
512
- m.label
531
+ w.label
513
532
  );
514
533
  }),
515
- /* @__PURE__ */ d("td", { className: "py-1 pr-3 text-right", children: /* @__PURE__ */ f("span", { className: "inline-flex items-center justify-end gap-1.5", children: [
516
- c && _ !== 0 && /* @__PURE__ */ f(
534
+ /* @__PURE__ */ d("td", { className: "py-1 pr-3 text-right", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center justify-end gap-1.5", children: [
535
+ v && C !== 0 && /* @__PURE__ */ b(
517
536
  "span",
518
537
  {
519
- className: $(
538
+ className: S(
520
539
  "rounded-full px-1.5 py-px text-[10.5px] font-medium tabular-nums",
521
- G,
540
+ P,
522
541
  "bg-[color-mix(in_srgb,var(--qtc)_12%,transparent)] dark:bg-[color-mix(in_srgb,var(--qtcd)_14%,transparent)]"
523
542
  ),
524
- style: U(_ > 0 ? "positive" : "negative"),
543
+ style: W(C > 0 ? "positive" : "negative"),
525
544
  children: [
526
- _ > 0 ? "+" : "−",
527
- O(Math.abs(_), t.value_format)
545
+ C > 0 ? "+" : "−",
546
+ L(Math.abs(C), t.value_format)
528
547
  ]
529
548
  }
530
549
  ),
531
- /* @__PURE__ */ f("span", { className: "relative", children: [
532
- t.value_format === "currency" && /* @__PURE__ */ d("span", { className: "pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-[11px] text-slate-400", children: "$" }),
533
- /* @__PURE__ */ d(
534
- "input",
535
- {
536
- type: "text",
537
- inputMode: "decimal",
538
- value: i,
539
- placeholder: O(
540
- n,
541
- t.value_format === "currency" ? "number" : t.value_format
542
- ),
543
- onChange: (m) => et(o, m.target.value),
544
- title: "Type a new amount, or +500 / -250 to adjust the current one",
545
- className: $(
546
- "h-7 w-32 rounded-md border bg-white text-right text-[12px] tabular-nums outline-none transition-colors placeholder:text-slate-300 focus:border-nvr-cyan dark:bg-background dark:placeholder:text-slate-600",
547
- t.value_format === "currency" ? "pl-5 pr-2" : "px-2",
548
- c ? "border-nvr-cyan bg-nvr-cyan/[0.06]" : "border-slate-200 dark:border-border"
550
+ /* @__PURE__ */ b(
551
+ "span",
552
+ {
553
+ className: "relative rounded-md",
554
+ "data-grid-cell": Q ? vt(Q, i) : void 0,
555
+ children: [
556
+ t.value_format === "currency" && /* @__PURE__ */ d("span", { className: "pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-[11px] text-slate-400", children: "$" }),
557
+ /* @__PURE__ */ d(
558
+ "input",
559
+ {
560
+ type: "text",
561
+ inputMode: "decimal",
562
+ value: c,
563
+ placeholder: L(
564
+ n,
565
+ t.value_format === "currency" ? "number" : t.value_format
566
+ ),
567
+ onChange: (w) => ut(o, w.target.value),
568
+ title: "Type a new amount, or +500 / -250 to adjust the current one",
569
+ className: S(
570
+ "h-7 w-32 rounded-md border bg-white text-right text-[12px] tabular-nums outline-none transition-colors placeholder:text-slate-300 focus:border-nvr-cyan dark:bg-background dark:placeholder:text-slate-600",
571
+ t.value_format === "currency" ? "pl-5 pr-2" : "px-2",
572
+ v ? "border-nvr-cyan bg-nvr-cyan/[0.06]" : "border-slate-200 dark:border-border"
573
+ )
574
+ }
549
575
  )
550
- }
551
- )
552
- ] })
576
+ ]
577
+ }
578
+ )
553
579
  ] }) })
554
580
  ]
555
581
  },
556
582
  o
557
583
  );
558
- }, fe = (e, s, r, l) => /* @__PURE__ */ d(
584
+ }, ke = (e, l, r, s) => /* @__PURE__ */ d(
559
585
  "td",
560
586
  {
561
- className: $(
587
+ className: S(
562
588
  "py-1.5 pr-3 text-right tabular-nums",
563
- l ? G : "text-slate-600 dark:text-slate-300"
589
+ s ? P : "text-slate-600 dark:text-slate-300"
564
590
  ),
565
- style: U(l),
566
- children: O(s, r)
591
+ style: W(s),
592
+ children: L(l, r)
567
593
  },
568
594
  e
569
- ), rt = (e) => {
570
- const s = M.perGroup.get(e);
571
- return !s || !Q || !F.some((r) => (s[r.field] ?? 0) !== 0) ? null : /* @__PURE__ */ f("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
595
+ ), pt = (e) => {
596
+ const l = z.perGroup.get(e);
597
+ return !l || !I || !R.some((r) => (l[r.field] ?? 0) !== 0) ? null : /* @__PURE__ */ b("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
572
598
  /* @__PURE__ */ d(
573
599
  "td",
574
600
  {
575
601
  className: "py-1 pr-3 pl-[18px] italic text-slate-400",
576
602
  title: "Spend and commitments on categories outside this project’s list — nothing to allocate here, but they count toward the project total",
577
- children: Q.option_label ?? "Other categories"
603
+ children: I.option_label ?? "Other categories"
578
604
  }
579
605
  ),
580
- X(null, t.value_format, { tone: "muted" }),
581
- F.map((r) => fe(r.field, s[r.field], r.format)),
582
- A.map((r) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right tabular-nums text-slate-400", children: "—" }, r.label)),
606
+ ee(null, t.value_format, { tone: "muted" }),
607
+ R.map((r) => ke(r.field, l[r.field], r.format)),
608
+ U.map((r) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right tabular-nums text-slate-400", children: "—" }, r.label)),
583
609
  /* @__PURE__ */ d("td", {})
584
610
  ] }, `${e}|__other__`);
585
- }, Ee = (e) => e.label ?? e.field.replace(/_/g, " ").replace(/\b\w/g, (s) => s.toUpperCase()), Ke = new Set(w ? Object.keys(y ?? {}) : []), Ae = (e) => Se((s) => {
586
- const r = new Set(s);
611
+ }, Ve = (e) => e.label ?? e.field.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()), De = new Set($ ? Object.keys(_ ?? {}) : []), Qe = (e) => Le((l) => {
612
+ const r = new Set(l);
587
613
  return r.has(e) ? r.delete(e) : r.add(e), r;
588
614
  });
589
- return /* @__PURE__ */ f("div", { className: "flex h-full min-h-0 flex-col", "data-matrix-editor": !0, children: [
590
- /* @__PURE__ */ f("div", { className: "flex shrink-0 flex-wrap items-end gap-3 border-b border-slate-200 bg-white px-4 py-3 dark:border-border dark:bg-card", children: [
591
- t.scope_fields.filter((e) => !Ke.has(e.field)).map((e) => {
592
- const s = xe(e.filter, x), r = s && !ke(s) ? s : void 0;
593
- return /* @__PURE__ */ f("div", { className: "w-56", children: [
594
- /* @__PURE__ */ d("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: Ee(e) }),
615
+ return /* @__PURE__ */ b("div", { ref: Fe, className: "flex h-full min-h-0 flex-col", "data-matrix-editor": !0, children: [
616
+ /* @__PURE__ */ b("div", { className: "flex shrink-0 flex-wrap items-end gap-3 border-b border-slate-200 bg-white px-4 py-3 dark:border-border dark:bg-card", children: [
617
+ t.scope_fields.filter((e) => !De.has(e.field)).map((e) => {
618
+ const l = Ne(e.filter, h), r = l && !$e(l) ? l : void 0;
619
+ return /* @__PURE__ */ b("div", { className: "w-56", children: [
620
+ /* @__PURE__ */ d("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: Ve(e) }),
595
621
  /* @__PURE__ */ d(
596
- it,
622
+ wt,
597
623
  {
598
624
  collection: e.collection,
599
- value: x[e.field] ?? null,
600
- onChange: (l) => {
601
- oe((a) => ({ ...a, [e.field]: l })), V({});
625
+ value: h[e.field] ?? null,
626
+ onChange: (s) => {
627
+ ue((a) => ({ ...a, [e.field]: s })), D({});
602
628
  },
603
629
  extraFilter: r,
604
630
  placeholder: "Select…"
@@ -606,82 +632,91 @@ function vt({
606
632
  )
607
633
  ] }, e.field);
608
634
  }),
609
- /* @__PURE__ */ d("span", { className: "flex-1" }),
610
- ge && /* @__PURE__ */ d("span", { className: "pb-2 text-[12px] text-slate-500", children: ge }),
611
- Le && /* @__PURE__ */ d(
635
+ pe.length > 0 ? /* @__PURE__ */ d(
636
+ gt,
637
+ {
638
+ className: "min-w-[12rem] flex-1 pb-2",
639
+ editors: pe,
640
+ noun: ((Ze = t.presence_noun) == null ? void 0 : Ze.trim()) || t.target_collection.replace(/_/g, " ").toLowerCase(),
641
+ rowLabel: (e) => ot.get(e),
642
+ cellLabel: (e) => Re.current.get(e)
643
+ }
644
+ ) : /* @__PURE__ */ d("span", { className: "flex-1" }),
645
+ qe && /* @__PURE__ */ d("span", { className: "pb-2 text-[12px] text-slate-500", children: qe }),
646
+ Ue && /* @__PURE__ */ d(
612
647
  "button",
613
648
  {
614
649
  type: "button",
615
- onClick: () => V({}),
650
+ onClick: () => D({}),
616
651
  className: "h-9 rounded-md px-3 text-[13px] font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-muted",
617
652
  children: "Discard"
618
653
  }
619
654
  ),
620
- /* @__PURE__ */ f(
655
+ /* @__PURE__ */ b(
621
656
  "button",
622
657
  {
623
658
  type: "button",
624
- disabled: !R || !Le || Ne,
625
- onClick: () => void tt(),
659
+ disabled: !F || !Ue || je,
660
+ onClick: () => void mt(),
626
661
  "data-matrix-save": !0,
627
662
  className: "inline-flex h-9 items-center gap-1.5 rounded-md bg-nvr-cyan px-3.5 text-[13px] font-semibold text-[#172940] hover:bg-nvr-cyan-dark disabled:opacity-50",
628
663
  children: [
629
- Ne && /* @__PURE__ */ d(Qe, { className: "h-3.5 w-3.5 animate-spin" }),
664
+ je && /* @__PURE__ */ d(rt, { className: "h-3.5 w-3.5 animate-spin" }),
630
665
  "Save changes"
631
666
  ]
632
667
  }
633
668
  )
634
669
  ] }),
635
- D !== null && R && /* @__PURE__ */ d("div", { className: "grid shrink-0 grid-cols-2 gap-px border-b border-slate-200 bg-slate-200 dark:border-border dark:bg-border sm:grid-cols-4", children: [
670
+ B !== null && F && /* @__PURE__ */ d("div", { className: "grid shrink-0 grid-cols-2 gap-px border-b border-slate-200 bg-slate-200 dark:border-border dark:bg-border sm:grid-cols-4", children: [
636
671
  {
637
- label: ((De = t.cap) == null ? void 0 : De.label) ?? "Cap",
638
- value: D,
672
+ label: ((et = t.cap) == null ? void 0 : et.label) ?? "Cap",
673
+ value: B,
639
674
  tone: "plain",
640
675
  role: "accent"
641
676
  },
642
677
  {
643
678
  label: "Allocated",
644
- value: I.next,
645
- tone: I.next !== de ? "edited" : "plain",
646
- role: me,
647
- sub: I.next !== de ? `was ${O(de, "currency")}` : void 0
679
+ value: H.next,
680
+ tone: H.next !== fe ? "edited" : "plain",
681
+ role: xe,
682
+ sub: H.next !== fe ? `was ${L(fe, "currency")}` : void 0
648
683
  },
649
684
  {
650
685
  label: "Available to allocate",
651
- value: ue,
652
- tone: ue !== null && ue < 0 ? "neg" : "ok"
686
+ value: he,
687
+ tone: he !== null && he < 0 ? "neg" : "ok"
653
688
  },
654
689
  {
655
690
  label: "Misallocated",
656
- value: K,
657
- tone: K > 0 ? "neg" : "muted",
691
+ value: A,
692
+ tone: A > 0 ? "neg" : "muted",
658
693
  hint: "Allocations on categories or regions outside this project’s current lists"
659
694
  }
660
- ].map((e) => /* @__PURE__ */ f("div", { className: "bg-white px-4 py-2.5 dark:bg-card", title: e.hint, children: [
695
+ ].map((e) => /* @__PURE__ */ b("div", { className: "bg-white px-4 py-2.5 dark:bg-card", title: e.hint, children: [
661
696
  /* @__PURE__ */ d("p", { className: "text-[10px] font-semibold uppercase tracking-wide text-slate-400", children: e.label }),
662
697
  /* @__PURE__ */ d(
663
698
  "p",
664
699
  {
665
- className: $(
700
+ className: S(
666
701
  "mt-0.5 text-[17px] font-semibold tabular-nums tracking-[-0.01em]",
667
- e.tone === "muted" ? "text-slate-400" : G
702
+ e.tone === "muted" ? "text-slate-400" : P
668
703
  ),
669
- style: U(
704
+ style: W(
670
705
  e.tone === "neg" ? "negative" : e.tone === "ok" ? "positive" : e.tone === "edited" ? "accent" : e.role ?? "ink"
671
706
  ),
672
- children: O(e.value, "currency")
707
+ children: L(e.value, "currency")
673
708
  }
674
709
  ),
675
710
  e.sub && /* @__PURE__ */ d("p", { className: "text-[11px] text-slate-400", children: e.sub })
676
711
  ] }, e.label)) }),
677
- /* @__PURE__ */ d("div", { className: "min-h-0 flex-1 overflow-auto bg-slate-50/60 dark:bg-transparent", children: R ? Xe || ce ? /* @__PURE__ */ f("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
678
- /* @__PURE__ */ d(Qe, { className: "h-4 w-4 animate-spin" }),
712
+ /* @__PURE__ */ d("div", { className: "min-h-0 flex-1 overflow-auto bg-slate-50/60 dark:bg-transparent", children: F ? it || be ? /* @__PURE__ */ b("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
713
+ /* @__PURE__ */ d(rt, { className: "h-4 w-4 animate-spin" }),
679
714
  " Loading…"
680
- ] }) : /* @__PURE__ */ f("table", { className: "w-full text-[12px]", children: [
681
- /* @__PURE__ */ d("thead", { className: "sticky top-0 z-[1] bg-slate-50 dark:bg-background", children: /* @__PURE__ */ f("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
715
+ ] }) : /* @__PURE__ */ b("table", { className: "w-full text-[12px]", children: [
716
+ /* @__PURE__ */ d("thead", { className: "sticky top-0 z-[1] bg-slate-50 dark:bg-background", children: /* @__PURE__ */ b("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
682
717
  /* @__PURE__ */ d("th", { className: "px-3 py-2 text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: t.option_collection.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) }),
683
- /* @__PURE__ */ d("th", { className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: Re }),
684
- F.map((e) => /* @__PURE__ */ d(
718
+ /* @__PURE__ */ d("th", { className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: Pe }),
719
+ R.map((e) => /* @__PURE__ */ d(
685
720
  "th",
686
721
  {
687
722
  className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
@@ -689,7 +724,7 @@ function vt({
689
724
  },
690
725
  e.field
691
726
  )),
692
- A.map((e) => /* @__PURE__ */ d(
727
+ U.map((e) => /* @__PURE__ */ d(
693
728
  "th",
694
729
  {
695
730
  className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
@@ -697,160 +732,160 @@ function vt({
697
732
  },
698
733
  e.label
699
734
  )),
700
- /* @__PURE__ */ f("th", { className: "w-44 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: [
735
+ /* @__PURE__ */ b("th", { className: "w-44 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: [
701
736
  "New ",
702
- Re
737
+ Pe
703
738
  ] })
704
739
  ] }) }),
705
- /* @__PURE__ */ f("tbody", { className: "bg-white dark:bg-transparent", children: [
706
- j.map((e) => {
707
- var n, u;
708
- const s = $e.has(e.id), r = [...k.entries()].filter(([i]) => i.startsWith(`${e.id}|`)).reduce((i, [, b]) => i + b.total, 0), l = Te(), a = pe([
709
- ...l.map((i) => le(e.id, i)),
710
- ...M.perGroup.get(e.id) ? [M.perGroup.get(e.id)] : []
711
- ]), o = l.reduce((i, b) => i + H(`${e.id}|${b}`), 0) + (r - l.reduce((i, b) => {
740
+ /* @__PURE__ */ b("tbody", { className: "bg-white dark:bg-transparent", children: [
741
+ q.map((e) => {
742
+ var i, u;
743
+ const l = Oe.has(e.id), r = [...y.entries()].filter(([n]) => n.startsWith(`${e.id}|`)).reduce((n, [, p]) => n + p.total, 0), s = Je(), a = _e([
744
+ ...s.map((n) => oe(e.id, n)),
745
+ ...z.perGroup.get(e.id) ? [z.perGroup.get(e.id)] : []
746
+ ]), o = s.reduce((n, p) => n + Z(`${e.id}|${p}`), 0) + (r - s.reduce((n, p) => {
712
747
  var c;
713
- return i + (((c = k.get(`${e.id}|${b}`)) == null ? void 0 : c.total) ?? 0);
748
+ return n + (((c = y.get(`${e.id}|${p}`)) == null ? void 0 : c.total) ?? 0);
714
749
  }, 0));
715
750
  return /* @__PURE__ */ d(
716
- He,
751
+ at,
717
752
  {
718
- header: p ? /* @__PURE__ */ f(
753
+ header: m ? /* @__PURE__ */ b(
719
754
  "tr",
720
755
  {
721
756
  className: "cursor-pointer border-y border-slate-200 bg-slate-100/70 hover:bg-slate-100 dark:border-border dark:bg-muted/60",
722
- onClick: () => Ae(e.id),
757
+ onClick: () => Qe(e.id),
723
758
  "data-matrix-group": e.id,
724
759
  children: [
725
- /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: /* @__PURE__ */ f("span", { className: "inline-flex items-center gap-1.5", children: [
760
+ /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center gap-1.5", children: [
726
761
  /* @__PURE__ */ d(
727
- Ie,
762
+ lt,
728
763
  {
729
- className: $(
764
+ className: S(
730
765
  "h-3.5 w-3.5 text-slate-400 transition-transform",
731
- !s && "rotate-90"
766
+ !l && "rotate-90"
732
767
  )
733
768
  }
734
769
  ),
735
770
  e.label
736
771
  ] }) }),
737
- be(r, o, a, !0)
772
+ ye(r, o, a, !0)
738
773
  ]
739
774
  }
740
775
  ) : null,
741
- children: !s && /* @__PURE__ */ f(ye, { children: [
742
- t.option_section ? ae.map((i) => {
743
- const b = `s:${e.id}|${i.name}`, c = $e.has(b), _ = i.rows.reduce(
744
- (m, C) => {
745
- var Y;
746
- return m + (((Y = k.get(`${e.id}|${C.key}`)) == null ? void 0 : Y.total) ?? 0);
776
+ children: !l && /* @__PURE__ */ b(we, { children: [
777
+ t.option_section ? ie.map((n) => {
778
+ const p = `s:${e.id}|${n.name}`, c = Oe.has(p), k = n.rows.reduce(
779
+ (x, O) => {
780
+ var te;
781
+ return x + (((te = y.get(`${e.id}|${O.key}`)) == null ? void 0 : te.total) ?? 0);
747
782
  },
748
783
  0
749
- ), g = i.rows.reduce(
750
- (m, C) => m + H(`${e.id}|${C.key}`),
784
+ ), v = n.rows.reduce(
785
+ (x, O) => x + Z(`${e.id}|${O.key}`),
751
786
  0
752
- ), q = pe(
753
- i.rows.map((m) => le(e.id, m.key))
787
+ ), C = _e(
788
+ n.rows.map((x) => oe(e.id, x.key))
754
789
  );
755
790
  return /* @__PURE__ */ d(
756
- He,
791
+ at,
757
792
  {
758
- header: /* @__PURE__ */ f(
793
+ header: /* @__PURE__ */ b(
759
794
  "tr",
760
795
  {
761
796
  className: "cursor-pointer border-b border-slate-100 bg-slate-50/80 hover:bg-slate-50 dark:border-border/50 dark:bg-muted/30",
762
- onClick: () => Ae(b),
797
+ onClick: () => Qe(p),
763
798
  children: [
764
- /* @__PURE__ */ d("td", { className: "py-1 pr-3 pl-[22px] text-[11.5px] font-medium text-slate-600 dark:text-slate-300", children: /* @__PURE__ */ f("span", { className: "inline-flex items-center gap-1.5", children: [
799
+ /* @__PURE__ */ d("td", { className: "py-1 pr-3 pl-[22px] text-[11.5px] font-medium text-slate-600 dark:text-slate-300", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center gap-1.5", children: [
765
800
  /* @__PURE__ */ d(
766
- Ie,
801
+ lt,
767
802
  {
768
- className: $(
803
+ className: S(
769
804
  "h-3 w-3 text-slate-400 transition-transform",
770
805
  !c && "rotate-90"
771
806
  )
772
807
  }
773
808
  ),
774
- i.name || "—"
809
+ n.name || "—"
775
810
  ] }) }),
776
- be(_, g, q, !1)
811
+ ye(k, v, C, !1)
777
812
  ]
778
813
  }
779
814
  ),
780
- children: !c && i.rows.map(
781
- (m) => ne(e.id, m.key, m.label, !1, 2.4)
815
+ children: !c && n.rows.map(
816
+ (x) => ce(e.id, x.key, x.label, !1, 2.4)
782
817
  )
783
818
  },
784
- b
819
+ p
785
820
  );
786
- }) : S.map((i) => ne(e.id, i.key, i.label, !1, 1)),
787
- ((n = t.specials) == null ? void 0 : n.uncategorized) && ne(
821
+ }) : j.map((n) => ce(e.id, n.key, n.label, !1, 1)),
822
+ ((i = t.specials) == null ? void 0 : i.uncategorized) && ce(
788
823
  e.id,
789
- W,
824
+ J,
790
825
  t.specials.uncategorized.label ?? "Uncategorized",
791
826
  !0,
792
827
  1
793
828
  ),
794
- ((u = t.specials) == null ? void 0 : u.bucket) && ne(
829
+ ((u = t.specials) == null ? void 0 : u.bucket) && ce(
795
830
  e.id,
796
- J,
831
+ V,
797
832
  t.specials.bucket.label ?? "Inventory",
798
833
  !0,
799
834
  1
800
835
  ),
801
- rt(e.id)
836
+ pt(e.id)
802
837
  ] })
803
838
  },
804
839
  e.id || "__all__"
805
840
  );
806
841
  }),
807
- Q && p && M.otherGroupCount > 0 && /* @__PURE__ */ f(
842
+ I && m && z.otherGroupCount > 0 && /* @__PURE__ */ b(
808
843
  "tr",
809
844
  {
810
845
  className: "border-y border-slate-200 bg-slate-100/70 dark:border-border dark:bg-muted/60",
811
846
  title: "Spend and commitments on regions outside this project’s list",
812
847
  children: [
813
- /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold italic text-slate-500", children: Q.group_label ?? "Other regions" }),
814
- X(null, t.value_format, { tone: "muted" }),
815
- F.map(
816
- (e) => fe(e.field, M.otherGroup[e.field], e.format)
848
+ /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold italic text-slate-500", children: I.group_label ?? "Other regions" }),
849
+ ee(null, t.value_format, { tone: "muted" }),
850
+ R.map(
851
+ (e) => ke(e.field, z.otherGroup[e.field], e.format)
817
852
  ),
818
- A.map((e) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right text-slate-400", children: "—" }, e.label)),
853
+ U.map((e) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right text-slate-400", children: "—" }, e.label)),
819
854
  /* @__PURE__ */ d("td", {})
820
855
  ]
821
856
  }
822
857
  )
823
858
  ] }),
824
- /* @__PURE__ */ d("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ f("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
859
+ /* @__PURE__ */ d("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ b("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
825
860
  /* @__PURE__ */ d("td", { className: "px-3 py-2 text-[12px] font-semibold text-slate-800 dark:text-slate-100", children: "Total" }),
826
- be(I.current, I.next, I.metrics, !0)
861
+ ye(H.current, H.next, H.metrics, !0)
827
862
  ] }) })
828
- ] }) : /* @__PURE__ */ f("div", { className: "flex h-full flex-col items-center justify-center gap-1 p-8 text-center", children: [
829
- /* @__PURE__ */ f("p", { className: "text-[13px] font-medium text-slate-600 dark:text-slate-300", children: [
863
+ ] }) : /* @__PURE__ */ b("div", { className: "flex h-full flex-col items-center justify-center gap-1 p-8 text-center", children: [
864
+ /* @__PURE__ */ b("p", { className: "text-[13px] font-medium text-slate-600 dark:text-slate-300", children: [
830
865
  "Choose",
831
866
  " ",
832
- t.scope_fields.filter((e) => !Ke.has(e.field)).map(Ee).join(" and "),
867
+ t.scope_fields.filter((e) => !De.has(e.field)).map(Ve).join(" and "),
833
868
  " ",
834
869
  "to load allocations"
835
870
  ] }),
836
- /* @__PURE__ */ f("p", { className: "text-[12px] text-slate-400", children: [
871
+ /* @__PURE__ */ b("p", { className: "text-[12px] text-slate-400", children: [
837
872
  "Amounts are grouped by",
838
873
  " ",
839
- p != null && p.label_field ? p.collection.replace(/_/g, " ") : "section",
874
+ m != null && m.label_field ? m.collection.replace(/_/g, " ") : "section",
840
875
  " and saved together."
841
876
  ] })
842
877
  ] }) })
843
878
  ] });
844
879
  }
845
- function He({
880
+ function at({
846
881
  header: t,
847
- children: y
882
+ children: _
848
883
  }) {
849
- return /* @__PURE__ */ f(ye, { children: [
884
+ return /* @__PURE__ */ b(we, { children: [
850
885
  t,
851
- y
886
+ _
852
887
  ] });
853
888
  }
854
889
  export {
855
- vt as MatrixEditor
890
+ Ut as MatrixEditor
856
891
  };