@nivaro/react 0.3.114 → 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 (281) 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 +1717 -21
  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 +1 -0
  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/change-proposals/ChangeProposalsPanel.js +320 -0
  62. package/dist/shared/components/change-proposals/ProposalValue.js +28 -0
  63. package/dist/shared/components/change-proposals/ProposeChangeButton.js +44 -0
  64. package/dist/shared/components/change-proposals/ProposeChangeDialog.js +359 -0
  65. package/dist/shared/components/change-proposals/types.js +4 -0
  66. package/dist/shared/components/chat/ChatPanel.js +1571 -1528
  67. package/dist/shared/components/chat/Composer.js +276 -298
  68. package/dist/shared/components/chat/room-due.js +13 -0
  69. package/dist/shared/components/collections-directory/CollectionRow.js +76 -75
  70. package/dist/shared/components/collections-directory/CollectionsDirectory.js +415 -395
  71. package/dist/shared/components/collections-directory/directory-data.js +75 -63
  72. package/dist/shared/components/imports/ImportConsole.js +159 -155
  73. package/dist/shared/components/imports/ImportDuplicatesNotice.js +46 -31
  74. package/dist/shared/components/integrations/SendStatus.js +202 -0
  75. package/dist/shared/components/integrations/console/IntegrationsConsole.js +45 -36
  76. package/dist/shared/components/integrations/console/ReadyToSendView.js +453 -0
  77. package/dist/shared/components/integrations/console/api.js +161 -117
  78. package/dist/shared/components/integrations/console/tone.js +15 -12
  79. package/dist/shared/components/item-edit/CatalogPickerField.js +1353 -1245
  80. package/dist/shared/components/item-edit/ChangedAfterApprovalBadge.js +162 -0
  81. package/dist/shared/components/item-edit/CloneDialog.js +208 -206
  82. package/dist/shared/components/item-edit/DerivedCauseNote.js +57 -0
  83. package/dist/shared/components/item-edit/DraftRecoveryBanner.js +81 -70
  84. package/dist/shared/components/item-edit/DuplicateNotice.js +169 -101
  85. package/dist/shared/components/item-edit/FieldAffordances.js +294 -385
  86. package/dist/shared/components/item-edit/FieldComments.js +159 -116
  87. package/dist/shared/components/item-edit/FieldPointer.js +132 -0
  88. package/dist/shared/components/item-edit/FieldRenderer.js +277 -273
  89. package/dist/shared/components/item-edit/FieldRow.js +519 -439
  90. package/dist/shared/components/item-edit/FieldSourceBadge.js +88 -0
  91. package/dist/shared/components/item-edit/FilePickerField.js +454 -369
  92. package/dist/shared/components/item-edit/GroupSection.js +618 -567
  93. package/dist/shared/components/item-edit/HeldEditsChip.js +113 -0
  94. package/dist/shared/components/item-edit/InlineTableField.js +2891 -2723
  95. package/dist/shared/components/item-edit/ListNeighborNav.js +79 -0
  96. package/dist/shared/components/item-edit/LiveTraceSheet.js +26 -0
  97. package/dist/shared/components/item-edit/M2MCombobox.js +284 -273
  98. package/dist/shared/components/item-edit/OutboxReviewTray.js +313 -0
  99. package/dist/shared/components/item-edit/PickerBadges.js +52 -0
  100. package/dist/shared/components/item-edit/PlanGrid.js +434 -439
  101. package/dist/shared/components/item-edit/RecalcValue.js +55 -0
  102. package/dist/shared/components/item-edit/RecordChatActions.js +76 -64
  103. package/dist/shared/components/item-edit/RecordChatMentionsChip.js +103 -0
  104. package/dist/shared/components/item-edit/RecordGrantTools.js +87 -86
  105. package/dist/shared/components/item-edit/RecordHelpChip.js +70 -0
  106. package/dist/shared/components/item-edit/RecordLiveSync.js +230 -217
  107. package/dist/shared/components/item-edit/RecordOutbox.js +53 -52
  108. package/dist/shared/components/item-edit/RecordRecapStrip.js +109 -36
  109. package/dist/shared/components/item-edit/RelationCombobox.js +229 -217
  110. package/dist/shared/components/item-edit/RelationGroupedCombobox.js +105 -100
  111. package/dist/shared/components/item-edit/RemoteChangeUi.js +454 -0
  112. package/dist/shared/components/item-edit/RemoteUploads.js +55 -0
  113. package/dist/shared/components/item-edit/RemovedLineNote.js +92 -0
  114. package/dist/shared/components/item-edit/RichTextEditorImpl.js +298 -223
  115. package/dist/shared/components/item-edit/ScheduledChangeChip.js +244 -0
  116. package/dist/shared/components/item-edit/SectionPresence.js +78 -0
  117. package/dist/shared/components/item-edit/SplitLinesButton.js +166 -0
  118. package/dist/shared/components/item-edit/catalog-line-watch.js +94 -0
  119. package/dist/shared/components/item-edit/coedit/collab.js +84 -0
  120. package/dist/shared/components/item-edit/coedit/context.js +24 -0
  121. package/dist/shared/components/item-edit/coedit/cursors.js +103 -0
  122. package/dist/shared/components/item-edit/coedit/safe-link.js +15 -0
  123. package/dist/shared/components/item-edit/coedit/session.js +382 -0
  124. package/dist/shared/components/item-edit/coedit/useCoedit.js +49 -0
  125. package/dist/shared/components/item-edit/file-live.js +77 -0
  126. package/dist/shared/components/item-edit/file-processing.js +87 -0
  127. package/dist/shared/components/item-edit/layout-switch.js +148 -0
  128. package/dist/shared/components/item-edit/live-related.js +23 -0
  129. package/dist/shared/components/item-edit/live-title.js +66 -0
  130. package/dist/shared/components/item-edit/partner-needs.js +142 -0
  131. package/dist/shared/components/item-edit/removed-line.js +58 -0
  132. package/dist/shared/components/item-edit/render-stability.js +70 -59
  133. package/dist/shared/components/layout-editor/ChangeNote.js +36 -34
  134. package/dist/shared/components/layout-editor/CollabParts.js +72 -70
  135. package/dist/shared/components/layout-editor/LayoutEditor.js +306 -303
  136. package/dist/shared/components/list/InlineEdit.js +504 -208
  137. package/dist/shared/components/list/ListViewers.js +81 -0
  138. package/dist/shared/components/merge/MergeRecordsDialog.js +1227 -0
  139. package/dist/shared/components/merge/MergeWithFlow.js +290 -0
  140. package/dist/shared/components/merge/merge-values.js +110 -0
  141. package/dist/shared/components/monitoring/InactiveUserLinksView.js +285 -258
  142. package/dist/shared/components/notifications/NotificationCenterView.js +388 -321
  143. package/dist/shared/components/notifications/NotificationDetailBits.js +205 -130
  144. package/dist/shared/components/notifications/NotificationRulesEditor.js +72 -52
  145. package/dist/shared/components/notifications/bundles.js +21 -19
  146. package/dist/shared/components/notifications/resolved-line.js +25 -0
  147. package/dist/shared/components/ops/OpsTasksView.js +45 -44
  148. package/dist/shared/components/panels/AccessGrantedNote.js +85 -0
  149. package/dist/shared/components/panels/AlertBanners.js +132 -0
  150. package/dist/shared/components/panels/AsyncUserPicker.js +54 -45
  151. package/dist/shared/components/panels/BranchLanes.js +82 -54
  152. package/dist/shared/components/panels/CommentAwareness.js +332 -0
  153. package/dist/shared/components/panels/CommentImages.js +219 -0
  154. package/dist/shared/components/panels/CommentPanel.js +649 -530
  155. package/dist/shared/components/panels/ExternalRequestsChip.js +98 -80
  156. package/dist/shared/components/panels/NewSinceChip.js +16 -0
  157. package/dist/shared/components/panels/OwnerOpenedLine.js +85 -0
  158. package/dist/shared/components/panels/PipelinePanel.js +1644 -1494
  159. package/dist/shared/components/panels/ResubmissionDiff.js +293 -0
  160. package/dist/shared/components/panels/SlaBreachBanner.js +30 -29
  161. package/dist/shared/components/panels/SlaClock.js +130 -99
  162. package/dist/shared/components/panels/TaskPanel.js +308 -287
  163. package/dist/shared/components/panels/unseen-move-check.js +101 -0
  164. package/dist/shared/components/pipeline/OwnerMatrix.js +80 -71
  165. package/dist/shared/components/pipeline/OwnerMatrixSheet.js +495 -0
  166. package/dist/shared/components/pipeline/PipelineEditorView.js +1855 -1771
  167. package/dist/shared/components/profile/AgentNameField.js +141 -0
  168. package/dist/shared/components/profile/AgentsPanel.js +55 -46
  169. package/dist/shared/components/profile/PersonAccess.js +398 -330
  170. package/dist/shared/components/profile/PersonAdminTools.js +127 -113
  171. package/dist/shared/components/profile/PersonProfile.js +81 -73
  172. package/dist/shared/components/profile/SignInTroubleshooter.js +361 -0
  173. package/dist/shared/components/queue/QueueBulkBar.js +101 -84
  174. package/dist/shared/components/queue/QueueItemSheet.js +66 -66
  175. package/dist/shared/components/queue/QueueTeamStrip.js +279 -0
  176. package/dist/shared/components/queue/QueueWorklist.js +1927 -1635
  177. package/dist/shared/components/send-view/SendViewButton.js +136 -0
  178. package/dist/shared/components/send-view/SentViewCards.js +147 -0
  179. package/dist/shared/components/support/ReportProblem.js +1 -0
  180. package/dist/shared/components/support/ScreenShare.js +554 -0
  181. package/dist/shared/components/support/SupportView.js +160 -129
  182. package/dist/shared/components/support/TicketDetailSheet.js +101 -89
  183. package/dist/shared/components/watch-list/WatchDock.js +1044 -0
  184. package/dist/shared/components/watch-list/WatchExtras.js +723 -0
  185. package/dist/shared/components/watch-list/WatchListButton.js +46 -0
  186. package/dist/shared/components/watch-list/WatchPinButton.js +67 -0
  187. package/dist/shared/components/watch-list/WatchRows.js +348 -0
  188. package/dist/shared/lib/activity-sentence.js +87 -75
  189. package/dist/shared/lib/agent-presence.js +46 -0
  190. package/dist/shared/lib/approval-progress.js +49 -0
  191. package/dist/shared/lib/attention-prefs.js +27 -0
  192. package/dist/shared/lib/cell-locks.js +56 -0
  193. package/dist/shared/lib/co-edit.js +166 -0
  194. package/dist/shared/lib/coedit-registry.js +44 -0
  195. package/dist/shared/lib/comment-awareness.js +124 -0
  196. package/dist/shared/lib/comment-images.js +45 -0
  197. package/dist/shared/lib/config-watch.js +94 -0
  198. package/dist/shared/lib/copy-rules.js +65 -0
  199. package/dist/shared/lib/count-step.js +30 -0
  200. package/dist/shared/lib/deadline-ticker.js +68 -0
  201. package/dist/shared/lib/derived-causes.js +115 -0
  202. package/dist/shared/lib/draft-store.js +114 -85
  203. package/dist/shared/lib/error-hints.js +1 -0
  204. package/dist/shared/lib/field-merge.js +126 -0
  205. package/dist/shared/lib/filter-sentence.js +10 -10
  206. package/dist/shared/lib/focus-mode.js +16 -12
  207. package/dist/shared/lib/grid-cursors.js +77 -0
  208. package/dist/shared/lib/grid-presence.js +182 -0
  209. package/dist/shared/lib/idle-reload.js +100 -73
  210. package/dist/shared/lib/in-step.js +45 -0
  211. package/dist/shared/lib/integration-chip.js +19 -18
  212. package/dist/shared/lib/line-locks.js +141 -0
  213. package/dist/shared/lib/line-split.js +41 -0
  214. package/dist/shared/lib/linked-changes.js +150 -0
  215. package/dist/shared/lib/list-return.js +231 -0
  216. package/dist/shared/lib/list-viewers.js +52 -0
  217. package/dist/shared/lib/live-announcer.js +86 -0
  218. package/dist/shared/lib/live-counts.js +85 -0
  219. package/dist/shared/lib/live-data-changed.js +108 -0
  220. package/dist/shared/lib/live-deltas.js +81 -0
  221. package/dist/shared/lib/live-findings.js +113 -0
  222. package/dist/shared/lib/live-groups.js +122 -0
  223. package/dist/shared/lib/live-link-labels.js +162 -0
  224. package/dist/shared/lib/live-list-flow.js +334 -0
  225. package/dist/shared/lib/live-list.js +143 -129
  226. package/dist/shared/lib/live-moves.js +51 -0
  227. package/dist/shared/lib/live-ops.js +26 -26
  228. package/dist/shared/lib/live-pickers.js +7 -0
  229. package/dist/shared/lib/live-preference.js +184 -0
  230. package/dist/shared/lib/live-queries.js +226 -181
  231. package/dist/shared/lib/live-screen.js +333 -0
  232. package/dist/shared/lib/live-search.js +108 -0
  233. package/dist/shared/lib/live-seen.js +35 -0
  234. package/dist/shared/lib/live-views.js +100 -0
  235. package/dist/shared/lib/live.js +159 -133
  236. package/dist/shared/lib/missed-updates.js +198 -0
  237. package/dist/shared/lib/newer-file.js +56 -0
  238. package/dist/shared/lib/notification-sound.js +42 -20
  239. package/dist/shared/lib/own-writes.js +59 -41
  240. package/dist/shared/lib/picker-badges.js +94 -0
  241. package/dist/shared/lib/presence-signals.js +131 -84
  242. package/dist/shared/lib/realtime.js +49 -24
  243. package/dist/shared/lib/record-gaps.js +85 -0
  244. package/dist/shared/lib/record-outbox.js +369 -222
  245. package/dist/shared/lib/record-peek.js +75 -0
  246. package/dist/shared/lib/record-tabs.js +92 -72
  247. package/dist/shared/lib/relative-ticker.js +42 -0
  248. package/dist/shared/lib/request-gate.js +119 -119
  249. package/dist/shared/lib/rollup-recalc.js +107 -0
  250. package/dist/shared/lib/room-gaps.js +40 -36
  251. package/dist/shared/lib/rum.js +137 -87
  252. package/dist/shared/lib/save-progress.js +20 -0
  253. package/dist/shared/lib/scheduled-countdown.js +67 -0
  254. package/dist/shared/lib/screen-refresh.js +160 -0
  255. package/dist/shared/lib/screen-share.js +234 -0
  256. package/dist/shared/lib/seen-since.js +74 -0
  257. package/dist/shared/lib/selection-watch.js +205 -0
  258. package/dist/shared/lib/send-status.js +132 -0
  259. package/dist/shared/lib/send-view.js +23 -0
  260. package/dist/shared/lib/socket-liveness.js +155 -0
  261. package/dist/shared/lib/socket-realtime.js +168 -140
  262. package/dist/shared/lib/state-census.js +53 -0
  263. package/dist/shared/lib/summary-mode.js +61 -39
  264. package/dist/shared/lib/tab-attention.js +143 -32
  265. package/dist/shared/lib/table-density.js +64 -0
  266. package/dist/shared/lib/track-travel.js +40 -0
  267. package/dist/shared/lib/unseen-changes.js +68 -0
  268. package/dist/shared/lib/upload-file.js +33 -0
  269. package/dist/shared/lib/upload-presence.js +127 -0
  270. package/dist/shared/lib/urgent-chime.js +65 -0
  271. package/dist/shared/lib/use-online-users.js +32 -11
  272. package/dist/shared/lib/user-sync.js +155 -39
  273. package/dist/shared/lib/waiting-count.js +44 -0
  274. package/dist/shared/lib/watch-desktop.js +83 -0
  275. package/dist/shared/lib/watch-list.js +447 -0
  276. package/dist/shared/lib/widget-image-render.js +64 -0
  277. package/dist/shared/lib/widget-image.js +111 -0
  278. package/dist/shared/lib/worker-socket.js +130 -104
  279. package/dist/shared/lib/write-to-screen.js +133 -0
  280. package/package.json +1 -1
  281. package/styles.css +49 -1
@@ -1,156 +1,156 @@
1
- import { clearChatOutbox as z } from "../components/chat/chat-outbox.js";
2
- import { get as C, patch as G } from "./commands.js";
3
- import { userErrorMessage as H } from "./safe-error.js";
4
- const Z = "nivaro-record-outbox", k = "entries", Q = 1, tt = 10080 * 60 * 1e3, P = 8e3;
5
- function et(t) {
1
+ import { clearChatOutbox as rt } from "../components/chat/chat-outbox.js";
2
+ import { get as v, patch as z } from "./commands.js";
3
+ import { userErrorMessage as st } from "./safe-error.js";
4
+ const at = "nivaro-record-outbox", I = "entries", lt = 1, ct = 10080 * 60 * 1e3, G = 8e3;
5
+ function ut(t) {
6
6
  return t ? `${typeof location < "u" ? location.host : ""}|${t}` : null;
7
7
  }
8
- function nt(t) {
8
+ function ft(t) {
9
9
  return t.slice(t.lastIndexOf("|") + 1);
10
10
  }
11
- function p(t, e, n) {
11
+ function _(t, e, n) {
12
12
  return `${t}|${e}|${String(n)}`;
13
13
  }
14
- let ot = !1;
15
- const O = /* @__PURE__ */ new Map();
16
- function rt() {
14
+ let dt = !1;
15
+ const C = /* @__PURE__ */ new Map();
16
+ function yt() {
17
17
  return new Promise((t) => {
18
18
  try {
19
- if (ot || typeof indexedDB > "u") return t(null);
20
- const e = indexedDB.open(Z, Q);
19
+ if (dt || typeof indexedDB > "u") return t(null);
20
+ const e = indexedDB.open(at, lt);
21
21
  e.onupgradeneeded = () => {
22
22
  const n = e.result;
23
- n.objectStoreNames.contains(k) || n.createObjectStore(k, { keyPath: "id" });
23
+ n.objectStoreNames.contains(I) || n.createObjectStore(I, { keyPath: "id" });
24
24
  }, e.onsuccess = () => t(e.result), e.onerror = () => t(null), e.onblocked = () => t(null);
25
25
  } catch {
26
26
  t(null);
27
27
  }
28
28
  });
29
29
  }
30
- async function g(t, e) {
31
- const n = await rt();
32
- return n ? new Promise((r) => {
30
+ async function j(t, e) {
31
+ const n = await yt();
32
+ return n ? new Promise((o) => {
33
33
  try {
34
- const o = n.transaction(k, t), i = e(o.objectStore(k));
35
- i.onsuccess = () => r({ ok: !0, value: i.result }), i.onerror = () => r({ ok: !1, value: null }), o.oncomplete = () => n.close(), o.onerror = () => {
36
- n.close(), r({ ok: !1, value: null });
34
+ const i = n.transaction(I, t), r = e(i.objectStore(I));
35
+ r.onsuccess = () => o({ ok: !0, value: r.result }), r.onerror = () => o({ ok: !1, value: null }), i.oncomplete = () => n.close(), i.onerror = () => {
36
+ n.close(), o({ ok: !1, value: null });
37
37
  };
38
38
  } catch {
39
- n.close(), r({ ok: !1, value: null });
39
+ n.close(), o({ ok: !1, value: null });
40
40
  }
41
41
  }) : { ok: !1, value: null };
42
42
  }
43
- async function T(t) {
44
- O.set(t.id, t), await g("readwrite", (e) => e.put(t));
43
+ async function P(t) {
44
+ C.set(t.id, t), await j("readwrite", (e) => e.put(t));
45
45
  }
46
- async function v(t) {
47
- O.delete(t), await g("readwrite", (e) => e.delete(t));
46
+ async function S(t) {
47
+ C.delete(t), await j("readwrite", (e) => e.delete(t));
48
48
  }
49
49
  async function x(t) {
50
- const e = await g("readonly", (n) => n.get(t));
51
- return e.ok ? e.value ?? null : O.get(t) ?? null;
50
+ const e = await j("readonly", (n) => n.get(t));
51
+ return e.ok ? e.value ?? null : C.get(t) ?? null;
52
52
  }
53
- async function M() {
54
- const t = await g("readonly", (e) => e.getAll());
55
- return t.ok ? t.value ?? [] : [...O.values()];
53
+ async function V() {
54
+ const t = await j("readonly", (e) => e.getAll());
55
+ return t.ok ? t.value ?? [] : [...C.values()];
56
56
  }
57
- function W(t) {
57
+ function F(t) {
58
58
  return JSON.parse(JSON.stringify(t ?? null));
59
59
  }
60
- let l = null, it = !1, j = null, w = null, a = [];
61
- const D = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set();
62
- let S = null, A = !1, m = null;
63
- function d() {
64
- for (const t of D) t();
60
+ let f = null, wt = !1, L = null, d = null, c = [];
61
+ const T = /* @__PURE__ */ new Set(), B = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Set();
62
+ let $ = null, X = !1, b = null;
63
+ function w() {
64
+ for (const t of T) t();
65
65
  }
66
- function R(t) {
67
- for (const e of I)
66
+ function E(t) {
67
+ for (const e of B)
68
68
  try {
69
69
  e(t);
70
70
  } catch {
71
71
  }
72
72
  }
73
- function y() {
73
+ function m() {
74
74
  try {
75
- m == null || m.postMessage({ type: "changed" });
75
+ b == null || b.postMessage({ type: "changed" });
76
76
  } catch {
77
77
  }
78
78
  }
79
- function K(t, e) {
79
+ function Z(t, e) {
80
80
  const n = new Date(t.created_at).getTime();
81
- return !Number.isFinite(n) || e - n > tt;
81
+ return !Number.isFinite(n) || e - n > ct;
82
82
  }
83
- async function st(t) {
84
- const e = B();
83
+ async function ht(t) {
84
+ const e = H();
85
85
  if (!e) return t();
86
86
  await e.request("nvr-record-outbox:sweep", {}, t).catch(() => {
87
87
  });
88
88
  }
89
- async function V() {
90
- const t = l;
91
- t && await st(async () => {
89
+ async function Q() {
90
+ const t = f;
91
+ t && await ht(async () => {
92
92
  const e = Date.now();
93
- for (const n of await M()) {
94
- if (!n || n.owner !== t || !K(n, e)) continue;
95
- const r = await x(n.id);
96
- r && (await v(n.id), a = a.filter((o) => o.id !== n.id), d(), y(), l === t && R({ type: "expired", entry: r }));
93
+ for (const n of await V()) {
94
+ if (!n || n.owner !== t || !Z(n, e)) continue;
95
+ const o = await x(n.id);
96
+ o && (await S(n.id), c = c.filter((i) => i.id !== n.id), w(), m(), f === t && E({ type: "expired", entry: o }));
97
97
  }
98
98
  });
99
99
  }
100
- async function at(t) {
101
- for (const e of await M()) e && e.owner !== t && await v(e.id);
102
- }
103
- async function $() {
104
- if (!l) return;
105
- const t = l, e = await M(), n = Date.now(), r = [];
106
- let o = !1;
107
- for (const i of e)
108
- if (!(!i || i.owner !== t)) {
109
- if (K(i, n)) {
110
- o = !0;
100
+ async function mt(t) {
101
+ for (const e of await V()) e && e.owner !== t && await S(e.id);
102
+ }
103
+ async function A() {
104
+ if (!f) return;
105
+ const t = f, e = await V(), n = Date.now(), o = [];
106
+ let i = !1;
107
+ for (const r of e)
108
+ if (!(!r || r.owner !== t)) {
109
+ if (Z(r, n)) {
110
+ i = !0;
111
111
  continue;
112
112
  }
113
- r.push(i.status === "sending" ? { ...i, status: "queued" } : i);
113
+ o.push(r.status === "sending" ? { ...r, status: "queued" } : r);
114
114
  }
115
- l === t && (a = r, d(), o && await V());
115
+ f === t && (c = o, w(), i && await Q());
116
116
  }
117
- function bt(t, e, n) {
118
- j = t, n && (w = n);
119
- const r = et(e);
120
- if (!(!r || r === l)) {
121
- if (l = r, a = [], d(), typeof BroadcastChannel < "u" && !m)
117
+ function Rt(t, e, n) {
118
+ L = t, n && (d = n);
119
+ const o = ut(e);
120
+ if (!(!o || o === f)) {
121
+ if (f = o, c = [], w(), typeof BroadcastChannel < "u" && !b)
122
122
  try {
123
- m = new BroadcastChannel("nvr-record-outbox"), m.onmessage = () => void $();
123
+ b = new BroadcastChannel("nvr-record-outbox"), b.onmessage = () => void A();
124
124
  } catch {
125
- m = null;
125
+ b = null;
126
126
  }
127
- !A && typeof window < "u" && (A = !0, window.addEventListener("online", () => b(0))), at(r).then(() => (y(), $())).then(() => {
128
- a.some((o) => o.status === "queued") && b(1e3);
127
+ !X && typeof window < "u" && (X = !0, window.addEventListener("online", () => O(0))), mt(o).then(() => (m(), A())).then(() => {
128
+ c.some((i) => i.status === "queued") && O(1e3);
129
129
  });
130
130
  }
131
131
  }
132
- function pt() {
133
- return a;
132
+ function kt() {
133
+ return c;
134
134
  }
135
- function Ot(t) {
136
- return D.add(t), () => D.delete(t);
135
+ function qt(t) {
136
+ return T.add(t), () => T.delete(t);
137
137
  }
138
- function gt(t) {
139
- return I.add(t), () => I.delete(t);
138
+ function Ct(t) {
139
+ return B.add(t), () => B.delete(t);
140
140
  }
141
- function vt(t) {
142
- return N.add(t), () => N.delete(t);
141
+ function jt(t) {
142
+ return M.add(t), () => M.delete(t);
143
143
  }
144
- function F(t) {
145
- var r;
146
- const e = t, n = (e == null ? void 0 : e.status) ?? ((r = e == null ? void 0 : e.response) == null ? void 0 : r.status);
144
+ function k(t) {
145
+ var o;
146
+ const e = t, n = (e == null ? void 0 : e.status) ?? ((o = e == null ? void 0 : e.response) == null ? void 0 : o.status);
147
147
  return n == null ? !(e != null && e.response) : n === 0 || n === 502 || n === 503 || n === 504;
148
148
  }
149
- function ct(t) {
149
+ function tt(t) {
150
150
  const e = t == null ? void 0 : t.response, n = (e == null ? void 0 : e.data) ?? e;
151
151
  return (n == null ? void 0 : n.code) !== "MIDAIR_COLLISION" || !Array.isArray(n.conflicts) ? null : { conflicts: n.conflicts, latest: Number(n.latest_revision) || 0 };
152
152
  }
153
- function L(t, e) {
153
+ function g(t, e) {
154
154
  if (t === e) return !0;
155
155
  if (t == null || e == null) return t == null && e == null;
156
156
  try {
@@ -159,215 +159,362 @@ function L(t, e) {
159
159
  return !1;
160
160
  }
161
161
  }
162
- async function xt(t) {
163
- const e = l;
164
- if (!e || it) return null;
162
+ async function Et(t) {
163
+ const e = f;
164
+ if (!e || wt) return null;
165
165
  const n = {};
166
- for (const [f, Y] of Object.entries(t.payload)) f.startsWith("_") || (n[f] = Y);
166
+ for (const [l, R] of Object.entries(t.payload)) l.startsWith("_") || (n[l] = R);
167
167
  if (Object.keys(n).length === 0) return null;
168
- const r = p(e, t.collection, t.item), o = a.find((f) => f.id === r) ?? await x(r), i = (/* @__PURE__ */ new Date()).toISOString(), c = !o || Object.keys(o.payload).every((f) => f in n), s = c ? {} : { ...o.before };
169
- for (const f of Object.keys(n))
170
- (c || !(f in s)) && (s[f] = t.before[f] ?? null);
171
- const u = (o == null ? void 0 : o.base_revision) ?? null, X = c ? t.baseRevision : u == null || t.baseRevision == null ? null : Math.min(u, t.baseRevision), q = W({
172
- id: r,
168
+ const o = _(e, t.collection, t.item), i = c.find((l) => l.id === o) ?? await x(o), r = (/* @__PURE__ */ new Date()).toISOString(), a = !i || Object.keys(i.payload).every((l) => l in n), s = a ? {} : { ...i.before };
169
+ for (const l of Object.keys(n))
170
+ (a || !(l in s)) && (s[l] = t.before[l] ?? null);
171
+ const u = (i == null ? void 0 : i.base_revision) ?? null, h = a ? t.baseRevision : u == null || t.baseRevision == null ? null : Math.min(u, t.baseRevision), y = F({
172
+ id: o,
173
173
  owner: e,
174
174
  collection: t.collection,
175
175
  item: String(t.item),
176
- payload: { ...(o == null ? void 0 : o.payload) ?? {}, ...n },
176
+ payload: { ...(i == null ? void 0 : i.payload) ?? {}, ...n },
177
177
  before: s,
178
- base_revision: X ?? null,
179
- change_reason: t.changeReason ?? (o == null ? void 0 : o.change_reason) ?? null,
180
- created_at: (o == null ? void 0 : o.created_at) ?? i,
181
- updated_at: i,
178
+ base_revision: h ?? null,
179
+ change_reason: t.changeReason ?? (i == null ? void 0 : i.change_reason) ?? null,
180
+ created_at: (i == null ? void 0 : i.created_at) ?? r,
181
+ updated_at: r,
182
182
  status: "queued",
183
183
  error: null,
184
184
  conflicts: null,
185
185
  latest_revision: null
186
186
  });
187
- return l !== e ? null : (a = [...a.filter((f) => f.id !== r), q], d(), await T(q), y(), b(P), q);
188
- }
189
- async function St(t, e, n) {
190
- if (!l) return;
191
- const r = p(l, t, e), o = a.find((s) => s.id === r) ?? await x(r);
192
- if (!o || o.owner !== l) return;
193
- const i = new Set(n), c = {};
194
- for (const [s, u] of Object.entries(o.payload)) i.has(s) || (c[s] = u);
195
- if (Object.keys(c).length === 0)
196
- a = a.filter((s) => s.id !== r), d(), await v(r);
187
+ return f !== e ? null : (c = [...c.filter((l) => l.id !== o), y], w(), await P(y), m(), O(G), y);
188
+ }
189
+ async function $t(t, e, n) {
190
+ if (!f) return;
191
+ const o = _(f, t, e), i = c.find((s) => s.id === o) ?? await x(o);
192
+ if (!i || i.owner !== f) return;
193
+ const r = new Set(n), a = {};
194
+ for (const [s, u] of Object.entries(i.payload)) r.has(s) || (a[s] = u);
195
+ if (Object.keys(a).length === 0)
196
+ c = c.filter((s) => s.id !== o), w(), await S(o);
197
197
  else {
198
198
  const s = {
199
- ...o,
200
- payload: c,
199
+ ...i,
200
+ payload: a,
201
201
  status: "queued",
202
202
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
203
203
  };
204
- a = a.map((u) => u.id === r ? s : u), d(), await T(s);
204
+ c = c.map((u) => u.id === o ? s : u), w(), await P(s);
205
205
  }
206
- y();
206
+ m();
207
207
  }
208
- async function kt(t, e) {
209
- if (!l) return;
210
- const n = p(l, t, e);
211
- a = a.filter((r) => r.id !== n), d(), await v(n), y();
208
+ async function It(t, e) {
209
+ if (!f) return;
210
+ const n = _(f, t, e);
211
+ c = c.filter((o) => o.id !== n), w(), await S(n), m();
212
212
  }
213
- async function _t() {
214
- z(), a = [], O.clear(), d(), await g("readwrite", (t) => t.clear()), y();
213
+ async function Nt() {
214
+ rt(), c = [], C.clear(), w(), await j("readwrite", (t) => t.clear()), m();
215
215
  }
216
- async function h(t, e) {
217
- const n = a.find((o) => o.id === t) ?? await x(t);
216
+ async function p(t, e) {
217
+ const n = c.find((i) => i.id === t) ?? await x(t);
218
218
  if (!n) return null;
219
- const r = { ...n, ...e };
220
- return a = a.some((o) => o.id === t) ? a.map((o) => o.id === t ? r : o) : a, d(), await T(r), y(), r;
219
+ const o = { ...n, ...e };
220
+ return c = c.some((i) => i.id === t) ? c.map((i) => i.id === t ? o : i) : c, w(), await P(o), m(), o;
221
221
  }
222
- function B() {
222
+ function H() {
223
223
  const t = globalThis.navigator;
224
224
  return (t == null ? void 0 : t.locks) ?? null;
225
225
  }
226
- const _ = /* @__PURE__ */ new Set();
227
- function Rt(t, e) {
228
- if (!l) return () => {
226
+ const q = /* @__PURE__ */ new Set();
227
+ function Dt(t, e) {
228
+ if (!f) return () => {
229
229
  };
230
- const n = p(l, t, e);
231
- _.add(n);
232
- let r = () => {
230
+ const n = _(f, t, e);
231
+ q.add(n), c = [...c], w();
232
+ let o = () => {
233
233
  };
234
- const o = new Promise((c) => {
235
- r = c;
236
- }), i = B();
237
- return i && i.request(`nvr-record-outbox:${n}`, {}, () => o).catch(() => {
234
+ const i = new Promise((a) => {
235
+ o = a;
236
+ }), r = H();
237
+ return r && r.request(`nvr-record-outbox:${n}`, {}, () => i).catch(() => {
238
238
  }), () => {
239
- _.delete(n), r();
239
+ q.delete(n), c = [...c], w(), o();
240
240
  };
241
241
  }
242
- async function lt(t, e) {
243
- if (_.has(t)) return;
244
- const n = B();
242
+ const U = /* @__PURE__ */ new Set();
243
+ function Lt() {
244
+ if (c.some((t) => t.status === "conflict"))
245
+ for (const t of U) t();
246
+ }
247
+ function Tt(t) {
248
+ return U.add(t), () => U.delete(t);
249
+ }
250
+ function Bt(t) {
251
+ return q.has(t);
252
+ }
253
+ async function pt(t, e) {
254
+ if (q.has(t)) return;
255
+ const n = H();
245
256
  if (!n) return e();
246
- await n.request(`nvr-record-outbox:${t}`, { ifAvailable: !0 }, async (r) => {
247
- r && await e();
257
+ await n.request(`nvr-record-outbox:${t}`, { ifAvailable: !0 }, async (o) => {
258
+ o && await e();
248
259
  }).catch(() => {
249
260
  });
250
261
  }
251
- let E = !1;
252
- function b(t) {
253
- S && clearTimeout(S), S = setTimeout(() => {
254
- S = null, ft();
262
+ let D = !1;
263
+ function O(t) {
264
+ $ && clearTimeout($), $ = setTimeout(() => {
265
+ $ = null, vt();
255
266
  }, t);
256
267
  }
257
- async function ut(t, e) {
268
+ async function bt(t, e) {
258
269
  var n;
259
270
  try {
260
- const r = await t.request(C("/auth/me")), o = (n = r == null ? void 0 : r.data) == null ? void 0 : n.id;
261
- return !!o && String(o).toLowerCase() === nt(e).toLowerCase();
262
- } catch (r) {
263
- return F(r) ? null : !1;
271
+ const o = await t.request(v("/auth/me")), i = (n = o == null ? void 0 : o.data) == null ? void 0 : n.id;
272
+ return !!i && String(i).toLowerCase() === ft(e).toLowerCase();
273
+ } catch (o) {
274
+ return k(o) ? null : !1;
264
275
  }
265
276
  }
266
- async function ft() {
267
- if (E || !j || !l || (await V(), !a.some((r) => r.status === "queued"))) return;
268
- E = !0;
269
- const t = j, e = l;
277
+ async function vt() {
278
+ if (D || !L || !f || (await Q(), !c.some((o) => o.status === "queued"))) return;
279
+ D = !0;
280
+ const t = L, e = f;
270
281
  let n = !1;
271
282
  try {
272
- const r = await ut(t, e);
273
- if (r === null) {
283
+ const o = await bt(t, e);
284
+ if (o === null) {
274
285
  n = !0;
275
286
  return;
276
287
  }
277
- if (!r) return;
278
- for (const i of N) i();
279
- const o = a.filter((i) => i.status === "queued" && !_.has(i.id));
280
- for (const i of o) {
281
- if (l !== e) return;
282
- if (await lt(i.id, async () => {
283
- const c = await x(i.id);
284
- if (!c || c.owner !== e || c.status !== "queued") {
285
- await $();
288
+ if (!o) return;
289
+ for (const r of M) r();
290
+ const i = c.filter((r) => r.status === "queued" && !q.has(r.id));
291
+ for (const r of i) {
292
+ if (f !== e) return;
293
+ if (await pt(r.id, async () => {
294
+ const a = await x(r.id);
295
+ if (!a || a.owner !== e || a.status !== "queued") {
296
+ await A();
286
297
  return;
287
298
  }
288
- await yt(t, c) === "offline" && (n = !0);
299
+ await Ot(t, a) === "offline" && (n = !0);
289
300
  }), n) break;
290
301
  }
291
302
  } finally {
292
- E = !1, n && b(P);
303
+ D = !1, n && O(G);
293
304
  }
294
305
  }
295
- async function dt(t, e) {
296
- const n = Object.keys(e.payload), r = await t.request(
297
- C(`/items/${e.collection}/${encodeURIComponent(e.item)}`, { fields: n.join(",") })
298
- ), o = (r == null ? void 0 : r.data) ?? {}, i = [];
306
+ async function Mt(t, e) {
307
+ const n = Object.keys(e.payload), o = await t.request(
308
+ v(`/items/${e.collection}/${encodeURIComponent(e.item)}`, { fields: n.join(",") })
309
+ ), i = (o == null ? void 0 : o.data) ?? {}, r = [];
299
310
  for (const s of n) {
300
- const u = o[s] ?? null;
301
- !L(u, e.before[s] ?? null) && !L(u, e.payload[s]) && i.push({ field: s, current_value: u });
311
+ const u = i[s] ?? null;
312
+ !g(u, e.before[s] ?? null) && !g(u, e.payload[s]) && r.push({ field: s, current_value: u });
302
313
  }
303
- const c = await t.request(
304
- C("/revisions", { collection: e.collection, item: e.item, latest_only: "1" })
314
+ const a = await t.request(
315
+ v("/revisions", { collection: e.collection, item: e.item, latest_only: "1" })
305
316
  ).then((s) => {
306
317
  var u;
307
318
  return ((u = s == null ? void 0 : s.data) == null ? void 0 : u.latest) ?? null;
308
319
  });
309
- return { conflicts: i, latest: c == null ? null : Number(c) || null };
320
+ return { conflicts: r, latest: a == null ? null : Number(a) || null };
321
+ }
322
+ async function gt(t, e) {
323
+ var h;
324
+ const n = await t.request(
325
+ v("/revisions", { collection: e.collection, item: e.item, latest_only: "1" })
326
+ ), o = (h = n == null ? void 0 : n.data) == null ? void 0 : h.latest, i = o == null ? null : Number(o) || null;
327
+ if (e.base_revision != null && (i == null || i <= e.base_revision))
328
+ return { clashes: [], latest: e.base_revision };
329
+ const r = Object.keys(e.payload), a = await t.request(
330
+ v(`/items/${e.collection}/${encodeURIComponent(e.item)}`, { fields: r.join(",") })
331
+ ), s = (a == null ? void 0 : a.data) ?? {}, u = [];
332
+ for (const y of r) {
333
+ if (!(y in s)) continue;
334
+ const l = s[y] ?? null;
335
+ !g(l, e.before[y] ?? null) && !g(l, e.payload[y]) && u.push({ field: y, current_value: l });
336
+ }
337
+ return u.length > 0 && await et(t, e, u), { clashes: u, latest: i };
310
338
  }
311
- async function yt(t, e) {
312
- var n, r;
313
- await h(e.id, { status: "sending" });
339
+ async function et(t, e, n) {
314
340
  try {
315
- let o = e.base_revision;
316
- if (o == null) {
317
- const c = await dt(t, e);
318
- if (c.conflicts.length > 0) return J(e, c.conflicts, c.latest ?? 0);
319
- o = c.latest;
341
+ const o = await t.request(
342
+ v("/revisions/field-touch", {
343
+ collection: e.collection,
344
+ item: e.item,
345
+ fields: n.map((r) => r.field).join(",")
346
+ })
347
+ ), i = (o == null ? void 0 : o.data) ?? {};
348
+ for (const r of n) {
349
+ const a = i[r.field];
350
+ r.by = a != null && a.who ? String(a.who).slice(0, 80) : null, r.at = a != null && a.at ? String(a.at) : null;
320
351
  }
321
- const i = { ...e.payload };
322
- return o != null && (i._base_revision = o), e.change_reason && (i._change_reason = e.change_reason), await t.request(G(`/items/${e.collection}/${encodeURIComponent(e.item)}`, i)), U(e);
352
+ } catch {
353
+ }
354
+ }
355
+ async function nt(t, e, n) {
356
+ if (n.length === 0) return [];
357
+ let o = null;
358
+ try {
359
+ const r = await t.request(
360
+ v(`/items/${e.collection}/${encodeURIComponent(e.item)}`, {
361
+ fields: n.map((a) => a.field).join(",")
362
+ })
363
+ );
364
+ o = (r == null ? void 0 : r.data) ?? null;
365
+ } catch {
366
+ o = null;
367
+ }
368
+ const i = n.map(
369
+ (r) => o && r.field in o ? { field: r.field, current_value: o[r.field] ?? null } : { field: r.field, current_value: null, hidden: !0 }
370
+ );
371
+ return await et(t, e, i), i;
372
+ }
373
+ function K(t, e) {
374
+ const n = {};
375
+ for (const o of e) o in t && (n[o] = t[o]);
376
+ return n;
377
+ }
378
+ function ot(t, e, n) {
379
+ const o = n ? K(t.payload, n) : { ...t.payload };
380
+ return e != null && (o._base_revision = e), t.change_reason && (o._change_reason = t.change_reason), o;
381
+ }
382
+ async function Ot(t, e) {
383
+ await p(e.id, { status: "sending" });
384
+ const n = `/items/${e.collection}/${encodeURIComponent(e.item)}`;
385
+ try {
386
+ let o = null;
387
+ try {
388
+ o = await gt(t, e);
389
+ } catch (r) {
390
+ if (k(r) || e.base_revision == null) throw r;
391
+ o = null;
392
+ }
393
+ const i = e.base_revision ?? (o == null ? void 0 : o.latest) ?? null;
394
+ return o && o.clashes.length > 0 ? await J(t, e, o, i) : (await t.request(z(n, ot(e, i))), Y(e));
323
395
  } catch (o) {
324
- if (F(o))
325
- return await h(e.id, { status: "queued", error: "Waiting for a connection" }), "offline";
326
- const i = ct(o);
327
- if (i)
328
- return i.conflicts.every((u) => L(u.current_value, e.payload[u.field])) ? U(e) : J(e, i.conflicts, i.latest);
329
- const c = ((n = o == null ? void 0 : o.response) == null ? void 0 : n.message) ?? ((r = o == null ? void 0 : o.response) == null ? void 0 : r.error) ?? H(o, "Could not save"), s = await h(e.id, { status: "failed", error: c });
330
- return s && R({ type: "failed", entry: s }), "failed";
396
+ if (k(o))
397
+ return await p(e.id, { status: "queued", error: "Waiting for a connection" }), "offline";
398
+ const i = tt(o);
399
+ if (i) {
400
+ const r = i.conflicts.filter((s) => !g(s.current_value, e.payload[s.field]));
401
+ if (r.length === 0) return Y(e);
402
+ const a = await nt(t, e, r);
403
+ try {
404
+ return await J(
405
+ t,
406
+ e,
407
+ { clashes: a, latest: i.latest },
408
+ e.base_revision,
409
+ !0
410
+ );
411
+ } catch (s) {
412
+ return k(s) ? (await p(e.id, { status: "queued", error: "Waiting for a connection" }), "offline") : W(e, s);
413
+ }
414
+ }
415
+ return W(e, o);
331
416
  }
332
417
  }
333
- async function U(t) {
334
- return a = a.filter((e) => e.id !== t.id), d(), await v(t.id), y(), R({ type: "replayed", entry: t }), w == null || w.invalidateQueries({ queryKey: ["item", t.collection] }), w == null || w.invalidateQueries({ queryKey: ["collision-base", t.collection] }), "done";
418
+ async function W(t, e) {
419
+ var i, r;
420
+ const n = ((i = e == null ? void 0 : e.response) == null ? void 0 : i.message) ?? ((r = e == null ? void 0 : e.response) == null ? void 0 : r.error) ?? st(e, "Could not save"), o = await p(t.id, { status: "failed", error: n });
421
+ return o && E({ type: "failed", entry: o }), "failed";
335
422
  }
336
- async function J(t, e, n) {
337
- const r = await h(t.id, {
423
+ async function J(t, e, n, o, i = !1) {
424
+ const r = new Set(n.clashes.map((l) => l.field)), a = Object.keys(e.payload).filter((l) => !r.has(l)), s = [...n.clashes];
425
+ let u = [];
426
+ if (a.length > 0)
427
+ try {
428
+ await t.request(
429
+ z(`/items/${e.collection}/${encodeURIComponent(e.item)}`, ot(e, o, a))
430
+ ), u = a;
431
+ } catch (l) {
432
+ if (k(l)) throw l;
433
+ const R = tt(l);
434
+ if (!R || i) return W(e, l);
435
+ const it = R.conflicts.filter(
436
+ (N) => !r.has(N.field) && !g(N.current_value, e.payload[N.field])
437
+ );
438
+ return s.push(...await nt(t, e, it)), J(
439
+ t,
440
+ e,
441
+ { clashes: s, latest: R.latest || n.latest },
442
+ o,
443
+ !0
444
+ );
445
+ }
446
+ const h = s.map((l) => l.field), y = await p(e.id, {
338
447
  status: "conflict",
339
- conflicts: W(e),
340
- latest_revision: n,
448
+ payload: K(e.payload, h),
449
+ before: K(e.before, h),
450
+ conflicts: F(s),
451
+ latest_revision: n.latest,
452
+ sent_fields: [.../* @__PURE__ */ new Set([...e.sent_fields ?? [], ...u])],
341
453
  error: "Someone else changed this record"
342
454
  });
343
- return r && R({ type: "conflict", entry: r }), "conflict";
455
+ return u.length > 0 && (d == null || d.invalidateQueries({ queryKey: ["item", e.collection] }), d == null || d.invalidateQueries({ queryKey: ["collision-base", e.collection] })), y && E({ type: "conflict", entry: y }), "conflict";
456
+ }
457
+ async function At(t, e, n, o) {
458
+ if (!f) return;
459
+ const i = _(f, t, e), r = c.find((l) => l.id === i) ?? await x(i);
460
+ if (!r || r.owner !== f || r.status !== "conflict") return;
461
+ const a = (r.conflicts ?? []).find((l) => l.field === n);
462
+ if (!a) return;
463
+ const s = { ...r.payload }, u = { ...r.before };
464
+ o === "theirs" ? (delete s[n], delete u[n]) : (typeof o == "object" && (s[n] = F(o.merged)), a.hidden || (u[n] = a.current_value));
465
+ const h = (r.conflicts ?? []).filter((l) => l.field !== n), y = (/* @__PURE__ */ new Date()).toISOString();
466
+ if (h.length > 0) {
467
+ await p(i, { payload: s, before: u, conflicts: h, updated_at: y });
468
+ return;
469
+ }
470
+ if (Object.keys(s).length === 0) {
471
+ c = c.filter((l) => l.id !== i), w(), await S(i), m(), E({ type: "resolved", entry: { ...r, payload: s, conflicts: [] } }), d == null || d.invalidateQueries({ queryKey: ["item", r.collection] });
472
+ return;
473
+ }
474
+ await p(i, {
475
+ payload: s,
476
+ before: u,
477
+ conflicts: null,
478
+ status: "queued",
479
+ error: null,
480
+ base_revision: r.latest_revision ?? r.base_revision,
481
+ updated_at: y
482
+ }), O(0);
483
+ }
484
+ async function Y(t) {
485
+ return c = c.filter((e) => e.id !== t.id), w(), await S(t.id), m(), E({ type: "replayed", entry: t }), d == null || d.invalidateQueries({ queryKey: ["item", t.collection] }), d == null || d.invalidateQueries({ queryKey: ["collision-base", t.collection] }), "done";
344
486
  }
345
- async function qt(t, e) {
346
- l && (await h(p(l, t, e), {
487
+ async function Ut(t, e) {
488
+ f && (await p(_(f, t, e), {
347
489
  status: "queued",
348
490
  error: null,
349
491
  conflicts: null
350
- }), b(0));
492
+ }), O(0));
351
493
  }
352
494
  export {
353
- tt as RECORD_OUTBOX_TTL_MS,
354
- bt as bindRecordOutbox,
355
- dt as checkUnknownBase,
356
- Rt as claimRecordOutbox,
357
- _t as clearRecordOutbox,
358
- kt as discardRecordOutbox,
359
- xt as enqueueRecordSave,
360
- pt as getRecordOutbox,
361
- F as isOfflineSaveError,
362
- ct as midairCollisionOf,
363
- gt as onRecordOutboxEvent,
364
- vt as onRecordOutboxRetry,
365
- p as outboxEntryId,
366
- et as outboxOwner,
367
- ft as replayRecordOutbox,
368
- qt as retryRecordOutbox,
369
- b as scheduleReplay,
370
- St as settleRecordOutbox,
371
- Ot as subscribeRecordOutbox,
372
- V as sweepExpiredRecordOutbox
495
+ ct as RECORD_OUTBOX_TTL_MS,
496
+ Rt as bindRecordOutbox,
497
+ Mt as checkUnknownBase,
498
+ Dt as claimRecordOutbox,
499
+ Nt as clearRecordOutbox,
500
+ It as discardRecordOutbox,
501
+ Et as enqueueRecordSave,
502
+ kt as getRecordOutbox,
503
+ k as isOfflineSaveError,
504
+ Bt as isRecordOutboxHeld,
505
+ tt as midairCollisionOf,
506
+ Lt as nudgeOutboxReview,
507
+ Tt as onOutboxReviewNudge,
508
+ Ct as onRecordOutboxEvent,
509
+ jt as onRecordOutboxRetry,
510
+ _ as outboxEntryId,
511
+ ut as outboxOwner,
512
+ gt as planOutboxSend,
513
+ vt as replayRecordOutbox,
514
+ At as resolveRecordOutboxField,
515
+ Ut as retryRecordOutbox,
516
+ O as scheduleReplay,
517
+ $t as settleRecordOutbox,
518
+ qt as subscribeRecordOutbox,
519
+ Q as sweepExpiredRecordOutbox
373
520
  };