@arbidocs/react 0.4.64 → 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.
- package/dist/annotations/index.cjs +241 -61
- package/dist/annotations/index.cjs.map +1 -1
- package/dist/annotations/index.d.cts +72 -5
- package/dist/annotations/index.d.ts +72 -5
- package/dist/annotations/index.js +236 -62
- package/dist/annotations/index.js.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/package.json +3 -3
|
@@ -134,6 +134,12 @@ function pendingRedactions(layer) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
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
|
+
};
|
|
137
143
|
function createMemoryStore(now = () => (/* @__PURE__ */ new Date()).toISOString()) {
|
|
138
144
|
const layers = /* @__PURE__ */ new Map();
|
|
139
145
|
return {
|
|
@@ -171,6 +177,56 @@ function safeLocalStorage() {
|
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
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
|
+
|
|
174
230
|
// src/annotations/redaction-log.ts
|
|
175
231
|
var REDACTION_LOG_COLUMNS = ["page", "reason", "status", "approved_by", "time"];
|
|
176
232
|
var STATUS = {
|
|
@@ -291,14 +347,37 @@ var REDACTION_REASONS = [
|
|
|
291
347
|
"Commercial",
|
|
292
348
|
"Irrelevant"
|
|
293
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
|
+
}
|
|
294
361
|
var AUTOSAVE_MS = 600;
|
|
362
|
+
var RETRY_MS = 1e4;
|
|
295
363
|
var defaultNow = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
296
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
|
+
}
|
|
297
373
|
function useAnnotationLayer({
|
|
298
374
|
documentId,
|
|
299
375
|
store,
|
|
300
376
|
author,
|
|
301
377
|
autosaveMs = AUTOSAVE_MS,
|
|
378
|
+
readOnly: readOnlyProp = false,
|
|
379
|
+
online = true,
|
|
380
|
+
pullMs = 0,
|
|
302
381
|
now = defaultNow,
|
|
303
382
|
makeId = defaultId
|
|
304
383
|
}) {
|
|
@@ -309,12 +388,17 @@ function useAnnotationLayer({
|
|
|
309
388
|
const [status, setStatus] = useState("loading");
|
|
310
389
|
const [error, setError] = useState(null);
|
|
311
390
|
const [saving, setSaving] = useState(false);
|
|
391
|
+
const [offlineFailure, setOfflineFailure] = useState(false);
|
|
392
|
+
const [storeReadOnly, setStoreReadOnly] = useState(false);
|
|
312
393
|
const [tool, setToolState] = useState("select");
|
|
313
394
|
const [settings, setSettingsState] = useState(DEFAULT_SETTINGS);
|
|
314
395
|
const [selectedId, setSelectedId] = useState(null);
|
|
396
|
+
const readOnly = readOnlyProp || storeReadOnly;
|
|
315
397
|
const historyRef = useRef(history);
|
|
316
398
|
const savedRef = useRef(null);
|
|
317
399
|
const timerRef = useRef(void 0);
|
|
400
|
+
const retryRef = useRef(void 0);
|
|
401
|
+
const savingRef = useRef(false);
|
|
318
402
|
const docRef = useRef(documentId);
|
|
319
403
|
const storeRef = useRef(store);
|
|
320
404
|
storeRef.current = store;
|
|
@@ -322,10 +406,24 @@ function useAnnotationLayer({
|
|
|
322
406
|
nowRef.current = now;
|
|
323
407
|
const idRef = useRef(makeId);
|
|
324
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;
|
|
325
415
|
const commit = useCallback((next) => {
|
|
326
416
|
historyRef.current = next;
|
|
327
417
|
setHistory(next);
|
|
328
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
|
+
);
|
|
329
427
|
useEffect(() => {
|
|
330
428
|
docRef.current = documentId;
|
|
331
429
|
let cancelled = false;
|
|
@@ -333,12 +431,14 @@ function useAnnotationLayer({
|
|
|
333
431
|
setError(null);
|
|
334
432
|
setSelectedId(null);
|
|
335
433
|
setSavedLayer(null);
|
|
434
|
+
setStoreReadOnly(false);
|
|
336
435
|
savedRef.current = null;
|
|
337
436
|
commit(createHistory(emptyLayer(documentId, nowRef.current())));
|
|
338
437
|
storeRef.current.load(documentId).then((layer) => {
|
|
339
438
|
if (cancelled) return;
|
|
340
439
|
savedRef.current = layer;
|
|
341
440
|
setSavedLayer(layer);
|
|
441
|
+
setStoreReadOnly(storeRef.current.canEdit?.(documentId) === false);
|
|
342
442
|
commit(createHistory(layer));
|
|
343
443
|
setStatus("ready");
|
|
344
444
|
}).catch((e) => {
|
|
@@ -349,37 +449,88 @@ function useAnnotationLayer({
|
|
|
349
449
|
return () => {
|
|
350
450
|
cancelled = true;
|
|
351
451
|
clearTimeout(timerRef.current);
|
|
452
|
+
clearTimeout(retryRef.current);
|
|
352
453
|
const layer = historyRef.current.present;
|
|
353
|
-
if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId) {
|
|
454
|
+
if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId && !readOnlyRef.current) {
|
|
354
455
|
storeRef.current.save(layer).catch((e) => console.error("Annotations could not be saved", e));
|
|
355
456
|
}
|
|
356
457
|
};
|
|
357
458
|
}, [documentId, commit]);
|
|
358
459
|
const save = useCallback(async () => {
|
|
359
460
|
clearTimeout(timerRef.current);
|
|
461
|
+
clearTimeout(retryRef.current);
|
|
360
462
|
const layer = historyRef.current.present;
|
|
361
|
-
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;
|
|
362
467
|
setSaving(true);
|
|
468
|
+
let failed = false;
|
|
363
469
|
try {
|
|
364
|
-
await storeRef.current.save(layer);
|
|
470
|
+
const stored = await storeRef.current.save(layer);
|
|
365
471
|
if (layer.documentId === docRef.current) {
|
|
366
|
-
savedRef.current = layer;
|
|
367
|
-
setSavedLayer(layer);
|
|
368
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
|
+
}
|
|
369
480
|
}
|
|
370
481
|
} catch (e) {
|
|
371
|
-
|
|
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);
|
|
372
489
|
} finally {
|
|
490
|
+
savingRef.current = false;
|
|
373
491
|
setSaving(false);
|
|
492
|
+
if (!failed && historyRef.current.present !== savedRef.current) {
|
|
493
|
+
timerRef.current = setTimeout(() => void saveRef.current(), autosaveMsRef.current);
|
|
494
|
+
}
|
|
374
495
|
}
|
|
375
|
-
}, []);
|
|
496
|
+
}, [adoptRemote]);
|
|
497
|
+
const saveRef = useRef(save);
|
|
498
|
+
saveRef.current = save;
|
|
376
499
|
const present = history.present;
|
|
377
500
|
const dirty = status === "ready" && present !== savedLayer;
|
|
378
501
|
useEffect(() => {
|
|
379
|
-
if (!dirty) return;
|
|
502
|
+
if (!dirty || !online || readOnly) return;
|
|
380
503
|
timerRef.current = setTimeout(() => void save(), autosaveMs);
|
|
381
504
|
return () => clearTimeout(timerRef.current);
|
|
382
|
-
}, [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]);
|
|
383
534
|
useEffect(() => {
|
|
384
535
|
const flush = () => void save();
|
|
385
536
|
const onVisibility = () => {
|
|
@@ -394,6 +545,7 @@ function useAnnotationLayer({
|
|
|
394
545
|
}, [save]);
|
|
395
546
|
const dispatch = useCallback(
|
|
396
547
|
(action) => {
|
|
548
|
+
if (readOnlyRef.current) return false;
|
|
397
549
|
try {
|
|
398
550
|
commit(applyAction(historyRef.current, action));
|
|
399
551
|
setError(null);
|
|
@@ -412,6 +564,7 @@ function useAnnotationLayer({
|
|
|
412
564
|
},
|
|
413
565
|
[author]
|
|
414
566
|
);
|
|
567
|
+
const offline = !online || offlineFailure;
|
|
415
568
|
const controller = useMemo(() => {
|
|
416
569
|
const exists = (id) => id !== null && present.annotations.some((a) => a.id === id) ? id : null;
|
|
417
570
|
return {
|
|
@@ -420,9 +573,12 @@ function useAnnotationLayer({
|
|
|
420
573
|
error,
|
|
421
574
|
saving,
|
|
422
575
|
dirty,
|
|
576
|
+
offline,
|
|
577
|
+
readOnly,
|
|
423
578
|
author,
|
|
424
|
-
tool,
|
|
579
|
+
tool: readOnly ? "select" : tool,
|
|
425
580
|
setTool: (next) => {
|
|
581
|
+
if (readOnly && next !== "select") return;
|
|
426
582
|
setToolState(next);
|
|
427
583
|
if (next !== "select") setSelectedId(null);
|
|
428
584
|
},
|
|
@@ -457,10 +613,14 @@ function useAnnotationLayer({
|
|
|
457
613
|
});
|
|
458
614
|
},
|
|
459
615
|
resolve: (id, resolved) => void dispatch({ type: "resolve", id, resolved, now: nowRef.current() }),
|
|
460
|
-
undo: () =>
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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),
|
|
464
624
|
flush: save
|
|
465
625
|
};
|
|
466
626
|
}, [
|
|
@@ -470,6 +630,8 @@ function useAnnotationLayer({
|
|
|
470
630
|
error,
|
|
471
631
|
saving,
|
|
472
632
|
dirty,
|
|
633
|
+
offline,
|
|
634
|
+
readOnly,
|
|
473
635
|
author,
|
|
474
636
|
tool,
|
|
475
637
|
settings,
|
|
@@ -730,7 +892,8 @@ function AnnotationPageOverlay({
|
|
|
730
892
|
const [openComment, setOpenComment] = useState(null);
|
|
731
893
|
const marks = controller.layer.annotations.filter((a) => a.page === pageNumber);
|
|
732
894
|
const hasText = useHasTextLayer(rootRef);
|
|
733
|
-
const
|
|
895
|
+
const readOnly = controller.readOnly;
|
|
896
|
+
const drawing = !readOnly && (DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText);
|
|
734
897
|
useEffect(() => {
|
|
735
898
|
if (openComment && selectedId !== openComment) setOpenComment(null);
|
|
736
899
|
}, [selectedId, openComment]);
|
|
@@ -827,7 +990,7 @@ function AnnotationPageOverlay({
|
|
|
827
990
|
};
|
|
828
991
|
const beginDrag = (e, a, mode) => {
|
|
829
992
|
const origin = singleRect(a);
|
|
830
|
-
if (!origin || e.button !== 0) return;
|
|
993
|
+
if (!origin || e.button !== 0 || readOnly) return;
|
|
831
994
|
e.stopPropagation();
|
|
832
995
|
e.currentTarget.setPointerCapture(e.pointerId);
|
|
833
996
|
setDrag({
|
|
@@ -858,7 +1021,7 @@ function AnnotationPageOverlay({
|
|
|
858
1021
|
if (drag.moved) controller.update(a.id, patchForRect(a, drag.rect));
|
|
859
1022
|
setDrag(null);
|
|
860
1023
|
};
|
|
861
|
-
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";
|
|
862
1025
|
const selected = marks.find((a) => a.id === selectedId);
|
|
863
1026
|
return /* @__PURE__ */ jsxs(
|
|
864
1027
|
"div",
|
|
@@ -906,7 +1069,7 @@ function AnnotationPageOverlay({
|
|
|
906
1069
|
},
|
|
907
1070
|
a.id
|
|
908
1071
|
)),
|
|
909
|
-
selected && tool === "select" && singleRect(selected) && /* @__PURE__ */ jsx(
|
|
1072
|
+
selected && tool === "select" && !readOnly && singleRect(selected) && /* @__PURE__ */ jsx(
|
|
910
1073
|
Handles,
|
|
911
1074
|
{
|
|
912
1075
|
rect: drag?.id === selected.id ? drag.rect : singleRect(selected),
|
|
@@ -915,7 +1078,7 @@ function AnnotationPageOverlay({
|
|
|
915
1078
|
onPointerUp: () => endDrag(selected)
|
|
916
1079
|
}
|
|
917
1080
|
),
|
|
918
|
-
selected && tool === "select" && /* @__PURE__ */ jsx(
|
|
1081
|
+
selected && tool === "select" && !readOnly && /* @__PURE__ */ jsx(
|
|
919
1082
|
ActionBar,
|
|
920
1083
|
{
|
|
921
1084
|
annotation: selected,
|
|
@@ -1232,14 +1395,15 @@ function CommentPopover({
|
|
|
1232
1395
|
}) {
|
|
1233
1396
|
const [body, setBody] = useState(a.body);
|
|
1234
1397
|
const [reply, setReply] = useState("");
|
|
1235
|
-
const
|
|
1398
|
+
const readOnly = controller.readOnly;
|
|
1399
|
+
const mine = a.author === controller.author && !readOnly;
|
|
1236
1400
|
useEffect(() => setBody(a.body), [a.body]);
|
|
1237
1401
|
const commitBody = () => {
|
|
1238
1402
|
if (mine && body !== a.body) controller.update(a.id, { body });
|
|
1239
1403
|
};
|
|
1240
1404
|
const close = () => {
|
|
1241
1405
|
commitBody();
|
|
1242
|
-
if (body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
|
|
1406
|
+
if (!readOnly && body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
|
|
1243
1407
|
onClose();
|
|
1244
1408
|
};
|
|
1245
1409
|
const sendReply = () => {
|
|
@@ -1310,7 +1474,7 @@ function CommentPopover({
|
|
|
1310
1474
|
] }, r.id))
|
|
1311
1475
|
}
|
|
1312
1476
|
),
|
|
1313
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex gap-1", children: [
|
|
1477
|
+
!readOnly && /* @__PURE__ */ jsxs("div", { className: "mt-2 flex gap-1", children: [
|
|
1314
1478
|
/* @__PURE__ */ jsx(
|
|
1315
1479
|
"input",
|
|
1316
1480
|
{
|
|
@@ -1339,7 +1503,7 @@ function CommentPopover({
|
|
|
1339
1503
|
}
|
|
1340
1504
|
)
|
|
1341
1505
|
] }),
|
|
1342
|
-
/* @__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: [
|
|
1343
1507
|
/* @__PURE__ */ jsx(
|
|
1344
1508
|
"button",
|
|
1345
1509
|
{
|
|
@@ -1426,14 +1590,20 @@ function Swatches({
|
|
|
1426
1590
|
c
|
|
1427
1591
|
)) });
|
|
1428
1592
|
}
|
|
1429
|
-
function AnnotationToolbar({
|
|
1593
|
+
function AnnotationToolbar({
|
|
1594
|
+
controller,
|
|
1595
|
+
onFreeze,
|
|
1596
|
+
actions,
|
|
1597
|
+
className
|
|
1598
|
+
}) {
|
|
1430
1599
|
useTextSelectionMarks(controller);
|
|
1431
1600
|
useAnnotationShortcuts(controller);
|
|
1432
1601
|
const { tool, settings } = controller;
|
|
1433
1602
|
const pending = pendingRedactions(controller.layer);
|
|
1434
1603
|
const redactionCount = controller.layer.annotations.filter((a) => a.kind === "redaction").length;
|
|
1435
1604
|
const colored = tool === "highlight" || tool === "box" || tool === "stamp";
|
|
1436
|
-
const status = controller
|
|
1605
|
+
const status = layerStatusText(controller);
|
|
1606
|
+
const editable = !controller.readOnly;
|
|
1437
1607
|
return /* @__PURE__ */ jsxs(
|
|
1438
1608
|
"div",
|
|
1439
1609
|
{
|
|
@@ -1445,7 +1615,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1445
1615
|
className
|
|
1446
1616
|
),
|
|
1447
1617
|
children: [
|
|
1448
|
-
/* @__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(
|
|
1449
1619
|
Button,
|
|
1450
1620
|
{
|
|
1451
1621
|
type: "button",
|
|
@@ -1460,7 +1630,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1460
1630
|
},
|
|
1461
1631
|
t
|
|
1462
1632
|
)) }),
|
|
1463
|
-
/* @__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: [
|
|
1464
1634
|
/* @__PURE__ */ jsx(
|
|
1465
1635
|
Button,
|
|
1466
1636
|
{
|
|
@@ -1490,7 +1660,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1490
1660
|
}
|
|
1491
1661
|
)
|
|
1492
1662
|
] }),
|
|
1493
|
-
colored && /* @__PURE__ */ jsx(
|
|
1663
|
+
editable && colored && /* @__PURE__ */ jsx(
|
|
1494
1664
|
Swatches,
|
|
1495
1665
|
{
|
|
1496
1666
|
label: "Colour",
|
|
@@ -1499,7 +1669,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1499
1669
|
onChange: (c) => controller.setSettings({ colors: { ...settings.colors, [tool]: c } })
|
|
1500
1670
|
}
|
|
1501
1671
|
),
|
|
1502
|
-
tool === "stamp" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1672
|
+
editable && tool === "stamp" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1503
1673
|
/* @__PURE__ */ jsx(
|
|
1504
1674
|
"input",
|
|
1505
1675
|
{
|
|
@@ -1514,7 +1684,7 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1514
1684
|
),
|
|
1515
1685
|
/* @__PURE__ */ jsx("datalist", { id: "annotation-stamp-presets", children: STAMP_PRESETS.map((s) => /* @__PURE__ */ jsx("option", { value: s }, s)) })
|
|
1516
1686
|
] }),
|
|
1517
|
-
(tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1687
|
+
editable && (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1518
1688
|
/* @__PURE__ */ jsx(
|
|
1519
1689
|
"input",
|
|
1520
1690
|
{
|
|
@@ -1534,36 +1704,38 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1534
1704
|
pending.length,
|
|
1535
1705
|
" pending"
|
|
1536
1706
|
] }),
|
|
1537
|
-
/* @__PURE__ */
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
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
|
+
] })
|
|
1567
1739
|
] }),
|
|
1568
1740
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-3 text-xs text-muted-foreground", children: [
|
|
1569
1741
|
/* @__PURE__ */ jsx(
|
|
@@ -1571,11 +1743,13 @@ function AnnotationToolbar({ controller, onFreeze, className }) {
|
|
|
1571
1743
|
{
|
|
1572
1744
|
"data-testid": "annotation-status",
|
|
1573
1745
|
role: "status",
|
|
1574
|
-
|
|
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"),
|
|
1575
1748
|
title: controller.error ?? void 0,
|
|
1576
1749
|
children: status
|
|
1577
1750
|
}
|
|
1578
1751
|
),
|
|
1752
|
+
actions,
|
|
1579
1753
|
onFreeze && /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", "data-testid": "annotation-freeze", onClick: onFreeze, children: [
|
|
1580
1754
|
/* @__PURE__ */ jsx(Snowflake, { size: 14 }),
|
|
1581
1755
|
"Freeze copy"
|
|
@@ -2095,6 +2269,6 @@ function ProductionDialog({
|
|
|
2095
2269
|
] }) });
|
|
2096
2270
|
}
|
|
2097
2271
|
|
|
2098
|
-
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 };
|
|
2099
2273
|
//# sourceMappingURL=index.js.map
|
|
2100
2274
|
//# sourceMappingURL=index.js.map
|