@arbidocs/react 0.4.63 → 0.4.65

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 (59) hide show
  1. package/dist/annotations/index.cjs +263 -82
  2. package/dist/annotations/index.cjs.map +1 -1
  3. package/dist/annotations/index.d.cts +72 -5
  4. package/dist/annotations/index.d.ts +72 -5
  5. package/dist/annotations/index.js +238 -63
  6. package/dist/annotations/index.js.map +1 -1
  7. package/dist/artifacts/index.cjs +79 -50
  8. package/dist/artifacts/index.cjs.map +1 -1
  9. package/dist/artifacts/index.d.cts +52 -31
  10. package/dist/artifacts/index.d.ts +52 -31
  11. package/dist/artifacts/index.js +63 -37
  12. package/dist/artifacts/index.js.map +1 -1
  13. package/dist/{chunk-QS3Q5542.js → chunk-2VW47ADK.js} +10 -3
  14. package/dist/chunk-2VW47ADK.js.map +1 -0
  15. package/dist/chunk-4PRCRCQ5.cjs +41 -0
  16. package/dist/chunk-4PRCRCQ5.cjs.map +1 -0
  17. package/dist/{chunk-X3F5ABY2.cjs → chunk-6YKVIERB.cjs} +43 -21
  18. package/dist/chunk-6YKVIERB.cjs.map +1 -0
  19. package/dist/{chunk-Z4M7JB4L.cjs → chunk-D3CSLSGD.cjs} +9 -9
  20. package/dist/{chunk-Z4M7JB4L.cjs.map → chunk-D3CSLSGD.cjs.map} +1 -1
  21. package/dist/{chunk-N5SVBDLC.js → chunk-DIZC2XVB.js} +11 -4
  22. package/dist/chunk-DIZC2XVB.js.map +1 -0
  23. package/dist/{chunk-CVN7MAGQ.js → chunk-F5WHYJRB.js} +29 -7
  24. package/dist/chunk-F5WHYJRB.js.map +1 -0
  25. package/dist/{chunk-XDCRWZF2.cjs → chunk-GXQO3IJC.cjs} +10 -3
  26. package/dist/chunk-GXQO3IJC.cjs.map +1 -0
  27. package/dist/{chunk-OBNTJEEO.cjs → chunk-LCMCZS5Y.cjs} +11 -4
  28. package/dist/chunk-LCMCZS5Y.cjs.map +1 -0
  29. package/dist/{chunk-UDOPD3GK.js → chunk-NDABXDML.js} +3 -3
  30. package/dist/{chunk-UDOPD3GK.js.map → chunk-NDABXDML.js.map} +1 -1
  31. package/dist/chunk-QICALPFQ.js +18 -0
  32. package/dist/chunk-QICALPFQ.js.map +1 -0
  33. package/dist/{chunk-DSG3E7QX.js → chunk-SX7FCSON.js} +2 -2
  34. package/dist/chunk-SX7FCSON.js.map +1 -0
  35. package/dist/{chunk-UUE2R2E2.cjs → chunk-VH5ITITV.cjs} +2 -2
  36. package/dist/chunk-VH5ITITV.cjs.map +1 -0
  37. package/dist/{index-CUxIcC5j.d.ts → index-BWv_FKi3.d.cts} +18 -3
  38. package/dist/{index-CUxIcC5j.d.cts → index-BWv_FKi3.d.ts} +18 -3
  39. package/dist/index.cjs +356 -347
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +46 -8
  42. package/dist/index.d.ts +46 -8
  43. package/dist/index.js +11 -10
  44. package/dist/index.js.map +1 -1
  45. package/dist/shell/index.cjs +8 -7
  46. package/dist/shell/index.js +3 -2
  47. package/dist/ui/index.cjs +152 -143
  48. package/dist/ui/index.d.cts +1 -1
  49. package/dist/ui/index.d.ts +1 -1
  50. package/dist/ui/index.js +4 -3
  51. package/package.json +3 -3
  52. package/dist/chunk-CVN7MAGQ.js.map +0 -1
  53. package/dist/chunk-DSG3E7QX.js.map +0 -1
  54. package/dist/chunk-N5SVBDLC.js.map +0 -1
  55. package/dist/chunk-OBNTJEEO.cjs.map +0 -1
  56. package/dist/chunk-QS3Q5542.js.map +0 -1
  57. package/dist/chunk-UUE2R2E2.cjs.map +0 -1
  58. package/dist/chunk-X3F5ABY2.cjs.map +0 -1
  59. package/dist/chunk-XDCRWZF2.cjs.map +0 -1
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkXDCRWZF2_cjs = require('../chunk-XDCRWZF2.cjs');
3
+ var chunkGXQO3IJC_cjs = require('../chunk-GXQO3IJC.cjs');
4
+ require('../chunk-4PRCRCQ5.cjs');
4
5
  var chunkS6A6FSG7_cjs = require('../chunk-S6A6FSG7.cjs');
5
6
  var chunkSSOPIPEX_cjs = require('../chunk-SSOPIPEX.cjs');
6
7
  var react = require('react');
@@ -134,6 +135,12 @@ function pendingRedactions(layer) {
134
135
  }
135
136
 
136
137
  // src/annotations/store.ts
138
+ var AnnotationStoreOfflineError = class extends Error {
139
+ constructor(message = "You are offline") {
140
+ super(message);
141
+ this.name = "AnnotationStoreOfflineError";
142
+ }
143
+ };
137
144
  function createMemoryStore(now = () => (/* @__PURE__ */ new Date()).toISOString()) {
138
145
  const layers = /* @__PURE__ */ new Map();
139
146
  return {
@@ -171,6 +178,56 @@ function safeLocalStorage() {
171
178
  }
172
179
  }
173
180
 
181
+ // src/annotations/merge.ts
182
+ var time = (iso) => {
183
+ const t = Date.parse(iso);
184
+ return Number.isNaN(t) ? 0 : t;
185
+ };
186
+ function mergeReplies(a, b) {
187
+ const byId = /* @__PURE__ */ new Map();
188
+ for (const r of [...a, ...b]) if (!byId.has(r.id)) byId.set(r.id, r);
189
+ return [...byId.values()].sort((x, y) => time(x.createdAt) - time(y.createdAt));
190
+ }
191
+ function newer(mine, theirs) {
192
+ const winner = time(theirs.updatedAt) > time(mine.updatedAt) ? theirs : mine;
193
+ if (mine.kind === "comment" && theirs.kind === "comment" && winner.kind === "comment") {
194
+ const replies = mergeReplies(mine.replies, theirs.replies);
195
+ if (replies.length !== winner.replies.length) return { ...winner, replies };
196
+ }
197
+ return winner;
198
+ }
199
+ function mergeLayers({ base, mine, theirs, deleted }) {
200
+ const baseById = new Map((base?.annotations ?? []).map((a) => [a.id, a]));
201
+ const theirsById = new Map(theirs.annotations.map((a) => [a.id, a]));
202
+ const mineIds = new Set(mine.annotations.map((a) => a.id));
203
+ const out = [];
204
+ for (const m of mine.annotations) {
205
+ if (deleted?.has(m.id)) continue;
206
+ const t = theirsById.get(m.id);
207
+ if (t) {
208
+ out.push(newer(m, t));
209
+ continue;
210
+ }
211
+ const b = baseById.get(m.id);
212
+ if (b && time(m.updatedAt) <= time(b.updatedAt)) continue;
213
+ out.push(m);
214
+ }
215
+ for (const t of theirs.annotations) {
216
+ if (mineIds.has(t.id) || deleted?.has(t.id)) continue;
217
+ if (baseById.has(t.id)) continue;
218
+ out.push(t);
219
+ }
220
+ const updatedAt = time(theirs.updatedAt) > time(mine.updatedAt) ? theirs.updatedAt : mine.updatedAt;
221
+ return { ...mine, annotations: out, updatedAt };
222
+ }
223
+ function sameMarks(a, b) {
224
+ if (a.annotations.length !== b.annotations.length) return false;
225
+ const byId = new Map(a.annotations.map((m) => [m.id, m.updatedAt]));
226
+ return b.annotations.every(
227
+ (m) => byId.get(m.id) === m.updatedAt && (m.kind !== "comment" || a.annotations.find((x) => x.id === m.id).replies.length === m.replies.length)
228
+ );
229
+ }
230
+
174
231
  // src/annotations/redaction-log.ts
175
232
  var REDACTION_LOG_COLUMNS = ["page", "reason", "status", "approved_by", "time"];
176
233
  var STATUS = {
@@ -291,14 +348,37 @@ var REDACTION_REASONS = [
291
348
  "Commercial",
292
349
  "Irrelevant"
293
350
  ];
351
+ function layerStatusText(controller) {
352
+ if (controller.status === "error") return "Could not be loaded";
353
+ if (controller.readOnly) return "View only";
354
+ if (controller.offline) {
355
+ return controller.dirty ? "Offline \u2014 will save when back online" : "Offline";
356
+ }
357
+ if (controller.error) return "Not saved \u2014 retrying";
358
+ if (controller.saving) return "Saving\u2026";
359
+ if (controller.dirty) return "Unsaved changes";
360
+ return "Saved";
361
+ }
294
362
  var AUTOSAVE_MS = 600;
363
+ var RETRY_MS = 1e4;
295
364
  var defaultNow = () => (/* @__PURE__ */ new Date()).toISOString();
296
365
  var defaultId = () => globalThis.crypto.randomUUID();
366
+ function rebaseHistory(history, sent, remote) {
367
+ const onto = (layer) => layer === sent ? remote : mergeLayers({ base: sent, mine: layer, theirs: remote });
368
+ return {
369
+ present: onto(history.present),
370
+ past: history.past.map(onto),
371
+ future: history.future.map(onto)
372
+ };
373
+ }
297
374
  function useAnnotationLayer({
298
375
  documentId,
299
376
  store,
300
377
  author,
301
378
  autosaveMs = AUTOSAVE_MS,
379
+ readOnly: readOnlyProp = false,
380
+ online = true,
381
+ pullMs = 0,
302
382
  now = defaultNow,
303
383
  makeId = defaultId
304
384
  }) {
@@ -309,12 +389,17 @@ function useAnnotationLayer({
309
389
  const [status, setStatus] = react.useState("loading");
310
390
  const [error, setError] = react.useState(null);
311
391
  const [saving, setSaving] = react.useState(false);
392
+ const [offlineFailure, setOfflineFailure] = react.useState(false);
393
+ const [storeReadOnly, setStoreReadOnly] = react.useState(false);
312
394
  const [tool, setToolState] = react.useState("select");
313
395
  const [settings, setSettingsState] = react.useState(DEFAULT_SETTINGS);
314
396
  const [selectedId, setSelectedId] = react.useState(null);
397
+ const readOnly = readOnlyProp || storeReadOnly;
315
398
  const historyRef = react.useRef(history);
316
399
  const savedRef = react.useRef(null);
317
400
  const timerRef = react.useRef(void 0);
401
+ const retryRef = react.useRef(void 0);
402
+ const savingRef = react.useRef(false);
318
403
  const docRef = react.useRef(documentId);
319
404
  const storeRef = react.useRef(store);
320
405
  storeRef.current = store;
@@ -322,10 +407,24 @@ function useAnnotationLayer({
322
407
  nowRef.current = now;
323
408
  const idRef = react.useRef(makeId);
324
409
  idRef.current = makeId;
410
+ const readOnlyRef = react.useRef(readOnly);
411
+ readOnlyRef.current = readOnly;
412
+ const onlineRef = react.useRef(online);
413
+ onlineRef.current = online;
414
+ const autosaveMsRef = react.useRef(autosaveMs);
415
+ autosaveMsRef.current = autosaveMs;
325
416
  const commit = react.useCallback((next) => {
326
417
  historyRef.current = next;
327
418
  setHistory(next);
328
419
  }, []);
420
+ const adoptRemote = react.useCallback(
421
+ (sent, remote) => {
422
+ commit(rebaseHistory(historyRef.current, sent, remote));
423
+ savedRef.current = remote;
424
+ setSavedLayer(remote);
425
+ },
426
+ [commit]
427
+ );
329
428
  react.useEffect(() => {
330
429
  docRef.current = documentId;
331
430
  let cancelled = false;
@@ -333,12 +432,14 @@ function useAnnotationLayer({
333
432
  setError(null);
334
433
  setSelectedId(null);
335
434
  setSavedLayer(null);
435
+ setStoreReadOnly(false);
336
436
  savedRef.current = null;
337
437
  commit(createHistory(chunkSSOPIPEX_cjs.emptyLayer(documentId, nowRef.current())));
338
438
  storeRef.current.load(documentId).then((layer) => {
339
439
  if (cancelled) return;
340
440
  savedRef.current = layer;
341
441
  setSavedLayer(layer);
442
+ setStoreReadOnly(storeRef.current.canEdit?.(documentId) === false);
342
443
  commit(createHistory(layer));
343
444
  setStatus("ready");
344
445
  }).catch((e) => {
@@ -349,37 +450,88 @@ function useAnnotationLayer({
349
450
  return () => {
350
451
  cancelled = true;
351
452
  clearTimeout(timerRef.current);
453
+ clearTimeout(retryRef.current);
352
454
  const layer = historyRef.current.present;
353
- if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId) {
455
+ if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId && !readOnlyRef.current) {
354
456
  storeRef.current.save(layer).catch((e) => console.error("Annotations could not be saved", e));
355
457
  }
356
458
  };
357
459
  }, [documentId, commit]);
358
460
  const save = react.useCallback(async () => {
359
461
  clearTimeout(timerRef.current);
462
+ clearTimeout(retryRef.current);
360
463
  const layer = historyRef.current.present;
361
- if (layer === savedRef.current) return;
464
+ if (layer === savedRef.current || savedRef.current === null) return;
465
+ if (readOnlyRef.current || savingRef.current) return;
466
+ if (!onlineRef.current) return;
467
+ savingRef.current = true;
362
468
  setSaving(true);
469
+ let failed = false;
363
470
  try {
364
- await storeRef.current.save(layer);
471
+ const stored = await storeRef.current.save(layer);
365
472
  if (layer.documentId === docRef.current) {
366
- savedRef.current = layer;
367
- setSavedLayer(layer);
368
473
  setError(null);
474
+ setOfflineFailure(false);
475
+ if (stored && stored !== layer) {
476
+ adoptRemote(layer, stored);
477
+ } else {
478
+ savedRef.current = layer;
479
+ setSavedLayer(layer);
480
+ }
369
481
  }
370
482
  } catch (e) {
371
- setError(e instanceof Error ? e.message : "The annotations could not be saved");
483
+ failed = true;
484
+ if (e instanceof AnnotationStoreOfflineError) {
485
+ setOfflineFailure(true);
486
+ } else {
487
+ setError(e instanceof Error ? e.message : "The annotations could not be saved");
488
+ }
489
+ retryRef.current = setTimeout(() => void saveRef.current(), RETRY_MS);
372
490
  } finally {
491
+ savingRef.current = false;
373
492
  setSaving(false);
493
+ if (!failed && historyRef.current.present !== savedRef.current) {
494
+ timerRef.current = setTimeout(() => void saveRef.current(), autosaveMsRef.current);
495
+ }
374
496
  }
375
- }, []);
497
+ }, [adoptRemote]);
498
+ const saveRef = react.useRef(save);
499
+ saveRef.current = save;
376
500
  const present = history.present;
377
501
  const dirty = status === "ready" && present !== savedLayer;
378
502
  react.useEffect(() => {
379
- if (!dirty) return;
503
+ if (!dirty || !online || readOnly) return;
380
504
  timerRef.current = setTimeout(() => void save(), autosaveMs);
381
505
  return () => clearTimeout(timerRef.current);
382
- }, [dirty, present, autosaveMs, save]);
506
+ }, [dirty, present, autosaveMs, save, online, readOnly]);
507
+ react.useEffect(() => {
508
+ if (online) setOfflineFailure(false);
509
+ if (online && savedRef.current !== null && historyRef.current.present !== savedRef.current) {
510
+ void save();
511
+ }
512
+ }, [online, save]);
513
+ const pull = react.useCallback(async () => {
514
+ const s = storeRef.current;
515
+ const base = savedRef.current;
516
+ if (!s.pull || !base || savingRef.current || !onlineRef.current) return;
517
+ if (historyRef.current.present !== base) return;
518
+ try {
519
+ const remote = await s.pull(docRef.current);
520
+ if (!remote || remote.documentId !== docRef.current || savedRef.current !== base) return;
521
+ adoptRemote(base, remote);
522
+ } catch {
523
+ }
524
+ }, [adoptRemote]);
525
+ react.useEffect(() => {
526
+ if (!pullMs || status !== "ready") return;
527
+ const timer = setInterval(() => void pull(), pullMs);
528
+ const onFocus = () => void pull();
529
+ window.addEventListener("focus", onFocus);
530
+ return () => {
531
+ clearInterval(timer);
532
+ window.removeEventListener("focus", onFocus);
533
+ };
534
+ }, [pullMs, status, pull]);
383
535
  react.useEffect(() => {
384
536
  const flush = () => void save();
385
537
  const onVisibility = () => {
@@ -394,6 +546,7 @@ function useAnnotationLayer({
394
546
  }, [save]);
395
547
  const dispatch = react.useCallback(
396
548
  (action) => {
549
+ if (readOnlyRef.current) return false;
397
550
  try {
398
551
  commit(applyAction(historyRef.current, action));
399
552
  setError(null);
@@ -412,6 +565,7 @@ function useAnnotationLayer({
412
565
  },
413
566
  [author]
414
567
  );
568
+ const offline = !online || offlineFailure;
415
569
  const controller = react.useMemo(() => {
416
570
  const exists = (id) => id !== null && present.annotations.some((a) => a.id === id) ? id : null;
417
571
  return {
@@ -420,9 +574,12 @@ function useAnnotationLayer({
420
574
  error,
421
575
  saving,
422
576
  dirty,
577
+ offline,
578
+ readOnly,
423
579
  author,
424
- tool,
580
+ tool: readOnly ? "select" : tool,
425
581
  setTool: (next) => {
582
+ if (readOnly && next !== "select") return;
426
583
  setToolState(next);
427
584
  if (next !== "select") setSelectedId(null);
428
585
  },
@@ -457,10 +614,14 @@ function useAnnotationLayer({
457
614
  });
458
615
  },
459
616
  resolve: (id, resolved) => void dispatch({ type: "resolve", id, resolved, now: nowRef.current() }),
460
- undo: () => commit(undo(historyRef.current)),
461
- redo: () => commit(redo(historyRef.current)),
462
- canUndo: canUndo(history),
463
- canRedo: canRedo(history),
617
+ undo: () => {
618
+ if (!readOnly) commit(undo(historyRef.current));
619
+ },
620
+ redo: () => {
621
+ if (!readOnly) commit(redo(historyRef.current));
622
+ },
623
+ canUndo: !readOnly && canUndo(history),
624
+ canRedo: !readOnly && canRedo(history),
464
625
  flush: save
465
626
  };
466
627
  }, [
@@ -470,6 +631,8 @@ function useAnnotationLayer({
470
631
  error,
471
632
  saving,
472
633
  dirty,
634
+ offline,
635
+ readOnly,
473
636
  author,
474
637
  tool,
475
638
  settings,
@@ -730,7 +893,8 @@ function AnnotationPageOverlay({
730
893
  const [openComment, setOpenComment] = react.useState(null);
731
894
  const marks = controller.layer.annotations.filter((a) => a.page === pageNumber);
732
895
  const hasText = useHasTextLayer(rootRef);
733
- const drawing = DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText;
896
+ const readOnly = controller.readOnly;
897
+ const drawing = !readOnly && (DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText);
734
898
  react.useEffect(() => {
735
899
  if (openComment && selectedId !== openComment) setOpenComment(null);
736
900
  }, [selectedId, openComment]);
@@ -827,7 +991,7 @@ function AnnotationPageOverlay({
827
991
  };
828
992
  const beginDrag = (e, a, mode) => {
829
993
  const origin = singleRect(a);
830
- if (!origin || e.button !== 0) return;
994
+ if (!origin || e.button !== 0 || readOnly) return;
831
995
  e.stopPropagation();
832
996
  e.currentTarget.setPointerCapture(e.pointerId);
833
997
  setDrag({
@@ -858,7 +1022,7 @@ function AnnotationPageOverlay({
858
1022
  if (drag.moved) controller.update(a.id, patchForRect(a, drag.rect));
859
1023
  setDrag(null);
860
1024
  };
861
- const interactive = (a) => tool === "select" || tool === "comment" && a.kind === "comment";
1025
+ const interactive = (a) => readOnly ? a.kind === "comment" : tool === "select" || tool === "comment" && a.kind === "comment";
862
1026
  const selected = marks.find((a) => a.id === selectedId);
863
1027
  return /* @__PURE__ */ jsxRuntime.jsxs(
864
1028
  "div",
@@ -906,7 +1070,7 @@ function AnnotationPageOverlay({
906
1070
  },
907
1071
  a.id
908
1072
  )),
909
- selected && tool === "select" && singleRect(selected) && /* @__PURE__ */ jsxRuntime.jsx(
1073
+ selected && tool === "select" && !readOnly && singleRect(selected) && /* @__PURE__ */ jsxRuntime.jsx(
910
1074
  Handles,
911
1075
  {
912
1076
  rect: drag?.id === selected.id ? drag.rect : singleRect(selected),
@@ -915,7 +1079,7 @@ function AnnotationPageOverlay({
915
1079
  onPointerUp: () => endDrag(selected)
916
1080
  }
917
1081
  ),
918
- selected && tool === "select" && /* @__PURE__ */ jsxRuntime.jsx(
1082
+ selected && tool === "select" && !readOnly && /* @__PURE__ */ jsxRuntime.jsx(
919
1083
  ActionBar,
920
1084
  {
921
1085
  annotation: selected,
@@ -1232,14 +1396,15 @@ function CommentPopover({
1232
1396
  }) {
1233
1397
  const [body, setBody] = react.useState(a.body);
1234
1398
  const [reply, setReply] = react.useState("");
1235
- const mine = a.author === controller.author;
1399
+ const readOnly = controller.readOnly;
1400
+ const mine = a.author === controller.author && !readOnly;
1236
1401
  react.useEffect(() => setBody(a.body), [a.body]);
1237
1402
  const commitBody = () => {
1238
1403
  if (mine && body !== a.body) controller.update(a.id, { body });
1239
1404
  };
1240
1405
  const close = () => {
1241
1406
  commitBody();
1242
- if (body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
1407
+ if (!readOnly && body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
1243
1408
  onClose();
1244
1409
  };
1245
1410
  const sendReply = () => {
@@ -1310,7 +1475,7 @@ function CommentPopover({
1310
1475
  ] }, r.id))
1311
1476
  }
1312
1477
  ),
1313
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex gap-1", children: [
1478
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex gap-1", children: [
1314
1479
  /* @__PURE__ */ jsxRuntime.jsx(
1315
1480
  "input",
1316
1481
  {
@@ -1339,7 +1504,7 @@ function CommentPopover({
1339
1504
  }
1340
1505
  )
1341
1506
  ] }),
1342
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex items-center justify-between", children: [
1507
+ readOnly ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-xs text-muted-foreground", "data-testid": "annotation-comment-status", children: a.resolved ? "Resolved" : "Open" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex items-center justify-between", children: [
1343
1508
  /* @__PURE__ */ jsxRuntime.jsx(
1344
1509
  "button",
1345
1510
  {
@@ -1426,14 +1591,20 @@ function Swatches({
1426
1591
  c
1427
1592
  )) });
1428
1593
  }
1429
- function AnnotationToolbar({ controller, onFreeze, className }) {
1594
+ function AnnotationToolbar({
1595
+ controller,
1596
+ onFreeze,
1597
+ actions,
1598
+ className
1599
+ }) {
1430
1600
  useTextSelectionMarks(controller);
1431
1601
  useAnnotationShortcuts(controller);
1432
1602
  const { tool, settings } = controller;
1433
1603
  const pending = pendingRedactions(controller.layer);
1434
1604
  const redactionCount = controller.layer.annotations.filter((a) => a.kind === "redaction").length;
1435
1605
  const colored = tool === "highlight" || tool === "box" || tool === "stamp";
1436
- const status = controller.error ? "Not saved" : controller.saving ? "Saving\u2026" : controller.dirty ? "Unsaved changes" : "Saved";
1606
+ const status = layerStatusText(controller);
1607
+ const editable = !controller.readOnly;
1437
1608
  return /* @__PURE__ */ jsxRuntime.jsxs(
1438
1609
  "div",
1439
1610
  {
@@ -1445,8 +1616,8 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1445
1616
  className
1446
1617
  ),
1447
1618
  children: [
1448
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Tool", children: TOOLS.map(({ tool: t, label, icon }) => /* @__PURE__ */ jsxRuntime.jsx(
1449
- chunkXDCRWZF2_cjs.Button,
1619
+ editable && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Tool", children: TOOLS.map(({ tool: t, label, icon }) => /* @__PURE__ */ jsxRuntime.jsx(
1620
+ chunkGXQO3IJC_cjs.Button,
1450
1621
  {
1451
1622
  type: "button",
1452
1623
  size: "icon",
@@ -1460,9 +1631,9 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1460
1631
  },
1461
1632
  t
1462
1633
  )) }),
1463
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "History", children: [
1634
+ editable && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "History", children: [
1464
1635
  /* @__PURE__ */ jsxRuntime.jsx(
1465
- chunkXDCRWZF2_cjs.Button,
1636
+ chunkGXQO3IJC_cjs.Button,
1466
1637
  {
1467
1638
  type: "button",
1468
1639
  size: "icon",
@@ -1476,7 +1647,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1476
1647
  }
1477
1648
  ),
1478
1649
  /* @__PURE__ */ jsxRuntime.jsx(
1479
- chunkXDCRWZF2_cjs.Button,
1650
+ chunkGXQO3IJC_cjs.Button,
1480
1651
  {
1481
1652
  type: "button",
1482
1653
  size: "icon",
@@ -1490,7 +1661,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1490
1661
  }
1491
1662
  )
1492
1663
  ] }),
1493
- colored && /* @__PURE__ */ jsxRuntime.jsx(
1664
+ editable && colored && /* @__PURE__ */ jsxRuntime.jsx(
1494
1665
  Swatches,
1495
1666
  {
1496
1667
  label: "Colour",
@@ -1499,7 +1670,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1499
1670
  onChange: (c) => controller.setSettings({ colors: { ...settings.colors, [tool]: c } })
1500
1671
  }
1501
1672
  ),
1502
- tool === "stamp" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1673
+ editable && tool === "stamp" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1503
1674
  /* @__PURE__ */ jsxRuntime.jsx(
1504
1675
  "input",
1505
1676
  {
@@ -1514,7 +1685,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1514
1685
  ),
1515
1686
  /* @__PURE__ */ jsxRuntime.jsx("datalist", { id: "annotation-stamp-presets", children: STAMP_PRESETS.map((s) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: s }, s)) })
1516
1687
  ] }),
1517
- (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1688
+ editable && (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1518
1689
  /* @__PURE__ */ jsxRuntime.jsx(
1519
1690
  "input",
1520
1691
  {
@@ -1534,36 +1705,38 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1534
1705
  pending.length,
1535
1706
  " pending"
1536
1707
  ] }),
1537
- /* @__PURE__ */ jsxRuntime.jsx(
1538
- chunkXDCRWZF2_cjs.Button,
1539
- {
1540
- type: "button",
1541
- size: "sm",
1542
- variant: "outline",
1543
- disabled: pending.length === 0,
1544
- "data-testid": "annotation-approve-all",
1545
- onClick: () => controller.setRedactionStatus(
1546
- pending.map((a) => a.id),
1547
- "approved"
1548
- ),
1549
- children: "Approve all"
1550
- }
1551
- ),
1552
- /* @__PURE__ */ jsxRuntime.jsx(
1553
- chunkXDCRWZF2_cjs.Button,
1554
- {
1555
- type: "button",
1556
- size: "sm",
1557
- variant: "outline",
1558
- disabled: pending.length === 0,
1559
- "data-testid": "annotation-reject-all",
1560
- onClick: () => controller.setRedactionStatus(
1561
- pending.map((a) => a.id),
1562
- "rejected"
1563
- ),
1564
- children: "Reject all"
1565
- }
1566
- )
1708
+ editable && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1709
+ /* @__PURE__ */ jsxRuntime.jsx(
1710
+ chunkGXQO3IJC_cjs.Button,
1711
+ {
1712
+ type: "button",
1713
+ size: "sm",
1714
+ variant: "outline",
1715
+ disabled: pending.length === 0,
1716
+ "data-testid": "annotation-approve-all",
1717
+ onClick: () => controller.setRedactionStatus(
1718
+ pending.map((a) => a.id),
1719
+ "approved"
1720
+ ),
1721
+ children: "Approve all"
1722
+ }
1723
+ ),
1724
+ /* @__PURE__ */ jsxRuntime.jsx(
1725
+ chunkGXQO3IJC_cjs.Button,
1726
+ {
1727
+ type: "button",
1728
+ size: "sm",
1729
+ variant: "outline",
1730
+ disabled: pending.length === 0,
1731
+ "data-testid": "annotation-reject-all",
1732
+ onClick: () => controller.setRedactionStatus(
1733
+ pending.map((a) => a.id),
1734
+ "rejected"
1735
+ ),
1736
+ children: "Reject all"
1737
+ }
1738
+ )
1739
+ ] })
1567
1740
  ] }),
1568
1741
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-auto flex items-center gap-3 text-xs text-muted-foreground", children: [
1569
1742
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1571,12 +1744,14 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1571
1744
  {
1572
1745
  "data-testid": "annotation-status",
1573
1746
  role: "status",
1574
- className: chunkS6A6FSG7_cjs.cn(controller.error && "text-destructive"),
1747
+ "data-state": controller.readOnly ? "readonly" : controller.offline ? "offline" : controller.error ? "error" : controller.saving ? "saving" : controller.dirty ? "dirty" : "saved",
1748
+ className: chunkS6A6FSG7_cjs.cn(controller.error && !controller.offline && "text-destructive"),
1575
1749
  title: controller.error ?? void 0,
1576
1750
  children: status
1577
1751
  }
1578
1752
  ),
1579
- onFreeze && /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.Button, { type: "button", size: "sm", "data-testid": "annotation-freeze", onClick: onFreeze, children: [
1753
+ actions,
1754
+ onFreeze && /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.Button, { type: "button", size: "sm", "data-testid": "annotation-freeze", onClick: onFreeze, children: [
1580
1755
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Snowflake, { size: 14 }),
1581
1756
  "Freeze copy"
1582
1757
  ] })
@@ -1618,10 +1793,10 @@ function FreezeDialog({
1618
1793
  marks.filter((a) => a.kind === k && (k !== "redaction" || chunkSSOPIPEX_cjs.isEffectiveRedaction(a))).length
1619
1794
  ]
1620
1795
  ).filter(([, n]) => n > 0);
1621
- return /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.Dialog, { open, onOpenChange: (next) => !busy && onOpenChange(next), children: /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogContent, { "data-testid": "freeze-dialog", children: [
1622
- /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogHeader, { children: [
1623
- /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.DialogTitle, { children: "Freeze a copy" }),
1624
- /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.DialogDescription, { children: "Saves a separate document with your annotations built in, next to the original. The original stays as it is." })
1796
+ return /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.Dialog, { open, onOpenChange: (next) => !busy && onOpenChange(next), children: /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogContent, { "data-testid": "freeze-dialog", children: [
1797
+ /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogHeader, { children: [
1798
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.DialogTitle, { children: "Freeze a copy" }),
1799
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.DialogDescription, { children: "Saves a separate document with your annotations built in, next to the original. The original stays as it is." })
1625
1800
  ] }),
1626
1801
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", "data-testid": "freeze-summary", children: counts.length === 0 ? "No annotations yet." : counts.map(([k, n]) => `${n} ${KIND_LABELS[k]}`).join(", ") }),
1627
1802
  /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "space-y-2 text-sm", disabled: busy, children: [
@@ -1730,9 +1905,9 @@ function FreezeDialog({
1730
1905
  "\u2026"
1731
1906
  ] }),
1732
1907
  error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", role: "alert", "data-testid": "freeze-error", children: error }),
1733
- /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogFooter, { children: [
1908
+ /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogFooter, { children: [
1734
1909
  /* @__PURE__ */ jsxRuntime.jsx(
1735
- chunkXDCRWZF2_cjs.Button,
1910
+ chunkGXQO3IJC_cjs.Button,
1736
1911
  {
1737
1912
  type: "button",
1738
1913
  variant: "outline",
@@ -1742,7 +1917,7 @@ function FreezeDialog({
1742
1917
  }
1743
1918
  ),
1744
1919
  /* @__PURE__ */ jsxRuntime.jsx(
1745
- chunkXDCRWZF2_cjs.Button,
1920
+ chunkGXQO3IJC_cjs.Button,
1746
1921
  {
1747
1922
  type: "button",
1748
1923
  "data-testid": "freeze-confirm",
@@ -1817,10 +1992,10 @@ function ProductionDialog({
1817
1992
  setDragFrom(null);
1818
1993
  };
1819
1994
  const valid = Number.isInteger(start) && start >= 0 && Number.isInteger(digits) && digits >= 1 && digits <= 12;
1820
- return /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.Dialog, { open, onOpenChange: (next) => !busy && onOpenChange(next), children: /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogContent, { "data-testid": "production-dialog", className: "max-h-[90dvh] overflow-y-auto", children: [
1821
- /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogHeader, { children: [
1822
- /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.DialogTitle, { children: "Production set" }),
1823
- /* @__PURE__ */ jsxRuntime.jsx(chunkXDCRWZF2_cjs.DialogDescription, { children: "Numbers every page with a Bates label, in the order shown. The originals are never changed; the result is downloaded and, if you choose, saved to the workspace." })
1995
+ return /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.Dialog, { open, onOpenChange: (next) => !busy && onOpenChange(next), children: /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogContent, { "data-testid": "production-dialog", className: "max-h-[90dvh] overflow-y-auto", children: [
1996
+ /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogHeader, { children: [
1997
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.DialogTitle, { children: "Production set" }),
1998
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGXQO3IJC_cjs.DialogDescription, { children: "Numbers every page with a Bates label, in the order shown. The originals are never changed; the result is downloaded and, if you choose, saved to the workspace." })
1824
1999
  ] }),
1825
2000
  /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", "data-testid": "production-summary", children: [
1826
2001
  documents.length,
@@ -1861,7 +2036,7 @@ function ProductionDialog({
1861
2036
  ] }),
1862
2037
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 flex-1 truncate", title: doc.name, children: doc.name }),
1863
2038
  /* @__PURE__ */ jsxRuntime.jsx(
1864
- chunkXDCRWZF2_cjs.Button,
2039
+ chunkGXQO3IJC_cjs.Button,
1865
2040
  {
1866
2041
  type: "button",
1867
2042
  variant: "ghost",
@@ -1875,7 +2050,7 @@ function ProductionDialog({
1875
2050
  }
1876
2051
  ),
1877
2052
  /* @__PURE__ */ jsxRuntime.jsx(
1878
- chunkXDCRWZF2_cjs.Button,
2053
+ chunkGXQO3IJC_cjs.Button,
1879
2054
  {
1880
2055
  type: "button",
1881
2056
  variant: "ghost",
@@ -2060,9 +2235,9 @@ function ProductionDialog({
2060
2235
  "\u2026"
2061
2236
  ] }),
2062
2237
  error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", role: "alert", "data-testid": "production-error", children: error }),
2063
- /* @__PURE__ */ jsxRuntime.jsxs(chunkXDCRWZF2_cjs.DialogFooter, { children: [
2238
+ /* @__PURE__ */ jsxRuntime.jsxs(chunkGXQO3IJC_cjs.DialogFooter, { children: [
2064
2239
  /* @__PURE__ */ jsxRuntime.jsx(
2065
- chunkXDCRWZF2_cjs.Button,
2240
+ chunkGXQO3IJC_cjs.Button,
2066
2241
  {
2067
2242
  type: "button",
2068
2243
  variant: "outline",
@@ -2072,7 +2247,7 @@ function ProductionDialog({
2072
2247
  }
2073
2248
  ),
2074
2249
  /* @__PURE__ */ jsxRuntime.jsx(
2075
- chunkXDCRWZF2_cjs.Button,
2250
+ chunkGXQO3IJC_cjs.Button,
2076
2251
  {
2077
2252
  type: "button",
2078
2253
  "data-testid": "production-confirm",
@@ -2127,7 +2302,9 @@ Object.defineProperty(exports, "parseLayer", {
2127
2302
  enumerable: true,
2128
2303
  get: function () { return chunkSSOPIPEX_cjs.parseLayer; }
2129
2304
  });
2305
+ exports.AUTOSAVE_MS = AUTOSAVE_MS;
2130
2306
  exports.AnnotationPageOverlay = AnnotationPageOverlay;
2307
+ exports.AnnotationStoreOfflineError = AnnotationStoreOfflineError;
2131
2308
  exports.AnnotationToolbar = AnnotationToolbar;
2132
2309
  exports.DEFAULT_SETTINGS = DEFAULT_SETTINGS;
2133
2310
  exports.FreezeDialog = FreezeDialog;
@@ -2136,6 +2313,7 @@ exports.MARK_COLORS = MARK_COLORS;
2136
2313
  exports.ProductionDialog = ProductionDialog;
2137
2314
  exports.REDACTION_LOG_COLUMNS = REDACTION_LOG_COLUMNS;
2138
2315
  exports.REDACTION_REASONS = REDACTION_REASONS;
2316
+ exports.RETRY_MS = RETRY_MS;
2139
2317
  exports.STAMP_PRESETS = STAMP_PRESETS;
2140
2318
  exports.annotationsOnPage = annotationsOnPage;
2141
2319
  exports.applyAction = applyAction;
@@ -2149,6 +2327,8 @@ exports.dragRect = dragRect;
2149
2327
  exports.dragToNorm = dragToNorm;
2150
2328
  exports.intersects = intersects;
2151
2329
  exports.isTooSmall = isTooSmall;
2330
+ exports.layerStatusText = layerStatusText;
2331
+ exports.mergeLayers = mergeLayers;
2152
2332
  exports.mergeLineRects = mergeLineRects;
2153
2333
  exports.moveItem = moveItem;
2154
2334
  exports.patchForRect = patchForRect;
@@ -2159,6 +2339,7 @@ exports.redactionLogCsv = redactionLogCsv;
2159
2339
  exports.redactionLogRows = redactionLogRows;
2160
2340
  exports.redo = redo;
2161
2341
  exports.reduceLayer = reduceLayer;
2342
+ exports.sameMarks = sameMarks;
2162
2343
  exports.selectionToPageMarks = selectionToPageMarks;
2163
2344
  exports.singleRect = singleRect;
2164
2345
  exports.toNorm = toNorm;