@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,4 +1,5 @@
1
- import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../chunk-QS3Q5542.js';
1
+ import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../chunk-2VW47ADK.js';
2
+ import '../chunk-QICALPFQ.js';
2
3
  import { cn } from '../chunk-SN5YV6FF.js';
3
4
  import { parseAnnotation, parseLayer, emptyLayer, clampRect, isEffectiveRedaction } from '../chunk-COWZGCL5.js';
4
5
  export { AnnotationLayerError, LAYER_SCHEMA_VERSION, annotationRects, clampRect, emptyLayer, isEffectiveRedaction, parseAnnotation, parseLayer } from '../chunk-COWZGCL5.js';
@@ -133,6 +134,12 @@ function pendingRedactions(layer) {
133
134
  }
134
135
 
135
136
  // src/annotations/store.ts
137
+ var AnnotationStoreOfflineError = class extends Error {
138
+ constructor(message = "You are offline") {
139
+ super(message);
140
+ this.name = "AnnotationStoreOfflineError";
141
+ }
142
+ };
136
143
  function createMemoryStore(now = () => (/* @__PURE__ */ new Date()).toISOString()) {
137
144
  const layers = /* @__PURE__ */ new Map();
138
145
  return {
@@ -170,6 +177,56 @@ function safeLocalStorage() {
170
177
  }
171
178
  }
172
179
 
180
+ // src/annotations/merge.ts
181
+ var time = (iso) => {
182
+ const t = Date.parse(iso);
183
+ return Number.isNaN(t) ? 0 : t;
184
+ };
185
+ function mergeReplies(a, b) {
186
+ const byId = /* @__PURE__ */ new Map();
187
+ for (const r of [...a, ...b]) if (!byId.has(r.id)) byId.set(r.id, r);
188
+ return [...byId.values()].sort((x, y) => time(x.createdAt) - time(y.createdAt));
189
+ }
190
+ function newer(mine, theirs) {
191
+ const winner = time(theirs.updatedAt) > time(mine.updatedAt) ? theirs : mine;
192
+ if (mine.kind === "comment" && theirs.kind === "comment" && winner.kind === "comment") {
193
+ const replies = mergeReplies(mine.replies, theirs.replies);
194
+ if (replies.length !== winner.replies.length) return { ...winner, replies };
195
+ }
196
+ return winner;
197
+ }
198
+ function mergeLayers({ base, mine, theirs, deleted }) {
199
+ const baseById = new Map((base?.annotations ?? []).map((a) => [a.id, a]));
200
+ const theirsById = new Map(theirs.annotations.map((a) => [a.id, a]));
201
+ const mineIds = new Set(mine.annotations.map((a) => a.id));
202
+ const out = [];
203
+ for (const m of mine.annotations) {
204
+ if (deleted?.has(m.id)) continue;
205
+ const t = theirsById.get(m.id);
206
+ if (t) {
207
+ out.push(newer(m, t));
208
+ continue;
209
+ }
210
+ const b = baseById.get(m.id);
211
+ if (b && time(m.updatedAt) <= time(b.updatedAt)) continue;
212
+ out.push(m);
213
+ }
214
+ for (const t of theirs.annotations) {
215
+ if (mineIds.has(t.id) || deleted?.has(t.id)) continue;
216
+ if (baseById.has(t.id)) continue;
217
+ out.push(t);
218
+ }
219
+ const updatedAt = time(theirs.updatedAt) > time(mine.updatedAt) ? theirs.updatedAt : mine.updatedAt;
220
+ return { ...mine, annotations: out, updatedAt };
221
+ }
222
+ function sameMarks(a, b) {
223
+ if (a.annotations.length !== b.annotations.length) return false;
224
+ const byId = new Map(a.annotations.map((m) => [m.id, m.updatedAt]));
225
+ return b.annotations.every(
226
+ (m) => byId.get(m.id) === m.updatedAt && (m.kind !== "comment" || a.annotations.find((x) => x.id === m.id).replies.length === m.replies.length)
227
+ );
228
+ }
229
+
173
230
  // src/annotations/redaction-log.ts
174
231
  var REDACTION_LOG_COLUMNS = ["page", "reason", "status", "approved_by", "time"];
175
232
  var STATUS = {
@@ -290,14 +347,37 @@ var REDACTION_REASONS = [
290
347
  "Commercial",
291
348
  "Irrelevant"
292
349
  ];
350
+ function layerStatusText(controller) {
351
+ if (controller.status === "error") return "Could not be loaded";
352
+ if (controller.readOnly) return "View only";
353
+ if (controller.offline) {
354
+ return controller.dirty ? "Offline \u2014 will save when back online" : "Offline";
355
+ }
356
+ if (controller.error) return "Not saved \u2014 retrying";
357
+ if (controller.saving) return "Saving\u2026";
358
+ if (controller.dirty) return "Unsaved changes";
359
+ return "Saved";
360
+ }
293
361
  var AUTOSAVE_MS = 600;
362
+ var RETRY_MS = 1e4;
294
363
  var defaultNow = () => (/* @__PURE__ */ new Date()).toISOString();
295
364
  var defaultId = () => globalThis.crypto.randomUUID();
365
+ function rebaseHistory(history, sent, remote) {
366
+ const onto = (layer) => layer === sent ? remote : mergeLayers({ base: sent, mine: layer, theirs: remote });
367
+ return {
368
+ present: onto(history.present),
369
+ past: history.past.map(onto),
370
+ future: history.future.map(onto)
371
+ };
372
+ }
296
373
  function useAnnotationLayer({
297
374
  documentId,
298
375
  store,
299
376
  author,
300
377
  autosaveMs = AUTOSAVE_MS,
378
+ readOnly: readOnlyProp = false,
379
+ online = true,
380
+ pullMs = 0,
301
381
  now = defaultNow,
302
382
  makeId = defaultId
303
383
  }) {
@@ -308,12 +388,17 @@ function useAnnotationLayer({
308
388
  const [status, setStatus] = useState("loading");
309
389
  const [error, setError] = useState(null);
310
390
  const [saving, setSaving] = useState(false);
391
+ const [offlineFailure, setOfflineFailure] = useState(false);
392
+ const [storeReadOnly, setStoreReadOnly] = useState(false);
311
393
  const [tool, setToolState] = useState("select");
312
394
  const [settings, setSettingsState] = useState(DEFAULT_SETTINGS);
313
395
  const [selectedId, setSelectedId] = useState(null);
396
+ const readOnly = readOnlyProp || storeReadOnly;
314
397
  const historyRef = useRef(history);
315
398
  const savedRef = useRef(null);
316
399
  const timerRef = useRef(void 0);
400
+ const retryRef = useRef(void 0);
401
+ const savingRef = useRef(false);
317
402
  const docRef = useRef(documentId);
318
403
  const storeRef = useRef(store);
319
404
  storeRef.current = store;
@@ -321,10 +406,24 @@ function useAnnotationLayer({
321
406
  nowRef.current = now;
322
407
  const idRef = useRef(makeId);
323
408
  idRef.current = makeId;
409
+ const readOnlyRef = useRef(readOnly);
410
+ readOnlyRef.current = readOnly;
411
+ const onlineRef = useRef(online);
412
+ onlineRef.current = online;
413
+ const autosaveMsRef = useRef(autosaveMs);
414
+ autosaveMsRef.current = autosaveMs;
324
415
  const commit = useCallback((next) => {
325
416
  historyRef.current = next;
326
417
  setHistory(next);
327
418
  }, []);
419
+ const adoptRemote = useCallback(
420
+ (sent, remote) => {
421
+ commit(rebaseHistory(historyRef.current, sent, remote));
422
+ savedRef.current = remote;
423
+ setSavedLayer(remote);
424
+ },
425
+ [commit]
426
+ );
328
427
  useEffect(() => {
329
428
  docRef.current = documentId;
330
429
  let cancelled = false;
@@ -332,12 +431,14 @@ function useAnnotationLayer({
332
431
  setError(null);
333
432
  setSelectedId(null);
334
433
  setSavedLayer(null);
434
+ setStoreReadOnly(false);
335
435
  savedRef.current = null;
336
436
  commit(createHistory(emptyLayer(documentId, nowRef.current())));
337
437
  storeRef.current.load(documentId).then((layer) => {
338
438
  if (cancelled) return;
339
439
  savedRef.current = layer;
340
440
  setSavedLayer(layer);
441
+ setStoreReadOnly(storeRef.current.canEdit?.(documentId) === false);
341
442
  commit(createHistory(layer));
342
443
  setStatus("ready");
343
444
  }).catch((e) => {
@@ -348,37 +449,88 @@ function useAnnotationLayer({
348
449
  return () => {
349
450
  cancelled = true;
350
451
  clearTimeout(timerRef.current);
452
+ clearTimeout(retryRef.current);
351
453
  const layer = historyRef.current.present;
352
- if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId) {
454
+ if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId && !readOnlyRef.current) {
353
455
  storeRef.current.save(layer).catch((e) => console.error("Annotations could not be saved", e));
354
456
  }
355
457
  };
356
458
  }, [documentId, commit]);
357
459
  const save = useCallback(async () => {
358
460
  clearTimeout(timerRef.current);
461
+ clearTimeout(retryRef.current);
359
462
  const layer = historyRef.current.present;
360
- if (layer === savedRef.current) return;
463
+ if (layer === savedRef.current || savedRef.current === null) return;
464
+ if (readOnlyRef.current || savingRef.current) return;
465
+ if (!onlineRef.current) return;
466
+ savingRef.current = true;
361
467
  setSaving(true);
468
+ let failed = false;
362
469
  try {
363
- await storeRef.current.save(layer);
470
+ const stored = await storeRef.current.save(layer);
364
471
  if (layer.documentId === docRef.current) {
365
- savedRef.current = layer;
366
- setSavedLayer(layer);
367
472
  setError(null);
473
+ setOfflineFailure(false);
474
+ if (stored && stored !== layer) {
475
+ adoptRemote(layer, stored);
476
+ } else {
477
+ savedRef.current = layer;
478
+ setSavedLayer(layer);
479
+ }
368
480
  }
369
481
  } catch (e) {
370
- setError(e instanceof Error ? e.message : "The annotations could not be saved");
482
+ failed = true;
483
+ if (e instanceof AnnotationStoreOfflineError) {
484
+ setOfflineFailure(true);
485
+ } else {
486
+ setError(e instanceof Error ? e.message : "The annotations could not be saved");
487
+ }
488
+ retryRef.current = setTimeout(() => void saveRef.current(), RETRY_MS);
371
489
  } finally {
490
+ savingRef.current = false;
372
491
  setSaving(false);
492
+ if (!failed && historyRef.current.present !== savedRef.current) {
493
+ timerRef.current = setTimeout(() => void saveRef.current(), autosaveMsRef.current);
494
+ }
373
495
  }
374
- }, []);
496
+ }, [adoptRemote]);
497
+ const saveRef = useRef(save);
498
+ saveRef.current = save;
375
499
  const present = history.present;
376
500
  const dirty = status === "ready" && present !== savedLayer;
377
501
  useEffect(() => {
378
- if (!dirty) return;
502
+ if (!dirty || !online || readOnly) return;
379
503
  timerRef.current = setTimeout(() => void save(), autosaveMs);
380
504
  return () => clearTimeout(timerRef.current);
381
- }, [dirty, present, autosaveMs, save]);
505
+ }, [dirty, present, autosaveMs, save, online, readOnly]);
506
+ useEffect(() => {
507
+ if (online) setOfflineFailure(false);
508
+ if (online && savedRef.current !== null && historyRef.current.present !== savedRef.current) {
509
+ void save();
510
+ }
511
+ }, [online, save]);
512
+ const pull = useCallback(async () => {
513
+ const s = storeRef.current;
514
+ const base = savedRef.current;
515
+ if (!s.pull || !base || savingRef.current || !onlineRef.current) return;
516
+ if (historyRef.current.present !== base) return;
517
+ try {
518
+ const remote = await s.pull(docRef.current);
519
+ if (!remote || remote.documentId !== docRef.current || savedRef.current !== base) return;
520
+ adoptRemote(base, remote);
521
+ } catch {
522
+ }
523
+ }, [adoptRemote]);
524
+ useEffect(() => {
525
+ if (!pullMs || status !== "ready") return;
526
+ const timer = setInterval(() => void pull(), pullMs);
527
+ const onFocus = () => void pull();
528
+ window.addEventListener("focus", onFocus);
529
+ return () => {
530
+ clearInterval(timer);
531
+ window.removeEventListener("focus", onFocus);
532
+ };
533
+ }, [pullMs, status, pull]);
382
534
  useEffect(() => {
383
535
  const flush = () => void save();
384
536
  const onVisibility = () => {
@@ -393,6 +545,7 @@ function useAnnotationLayer({
393
545
  }, [save]);
394
546
  const dispatch = useCallback(
395
547
  (action) => {
548
+ if (readOnlyRef.current) return false;
396
549
  try {
397
550
  commit(applyAction(historyRef.current, action));
398
551
  setError(null);
@@ -411,6 +564,7 @@ function useAnnotationLayer({
411
564
  },
412
565
  [author]
413
566
  );
567
+ const offline = !online || offlineFailure;
414
568
  const controller = useMemo(() => {
415
569
  const exists = (id) => id !== null && present.annotations.some((a) => a.id === id) ? id : null;
416
570
  return {
@@ -419,9 +573,12 @@ function useAnnotationLayer({
419
573
  error,
420
574
  saving,
421
575
  dirty,
576
+ offline,
577
+ readOnly,
422
578
  author,
423
- tool,
579
+ tool: readOnly ? "select" : tool,
424
580
  setTool: (next) => {
581
+ if (readOnly && next !== "select") return;
425
582
  setToolState(next);
426
583
  if (next !== "select") setSelectedId(null);
427
584
  },
@@ -456,10 +613,14 @@ function useAnnotationLayer({
456
613
  });
457
614
  },
458
615
  resolve: (id, resolved) => void dispatch({ type: "resolve", id, resolved, now: nowRef.current() }),
459
- undo: () => commit(undo(historyRef.current)),
460
- redo: () => commit(redo(historyRef.current)),
461
- canUndo: canUndo(history),
462
- canRedo: canRedo(history),
616
+ undo: () => {
617
+ if (!readOnly) commit(undo(historyRef.current));
618
+ },
619
+ redo: () => {
620
+ if (!readOnly) commit(redo(historyRef.current));
621
+ },
622
+ canUndo: !readOnly && canUndo(history),
623
+ canRedo: !readOnly && canRedo(history),
463
624
  flush: save
464
625
  };
465
626
  }, [
@@ -469,6 +630,8 @@ function useAnnotationLayer({
469
630
  error,
470
631
  saving,
471
632
  dirty,
633
+ offline,
634
+ readOnly,
472
635
  author,
473
636
  tool,
474
637
  settings,
@@ -729,7 +892,8 @@ function AnnotationPageOverlay({
729
892
  const [openComment, setOpenComment] = useState(null);
730
893
  const marks = controller.layer.annotations.filter((a) => a.page === pageNumber);
731
894
  const hasText = useHasTextLayer(rootRef);
732
- const drawing = DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText;
895
+ const readOnly = controller.readOnly;
896
+ const drawing = !readOnly && (DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText);
733
897
  useEffect(() => {
734
898
  if (openComment && selectedId !== openComment) setOpenComment(null);
735
899
  }, [selectedId, openComment]);
@@ -826,7 +990,7 @@ function AnnotationPageOverlay({
826
990
  };
827
991
  const beginDrag = (e, a, mode) => {
828
992
  const origin = singleRect(a);
829
- if (!origin || e.button !== 0) return;
993
+ if (!origin || e.button !== 0 || readOnly) return;
830
994
  e.stopPropagation();
831
995
  e.currentTarget.setPointerCapture(e.pointerId);
832
996
  setDrag({
@@ -857,7 +1021,7 @@ function AnnotationPageOverlay({
857
1021
  if (drag.moved) controller.update(a.id, patchForRect(a, drag.rect));
858
1022
  setDrag(null);
859
1023
  };
860
- const interactive = (a) => tool === "select" || tool === "comment" && a.kind === "comment";
1024
+ const interactive = (a) => readOnly ? a.kind === "comment" : tool === "select" || tool === "comment" && a.kind === "comment";
861
1025
  const selected = marks.find((a) => a.id === selectedId);
862
1026
  return /* @__PURE__ */ jsxs(
863
1027
  "div",
@@ -905,7 +1069,7 @@ function AnnotationPageOverlay({
905
1069
  },
906
1070
  a.id
907
1071
  )),
908
- selected && tool === "select" && singleRect(selected) && /* @__PURE__ */ jsx(
1072
+ selected && tool === "select" && !readOnly && singleRect(selected) && /* @__PURE__ */ jsx(
909
1073
  Handles,
910
1074
  {
911
1075
  rect: drag?.id === selected.id ? drag.rect : singleRect(selected),
@@ -914,7 +1078,7 @@ function AnnotationPageOverlay({
914
1078
  onPointerUp: () => endDrag(selected)
915
1079
  }
916
1080
  ),
917
- selected && tool === "select" && /* @__PURE__ */ jsx(
1081
+ selected && tool === "select" && !readOnly && /* @__PURE__ */ jsx(
918
1082
  ActionBar,
919
1083
  {
920
1084
  annotation: selected,
@@ -1231,14 +1395,15 @@ function CommentPopover({
1231
1395
  }) {
1232
1396
  const [body, setBody] = useState(a.body);
1233
1397
  const [reply, setReply] = useState("");
1234
- const mine = a.author === controller.author;
1398
+ const readOnly = controller.readOnly;
1399
+ const mine = a.author === controller.author && !readOnly;
1235
1400
  useEffect(() => setBody(a.body), [a.body]);
1236
1401
  const commitBody = () => {
1237
1402
  if (mine && body !== a.body) controller.update(a.id, { body });
1238
1403
  };
1239
1404
  const close = () => {
1240
1405
  commitBody();
1241
- if (body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
1406
+ if (!readOnly && body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
1242
1407
  onClose();
1243
1408
  };
1244
1409
  const sendReply = () => {
@@ -1309,7 +1474,7 @@ function CommentPopover({
1309
1474
  ] }, r.id))
1310
1475
  }
1311
1476
  ),
1312
- /* @__PURE__ */ jsxs("div", { className: "mt-2 flex gap-1", children: [
1477
+ !readOnly && /* @__PURE__ */ jsxs("div", { className: "mt-2 flex gap-1", children: [
1313
1478
  /* @__PURE__ */ jsx(
1314
1479
  "input",
1315
1480
  {
@@ -1338,7 +1503,7 @@ function CommentPopover({
1338
1503
  }
1339
1504
  )
1340
1505
  ] }),
1341
- /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-between", children: [
1506
+ readOnly ? /* @__PURE__ */ jsx("div", { className: "mt-2 text-xs text-muted-foreground", "data-testid": "annotation-comment-status", children: a.resolved ? "Resolved" : "Open" }) : /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-between", children: [
1342
1507
  /* @__PURE__ */ jsx(
1343
1508
  "button",
1344
1509
  {
@@ -1425,14 +1590,20 @@ function Swatches({
1425
1590
  c
1426
1591
  )) });
1427
1592
  }
1428
- function AnnotationToolbar({ controller, onFreeze, className }) {
1593
+ function AnnotationToolbar({
1594
+ controller,
1595
+ onFreeze,
1596
+ actions,
1597
+ className
1598
+ }) {
1429
1599
  useTextSelectionMarks(controller);
1430
1600
  useAnnotationShortcuts(controller);
1431
1601
  const { tool, settings } = controller;
1432
1602
  const pending = pendingRedactions(controller.layer);
1433
1603
  const redactionCount = controller.layer.annotations.filter((a) => a.kind === "redaction").length;
1434
1604
  const colored = tool === "highlight" || tool === "box" || tool === "stamp";
1435
- const status = controller.error ? "Not saved" : controller.saving ? "Saving\u2026" : controller.dirty ? "Unsaved changes" : "Saved";
1605
+ const status = layerStatusText(controller);
1606
+ const editable = !controller.readOnly;
1436
1607
  return /* @__PURE__ */ jsxs(
1437
1608
  "div",
1438
1609
  {
@@ -1444,7 +1615,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1444
1615
  className
1445
1616
  ),
1446
1617
  children: [
1447
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Tool", children: TOOLS.map(({ tool: t, label, icon }) => /* @__PURE__ */ jsx(
1618
+ editable && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Tool", children: TOOLS.map(({ tool: t, label, icon }) => /* @__PURE__ */ jsx(
1448
1619
  Button,
1449
1620
  {
1450
1621
  type: "button",
@@ -1459,7 +1630,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1459
1630
  },
1460
1631
  t
1461
1632
  )) }),
1462
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "History", children: [
1633
+ editable && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "History", children: [
1463
1634
  /* @__PURE__ */ jsx(
1464
1635
  Button,
1465
1636
  {
@@ -1489,7 +1660,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1489
1660
  }
1490
1661
  )
1491
1662
  ] }),
1492
- colored && /* @__PURE__ */ jsx(
1663
+ editable && colored && /* @__PURE__ */ jsx(
1493
1664
  Swatches,
1494
1665
  {
1495
1666
  label: "Colour",
@@ -1498,7 +1669,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1498
1669
  onChange: (c) => controller.setSettings({ colors: { ...settings.colors, [tool]: c } })
1499
1670
  }
1500
1671
  ),
1501
- tool === "stamp" && /* @__PURE__ */ jsxs(Fragment, { children: [
1672
+ editable && tool === "stamp" && /* @__PURE__ */ jsxs(Fragment, { children: [
1502
1673
  /* @__PURE__ */ jsx(
1503
1674
  "input",
1504
1675
  {
@@ -1513,7 +1684,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1513
1684
  ),
1514
1685
  /* @__PURE__ */ jsx("datalist", { id: "annotation-stamp-presets", children: STAMP_PRESETS.map((s) => /* @__PURE__ */ jsx("option", { value: s }, s)) })
1515
1686
  ] }),
1516
- (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxs(Fragment, { children: [
1687
+ editable && (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxs(Fragment, { children: [
1517
1688
  /* @__PURE__ */ jsx(
1518
1689
  "input",
1519
1690
  {
@@ -1533,36 +1704,38 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1533
1704
  pending.length,
1534
1705
  " pending"
1535
1706
  ] }),
1536
- /* @__PURE__ */ jsx(
1537
- Button,
1538
- {
1539
- type: "button",
1540
- size: "sm",
1541
- variant: "outline",
1542
- disabled: pending.length === 0,
1543
- "data-testid": "annotation-approve-all",
1544
- onClick: () => controller.setRedactionStatus(
1545
- pending.map((a) => a.id),
1546
- "approved"
1547
- ),
1548
- children: "Approve all"
1549
- }
1550
- ),
1551
- /* @__PURE__ */ jsx(
1552
- Button,
1553
- {
1554
- type: "button",
1555
- size: "sm",
1556
- variant: "outline",
1557
- disabled: pending.length === 0,
1558
- "data-testid": "annotation-reject-all",
1559
- onClick: () => controller.setRedactionStatus(
1560
- pending.map((a) => a.id),
1561
- "rejected"
1562
- ),
1563
- children: "Reject all"
1564
- }
1565
- )
1707
+ editable && /* @__PURE__ */ jsxs(Fragment, { children: [
1708
+ /* @__PURE__ */ jsx(
1709
+ Button,
1710
+ {
1711
+ type: "button",
1712
+ size: "sm",
1713
+ variant: "outline",
1714
+ disabled: pending.length === 0,
1715
+ "data-testid": "annotation-approve-all",
1716
+ onClick: () => controller.setRedactionStatus(
1717
+ pending.map((a) => a.id),
1718
+ "approved"
1719
+ ),
1720
+ children: "Approve all"
1721
+ }
1722
+ ),
1723
+ /* @__PURE__ */ jsx(
1724
+ Button,
1725
+ {
1726
+ type: "button",
1727
+ size: "sm",
1728
+ variant: "outline",
1729
+ disabled: pending.length === 0,
1730
+ "data-testid": "annotation-reject-all",
1731
+ onClick: () => controller.setRedactionStatus(
1732
+ pending.map((a) => a.id),
1733
+ "rejected"
1734
+ ),
1735
+ children: "Reject all"
1736
+ }
1737
+ )
1738
+ ] })
1566
1739
  ] }),
1567
1740
  /* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-3 text-xs text-muted-foreground", children: [
1568
1741
  /* @__PURE__ */ jsx(
@@ -1570,11 +1743,13 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
1570
1743
  {
1571
1744
  "data-testid": "annotation-status",
1572
1745
  role: "status",
1573
- className: cn(controller.error && "text-destructive"),
1746
+ "data-state": controller.readOnly ? "readonly" : controller.offline ? "offline" : controller.error ? "error" : controller.saving ? "saving" : controller.dirty ? "dirty" : "saved",
1747
+ className: cn(controller.error && !controller.offline && "text-destructive"),
1574
1748
  title: controller.error ?? void 0,
1575
1749
  children: status
1576
1750
  }
1577
1751
  ),
1752
+ actions,
1578
1753
  onFreeze && /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", "data-testid": "annotation-freeze", onClick: onFreeze, children: [
1579
1754
  /* @__PURE__ */ jsx(Snowflake, { size: 14 }),
1580
1755
  "Freeze copy"
@@ -2094,6 +2269,6 @@ function ProductionDialog({
2094
2269
  ] }) });
2095
2270
  }
2096
2271
 
2097
- export { AnnotationPageOverlay, AnnotationToolbar, DEFAULT_SETTINGS, FreezeDialog, HIGHLIGHT_COLORS, MARK_COLORS, ProductionDialog, REDACTION_LOG_COLUMNS, REDACTION_REASONS, STAMP_PRESETS, annotationsOnPage, applyAction, canRedo, canUndo, containsPoint, createHistory, createLocalStorageStore, createMemoryStore, dragRect, dragToNorm, intersects, isTooSmall, mergeLineRects, moveItem, patchForRect, pendingRedactions, qrCornerFor, readSelection, redactionLogCsv, redactionLogRows, redo, reduceLayer, selectionToPageMarks, singleRect, toNorm, toPixels, undo, useAnnotationLayer, useAnnotationShortcuts, useTextSelectionMarks };
2272
+ export { AUTOSAVE_MS, AnnotationPageOverlay, AnnotationStoreOfflineError, AnnotationToolbar, DEFAULT_SETTINGS, FreezeDialog, HIGHLIGHT_COLORS, MARK_COLORS, ProductionDialog, REDACTION_LOG_COLUMNS, REDACTION_REASONS, RETRY_MS, STAMP_PRESETS, annotationsOnPage, applyAction, canRedo, canUndo, containsPoint, createHistory, createLocalStorageStore, createMemoryStore, dragRect, dragToNorm, intersects, isTooSmall, layerStatusText, mergeLayers, mergeLineRects, moveItem, patchForRect, pendingRedactions, qrCornerFor, readSelection, redactionLogCsv, redactionLogRows, redo, reduceLayer, sameMarks, selectionToPageMarks, singleRect, toNorm, toPixels, undo, useAnnotationLayer, useAnnotationShortcuts, useTextSelectionMarks };
2098
2273
  //# sourceMappingURL=index.js.map
2099
2274
  //# sourceMappingURL=index.js.map