@arbidocs/react 0.4.69 → 0.4.71

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 (96) hide show
  1. package/README.md +10 -0
  2. package/dist/ProductionDialog-BRrZ5Lj5.d.cts +84 -0
  3. package/dist/ProductionDialog-DUC9BXWS.d.ts +84 -0
  4. package/dist/annotations/freeze/index.cjs +45 -1100
  5. package/dist/annotations/freeze/index.cjs.map +1 -1
  6. package/dist/annotations/freeze/index.d.cts +2 -85
  7. package/dist/annotations/freeze/index.d.ts +2 -85
  8. package/dist/annotations/freeze/index.js +4 -1084
  9. package/dist/annotations/freeze/index.js.map +1 -1
  10. package/dist/annotations/index.cjs +186 -2450
  11. package/dist/annotations/index.cjs.map +1 -1
  12. package/dist/annotations/index.d.cts +3 -81
  13. package/dist/annotations/index.d.ts +3 -81
  14. package/dist/annotations/index.js +4 -2411
  15. package/dist/annotations/index.js.map +1 -1
  16. package/dist/artifacts/index.cjs +91 -115
  17. package/dist/artifacts/index.cjs.map +1 -1
  18. package/dist/artifacts/index.js +13 -62
  19. package/dist/artifacts/index.js.map +1 -1
  20. package/dist/artifacts/redline-core.cjs +8 -7
  21. package/dist/artifacts/redline-core.js +2 -1
  22. package/dist/bundle-BnCSbHy2.d.cts +85 -0
  23. package/dist/bundle-BnCSbHy2.d.ts +85 -0
  24. package/dist/bundle-N2JIJ2T6.js +4 -0
  25. package/dist/bundle-N2JIJ2T6.js.map +1 -0
  26. package/dist/bundle-T6BEVYHE.cjs +13 -0
  27. package/dist/bundle-T6BEVYHE.cjs.map +1 -0
  28. package/dist/{chunk-PATLJSAO.cjs → chunk-3AADNIOK.cjs} +9 -52
  29. package/dist/chunk-3AADNIOK.cjs.map +1 -0
  30. package/dist/chunk-3QF5DNAP.js +2413 -0
  31. package/dist/chunk-3QF5DNAP.js.map +1 -0
  32. package/dist/chunk-5DCRIWCA.cjs +243 -0
  33. package/dist/chunk-5DCRIWCA.cjs.map +1 -0
  34. package/dist/{chunk-NA3FOYSF.cjs → chunk-5SZ2J2WT.cjs} +5 -177
  35. package/dist/chunk-5SZ2J2WT.cjs.map +1 -0
  36. package/dist/{chunk-PFKLOVGQ.js → chunk-6ERJUIMQ.js} +4 -234
  37. package/dist/chunk-6ERJUIMQ.js.map +1 -0
  38. package/dist/{chunk-Z3RRZ3KV.cjs → chunk-6TFD5OS5.cjs} +25 -263
  39. package/dist/chunk-6TFD5OS5.cjs.map +1 -0
  40. package/dist/{chunk-43AKLNBC.js → chunk-74N436VK.js} +4 -40
  41. package/dist/chunk-74N436VK.js.map +1 -0
  42. package/dist/{chunk-BWVIAATD.cjs → chunk-BTRIS3HY.cjs} +4 -4
  43. package/dist/{chunk-BWVIAATD.cjs.map → chunk-BTRIS3HY.cjs.map} +1 -1
  44. package/dist/chunk-G6FHNURH.js +234 -0
  45. package/dist/chunk-G6FHNURH.js.map +1 -0
  46. package/dist/chunk-HKUD2NZN.js +61 -0
  47. package/dist/chunk-HKUD2NZN.js.map +1 -0
  48. package/dist/{chunk-ZMTLGO3K.cjs → chunk-IIT7DMQL.cjs} +6 -2
  49. package/dist/chunk-IIT7DMQL.cjs.map +1 -0
  50. package/dist/chunk-QJXFRP5R.cjs +1103 -0
  51. package/dist/chunk-QJXFRP5R.cjs.map +1 -0
  52. package/dist/chunk-QRCMKEE6.js +173 -0
  53. package/dist/chunk-QRCMKEE6.js.map +1 -0
  54. package/dist/chunk-T4IJHRRD.cjs +71 -0
  55. package/dist/chunk-T4IJHRRD.cjs.map +1 -0
  56. package/dist/chunk-ULU5LEWF.cjs +2460 -0
  57. package/dist/chunk-ULU5LEWF.cjs.map +1 -0
  58. package/dist/{chunk-TQ6FRVAH.js → chunk-V4CXOPLB.js} +3 -3
  59. package/dist/{chunk-TQ6FRVAH.js.map → chunk-V4CXOPLB.js.map} +1 -1
  60. package/dist/chunk-VOFNX4P6.cjs +50 -0
  61. package/dist/chunk-VOFNX4P6.cjs.map +1 -0
  62. package/dist/{chunk-J4MX2W4H.js → chunk-WBYNKFUO.js} +6 -3
  63. package/dist/chunk-WBYNKFUO.js.map +1 -0
  64. package/dist/chunk-WUTL62MC.js +42 -0
  65. package/dist/chunk-WUTL62MC.js.map +1 -0
  66. package/dist/{chunk-JPGV7NMY.js → chunk-YXSXGTYQ.js} +4 -173
  67. package/dist/chunk-YXSXGTYQ.js.map +1 -0
  68. package/dist/chunk-Z3LLUO32.cjs +177 -0
  69. package/dist/chunk-Z3LLUO32.cjs.map +1 -0
  70. package/dist/chunk-ZJMUNGOY.js +1088 -0
  71. package/dist/chunk-ZJMUNGOY.js.map +1 -0
  72. package/dist/document-tools/index.cjs +898 -0
  73. package/dist/document-tools/index.cjs.map +1 -0
  74. package/dist/document-tools/index.d.cts +522 -0
  75. package/dist/document-tools/index.d.ts +522 -0
  76. package/dist/document-tools/index.js +837 -0
  77. package/dist/document-tools/index.js.map +1 -0
  78. package/dist/index.cjs +365 -359
  79. package/dist/index.cjs.map +1 -1
  80. package/dist/index.d.cts +7 -1
  81. package/dist/index.d.ts +7 -1
  82. package/dist/index.js +11 -8
  83. package/dist/index.js.map +1 -1
  84. package/dist/ui/index.cjs +132 -131
  85. package/dist/ui/index.js +3 -2
  86. package/dist/viewers/index.cjs +2 -2
  87. package/dist/viewers/index.js +1 -1
  88. package/package.json +11 -3
  89. package/dist/chunk-43AKLNBC.js.map +0 -1
  90. package/dist/chunk-J4MX2W4H.js.map +0 -1
  91. package/dist/chunk-JPGV7NMY.js.map +0 -1
  92. package/dist/chunk-NA3FOYSF.cjs.map +0 -1
  93. package/dist/chunk-PATLJSAO.cjs.map +0 -1
  94. package/dist/chunk-PFKLOVGQ.js.map +0 -1
  95. package/dist/chunk-Z3RRZ3KV.cjs.map +0 -1
  96. package/dist/chunk-ZMTLGO3K.cjs.map +0 -1
@@ -0,0 +1,522 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { ArbiClient, operations, components } from '@arbidocs/client';
4
+ import { P as ProductionChoices, A as AnnotationStore } from '../ProductionDialog-DUC9BXWS.js';
5
+ import { a as BundleFile, b as BundleIndexEntry } from '../bundle-BnCSbHy2.js';
6
+ import { A as Annotation, b as AnnotationLayer } from '../model-DIwXRuGC.js';
7
+ import * as _tanstack_react_query from '@tanstack/react-query';
8
+
9
+ type DocumentToolsClient = ArbiClient['fetch'];
10
+ type DocumentToolsNoticeKind = 'success' | 'error' | 'info' | 'warning';
11
+ interface DocumentToolsNoticeOptions {
12
+ /** A second line under the message. */
13
+ description?: string;
14
+ /** One action button on the notice ("Email it"). */
15
+ action?: {
16
+ label: string;
17
+ onClick: () => void;
18
+ };
19
+ }
20
+ type DocumentToolsNotify = (message: string, kind: DocumentToolsNoticeKind, options?: DocumentToolsNoticeOptions) => void;
21
+ interface DocumentToolsUser {
22
+ /** The name marks are authored as and the signer's name is prefilled with. */
23
+ name: string;
24
+ /** The sign-in email: signing re-derives the user's key from it and the password. */
25
+ email?: string | null;
26
+ }
27
+ /** What changed about a document, so the host can refresh its own lists and caches. */
28
+ type DocumentChange =
29
+ /** A version's markup got its first mark or lost its last one. */
30
+ 'markup'
31
+ /** A signature was added: the document has a new current version. */
32
+ | 'signed'
33
+ /** A new document was made from it (a frozen copy). The ids are the NEW documents. */
34
+ | 'copy';
35
+ /**
36
+ * The `/v1/document/upload` query, typed from the API schema: `derived_from` is a list (a
37
+ * production set is derived from every document in it), `shared` a boolean.
38
+ */
39
+ type DocumentUploadQuery = NonNullable<operations['upload_documents']['parameters']['query']>;
40
+ interface DocumentUploadRequest {
41
+ file: File;
42
+ /** `/v1/document/upload` query: `derived_from`, `derived_role`, `shared`, `folder`. */
43
+ query: DocumentUploadQuery;
44
+ }
45
+ /**
46
+ * The upload query as a URL query string, for a host that posts the upload itself (an XHR with
47
+ * progress): a list repeats its key (`derived_from=a&derived_from=b`), empty values are left out.
48
+ */
49
+ declare function uploadQueryString(query: DocumentUploadQuery): string;
50
+ interface DocumentToolsEnvironment {
51
+ client: DocumentToolsClient;
52
+ /**
53
+ * The deployment domain the user's keys are derived for. Needed for signing. Default: the one
54
+ * the enclosing `<ArbiProvider>`'s `Arbi` computes (`arbi.getDeploymentDomain()`), if any.
55
+ */
56
+ deploymentDomain?: string;
57
+ /** The signed-in user; marks are authored as "You" without one, and signing is unavailable. */
58
+ user?: DocumentToolsUser | null;
59
+ /** Surface a transient message. Default: none (errors still show inline where they can). */
60
+ notify?: DocumentToolsNotify;
61
+ /** Open a document or a version reference (`doc-…@v2`): the copy just made, the signed copy. */
62
+ openDocument?: (documentRef: string) => void;
63
+ /**
64
+ * Documents changed on the server (see {@link DocumentChange}); refresh the host's lists. The
65
+ * tools wait for it before opening the document, so a copy is listed when it opens.
66
+ */
67
+ onDocumentsChanged?: (documentIds: string[], change: DocumentChange) => void | Promise<void>;
68
+ /** Upload a derived copy. Default: `POST /v1/document/upload` through `client`. */
69
+ uploadDocument?: (request: DocumentUploadRequest) => Promise<{
70
+ doc_ext_ids?: string[];
71
+ } | undefined>;
72
+ /** Save a file to the user's computer. Default: a temporary download link. */
73
+ saveFile?: (blob: Blob, fileName: string) => void;
74
+ /** Email a document (offered once it is signed). Omitted: no "Email it". */
75
+ emailDocument?: (documentRef: string) => void;
76
+ /**
77
+ * The public page that checks a signature (the certificate) in this app. When given, "View
78
+ * certificate" opens it in preference to the backend's `certificate_url` (which is on the
79
+ * deployment domain, like the link embedded in the signed PDF). Without it: the backend's
80
+ * `certificate_url`, else `/verify/{reference}` on this origin.
81
+ */
82
+ certificateUrl?: (reference: string) => string;
83
+ }
84
+ /** The environment with every default filled in. */
85
+ interface ResolvedDocumentToolsEnvironment extends DocumentToolsEnvironment {
86
+ notify: DocumentToolsNotify;
87
+ saveFile: (blob: Blob, fileName: string) => void;
88
+ uploadDocument: (request: DocumentUploadRequest) => Promise<{
89
+ doc_ext_ids?: string[];
90
+ } | undefined>;
91
+ }
92
+ /** Save a blob through a temporary `<a download>`. */
93
+ declare function downloadBlob(blob: Blob, fileName: string): void;
94
+ /** The default upload: multipart `files` to `/v1/document/upload` through the API client. */
95
+ declare function clientUpload(client: DocumentToolsClient): ({ file, query }: DocumentUploadRequest) => Promise<{
96
+ doc_ext_ids?: string[] | undefined;
97
+ version?: number | null | undefined;
98
+ batch_id?: string | null | undefined;
99
+ skipped?: {
100
+ file_name: string;
101
+ reason: string;
102
+ }[] | undefined;
103
+ } | undefined>;
104
+ declare function defaultCertificateUrl(reference: string): string;
105
+ /**
106
+ * Where "View certificate" goes for a signature: the host's `certificateUrl(reference)` when it
107
+ * gives one, else the `certificate_url` the backend returned, else `/verify/{reference}` here.
108
+ */
109
+ declare function certificateLink(signature: {
110
+ reference: string;
111
+ certificate_url?: string | null;
112
+ }, certificateUrl?: (reference: string) => string): string;
113
+ interface DocumentToolsProviderProps extends DocumentToolsEnvironment {
114
+ children: ReactNode;
115
+ }
116
+ declare function DocumentToolsProvider({ children, ...env }: DocumentToolsProviderProps): React.JSX.Element;
117
+ /** The host's environment, or `null` outside a `<DocumentToolsProvider>`. */
118
+ declare function useOptionalDocumentTools(): ResolvedDocumentToolsEnvironment | null;
119
+ /** The host's environment; throws outside a `<DocumentToolsProvider>`. */
120
+ declare function useDocumentTools(): ResolvedDocumentToolsEnvironment;
121
+
122
+ /**
123
+ * A document's bytes, through the host's API client: the PDF the viewer and the tools draw on
124
+ * (`/view`: the file itself for a PDF, its PDF rendering for a Word or text file) and the stored
125
+ * file (`/download`). Either takes a document id or a version reference `doc-…@v{n}`.
126
+ */
127
+
128
+ interface DocumentFetchOptions {
129
+ /** The version to fetch. Default: the one `documentRef` names, else the current version. */
130
+ version?: number | null;
131
+ signal?: AbortSignal;
132
+ }
133
+ /** A document's bytes could not be fetched; `status` is the HTTP status. */
134
+ declare class DocumentFetchError extends Error {
135
+ readonly status: number;
136
+ constructor(message: string, status: number);
137
+ }
138
+ /**
139
+ * The PDF of a document version: `GET /v1/document/{id}/view?version=` with
140
+ * `Accept: application/pdf`. Throws a {@link DocumentFetchError} when there is none (yet).
141
+ */
142
+ declare function fetchDocumentPdf(client: DocumentToolsClient, documentRef: string, options?: DocumentFetchOptions): Promise<Blob>;
143
+ /** The stored file of a document version, as uploaded: `GET /v1/document/{id}/download`. */
144
+ declare function fetchDocumentFile(client: DocumentToolsClient, documentRef: string, options?: DocumentFetchOptions): Promise<Blob>;
145
+
146
+ /**
147
+ * Production sets: number the selected documents with Bates labels (optionally a QR code back to
148
+ * each document and an index page) and save the result back to the workspace. The dialog is
149
+ * `ProductionSetDialog` in `@arbidocs/blocks/document-tools`; this is its data side.
150
+ *
151
+ * A PDF is numbered as stored (`/download`). Any other document is numbered through its PDF
152
+ * rendition (`/view`, what the viewer shows for a Word or text file); one without a rendition is
153
+ * left out. Saved results are new documents derived from their sources (role `production`) in a
154
+ * Productions folder, shared with the workspace only if every source is. The originals never
155
+ * change.
156
+ *
157
+ * pdf-lib (the numbering) is loaded only when a production is built, so importing this module
158
+ * stays as light as the rest of the document tools.
159
+ */
160
+
161
+ /** The fields of a document record (`DocResponse`) a production uses. */
162
+ type ProductionSource = Pick<components['schemas']['DocResponse'], 'external_id' | 'file_name' | 'file_type' | 'shared'> & {
163
+ doc_metadata?: {
164
+ title?: string | null;
165
+ } | null;
166
+ };
167
+ declare const PRODUCTIONS_FOLDER = "Productions";
168
+ declare const isPdfDocument: (doc: ProductionSource) => boolean;
169
+ /** True for a document with no PDF version to number (media, archives and the like). */
170
+ declare const hasNoRendition: (doc: ProductionSource) => boolean;
171
+ /** The name a document goes by in the dialog and the index: its title, else its file name. */
172
+ declare const productionDocumentName: (doc: ProductionSource) => string;
173
+ /**
174
+ * The PDF to number for `doc`: the file itself, or the PDF version of anything else. `null` when a
175
+ * non-PDF has no PDF version (yet), so it is left out; a PDF that cannot be downloaded throws.
176
+ */
177
+ declare function fetchProductionPdf(client: DocumentToolsClient, doc: ProductionSource): Promise<Uint8Array | null>;
178
+ /** "Production ACME-000001-ACME-000042": names the files and folder of one production. */
179
+ declare function productionTitle(firstLabel: string, lastLabel: string): string;
180
+ /** Where a production is saved: the Productions folder, or a folder of its own per document. */
181
+ declare function productionFolder(title: string, merged: boolean): string;
182
+ /** In the workspace a per-document file says which range it holds, beside its original. */
183
+ declare function productionFileName(file: BundleFile, title: string): string;
184
+ /** The `index.csv` of a per-document production: every document with its file and range. */
185
+ declare function productionIndexCsv(index: readonly BundleIndexEntry[]): string;
186
+ interface ProductionUpload {
187
+ name: string;
188
+ bytes: Uint8Array;
189
+ /** The documents this file was made from. */
190
+ sources: ProductionSource[];
191
+ }
192
+ /** Save each file as a new workspace document derived from its sources; returns the new ids. */
193
+ declare function saveProductionFiles(upload: NonNullable<DocumentToolsEnvironment['uploadDocument']>, files: readonly ProductionUpload[], folder: string): Promise<string[]>;
194
+ interface BuildProductionOptions {
195
+ /** The link a document's QR code opens (the document in the host app). */
196
+ documentUrl: (documentId: string) => string;
197
+ /** Who produced the set; recorded in a merged file's metadata. */
198
+ author?: string;
199
+ onProgress?: (done: number, total: number) => void;
200
+ }
201
+ interface BuiltProduction {
202
+ title: string;
203
+ merged: boolean;
204
+ /** The numbered files: one merged PDF (named after its range), or one per document (+ index). */
205
+ files: BundleFile[];
206
+ index: BundleIndexEntry[];
207
+ /** The documents numbered, in order. */
208
+ included: ProductionSource[];
209
+ /** Documents left out because they have no PDF version yet. */
210
+ noRendition: ProductionSource[];
211
+ /** The files as they are saved to the workspace, each with the documents it was made from. */
212
+ uploads: ProductionUpload[];
213
+ folder: string;
214
+ }
215
+ /**
216
+ * Fetch each document's PDF (in `choices.order`) and number the set. Throws when none of the
217
+ * documents has a PDF version, or when a PDF cannot be fetched.
218
+ */
219
+ declare function buildProduction(client: DocumentToolsClient, documents: readonly ProductionSource[], choices: ProductionChoices, options: BuildProductionOptions): Promise<BuiltProduction>;
220
+
221
+ /**
222
+ * The annotation store for a document version's MARKUP on the server: `GET`/`PUT
223
+ * /v1/document/{id}/markup`. The server keeps the marks as native PDF annotations in an encrypted
224
+ * `{doc}-markup.pdf` next to the version (same document id, the document's own privacy); this store
225
+ * only moves the layer and its revision.
226
+ *
227
+ * Optimistic concurrency: every save names the revision it started from. When someone else saved
228
+ * first the server answers 409; the store then re-reads the latest layer, merges it with ours by
229
+ * annotation id (`mergeLayers`: union, last edit wins per mark, replies unioned, our deletions
230
+ * stay deleted) and saves again. The merged layer is returned so the viewer shows their marks too.
231
+ *
232
+ * Deletions are tracked as tombstones for the session: an id this session has seen that is no
233
+ * longer in the layer it saves was deleted here, and a concurrent edit elsewhere cannot bring it
234
+ * back.
235
+ */
236
+
237
+ /** How many times a save re-reads and merges after a 409 before giving up (each is a real race). */
238
+ declare const MAX_MERGE_ATTEMPTS = 5;
239
+ interface MarkupSnapshot {
240
+ revision: number;
241
+ count: number;
242
+ canEdit: boolean;
243
+ }
244
+ interface MarkupStoreOptions {
245
+ /** The version the markup belongs to; omitted = the document's current version. */
246
+ version?: number;
247
+ /** The ARBI API client (see `DocumentToolsEnvironment.client`). */
248
+ client: DocumentToolsClient;
249
+ /** After every successful save: the new revision and how many marks the markup holds. */
250
+ onSaved?: (snapshot: MarkupSnapshot) => void;
251
+ }
252
+ interface MarkupStore extends AnnotationStore {
253
+ snapshot(): MarkupSnapshot;
254
+ }
255
+ declare class MarkupStoreError extends Error {
256
+ readonly status?: number | undefined;
257
+ constructor(message: string, status?: number | undefined);
258
+ }
259
+ declare function createMarkupStore({ version, client, onSaved }: MarkupStoreOptions): MarkupStore;
260
+
261
+ /**
262
+ * Moving marks INTO a version's markup without the viewer: the one-time migration of layers kept in
263
+ * this browser before markup lived on the server, and "copy open comments" from an older version's
264
+ * markup onto the current one (a new version — signed, synced from Drive, saved from Word — starts
265
+ * with an empty markup; redactions never carry over).
266
+ *
267
+ * Both are unions by annotation id, so running them twice adds nothing twice.
268
+ */
269
+
270
+ declare const LEGACY_LAYER_PREFIX = "arbi:annotations:";
271
+ interface VersionInfo {
272
+ n: number;
273
+ created_at?: string | null;
274
+ markup_count?: number | null;
275
+ }
276
+ /** The layer this browser kept for a document before markup moved to the server, if any. */
277
+ declare function readLegacyLayer(documentId: string): AnnotationLayer | null;
278
+ declare function forgetLegacyLayer(documentId: string): void;
279
+ /**
280
+ * Which version each legacy mark belongs to: the version that was current when it was made. A
281
+ * document's id is the id of its first version (older layers were made on it); a layer made after
282
+ * the versions moved inside the document was made on whatever version was then current.
283
+ */
284
+ declare function marksByVersion(layer: AnnotationLayer, versions: VersionInfo[]): Map<number, Annotation[]>;
285
+ /** Add marks to one version's markup (union by id); returns how many were new. */
286
+ declare function addToMarkup(documentId: string, version: number | undefined, marks: Annotation[], client: DocumentToolsClient): Promise<number>;
287
+ /**
288
+ * Migrate this browser's layer for a document into its markup, version by version, then forget
289
+ * the browser copy. Throws (and keeps the browser copy) if any version could not be saved.
290
+ */
291
+ declare function migrateLegacyLayer(documentId: string, layer: AnnotationLayer, versions: VersionInfo[], currentVersion: number, client: DocumentToolsClient): Promise<number>;
292
+ /** The unresolved comment threads (with replies) of a version's markup. */
293
+ declare function openThreadsOf(documentId: string, version: number, client: DocumentToolsClient): Promise<Annotation[]>;
294
+ /** Copy the open comment threads of an older version onto the current version's markup. */
295
+ declare function copyOpenThreads(documentId: string, fromVersion: number, client: DocumentToolsClient): Promise<number>;
296
+ /** Version entries of a document as the API returns them (`DocResponse.versions`). */
297
+ declare function versionsWithMarkup(versions: VersionInfo[] | null | undefined): VersionInfo[];
298
+
299
+ /**
300
+ * "Download with markup": a document version's markup PDF, the PDF with its annotations as native
301
+ * PDF annotations (comments, highlights, stamps, unapplied redactions), which Acrobat and Preview
302
+ * show. The plain Download serves the original. Kept apart from the annotation layer code so a
303
+ * documents list can offer it without loading the annotation tools.
304
+ *
305
+ * A SIGNED version is locked: nothing but a further signature changes it. Its markup stays in the
306
+ * separate markup layer (a title beside the signature, say) and is never written into its PDF, so
307
+ * it has no "Download with markup"; the plain Download is the signed file as it is.
308
+ */
309
+
310
+ interface DocumentVersions {
311
+ current_version?: number | null;
312
+ versions?: Array<{
313
+ n: number;
314
+ markup_count?: number | null;
315
+ reason?: string | null;
316
+ }> | null;
317
+ }
318
+ /** Why "Download with markup" is off for a signed version. */
319
+ declare const SIGNED_LOCKED_REASON = "Signed documents can't be changed \u2014 download the signed file instead";
320
+ /** Whether a version (default: the current one) is a signed copy, per its version entry. */
321
+ declare function isSignedVersion(doc: DocumentVersions, version?: number): boolean;
322
+ declare class MarkupDownloadError extends Error {
323
+ readonly status?: number | undefined;
324
+ constructor(message: string, status?: number | undefined);
325
+ }
326
+ /** Whether a document's current version has markup (per its version entries). */
327
+ declare function currentHasMarkup(doc: DocumentVersions): boolean;
328
+ /** Fetch a version's markup PDF (default: the current version's). */
329
+ declare function fetchMarkupPdf(client: DocumentToolsClient, documentId: string, version?: number): Promise<{
330
+ blob: Blob;
331
+ fileName: string;
332
+ }>;
333
+
334
+ declare const SIGNED_UNCHANGED = "The signed PDF is unchanged: the comments are kept beside it as markup.";
335
+ interface MarkupDocument {
336
+ external_id: string;
337
+ shared?: boolean | null;
338
+ current_version?: number | null;
339
+ versions?: VersionInfo[] | null;
340
+ }
341
+ interface LegacyPrompt {
342
+ count: number;
343
+ busy: boolean;
344
+ add: () => void;
345
+ discard: () => void;
346
+ }
347
+ interface OlderMarkupNote {
348
+ version: number;
349
+ busy: boolean;
350
+ /** The current version is a signed copy: say that copying leaves its signed PDF as it is. */
351
+ signed: boolean;
352
+ copy: () => void;
353
+ }
354
+ declare function useDocumentMarkup(documentData: MarkupDocument | null | undefined,
355
+ /** The version on screen when it is an older one (a read-only snapshot). */
356
+ snapshotVersion: number | undefined,
357
+ /**
358
+ * Whether the version on screen is a signed, sealed copy: locked, so no "Download with markup"
359
+ * (and, for the current version, copied comments leave its signed PDF as it is).
360
+ */
361
+ currentSigned?: boolean): {
362
+ hasMarkup: boolean;
363
+ showOriginal: boolean;
364
+ setShowOriginal: React.Dispatch<React.SetStateAction<boolean>>;
365
+ onMarkupChange: (snapshot: MarkupSnapshot) => void;
366
+ downloadMarkup: () => Promise<void>;
367
+ legacyPrompt: LegacyPrompt | null;
368
+ olderNote: OlderMarkupNote | null;
369
+ };
370
+
371
+ /**
372
+ * Saving a frozen copy: a SEPARATE document derived from the version it was frozen from
373
+ * (`derived_from`, role `redaction` or `annotated`), never a new version of it. The original keeps
374
+ * its place in every list and stays the current version; the copy sits beside it, in the same
375
+ * folder and with the same workspace sharing.
376
+ */
377
+
378
+ interface FrozenCopySource {
379
+ /** The version on screen, which the copy is derived from. */
380
+ documentId: string;
381
+ fileName: string | null | undefined;
382
+ shared: boolean;
383
+ folder?: string | null;
384
+ }
385
+ /** "Contract.pdf" becomes "Contract (redacted).pdf"; a .txt or .docx keeps its extension inside. */
386
+ declare function frozenCopyName(fileName: string | null | undefined, redacted: boolean): string;
387
+ declare function redactionLogName(fileName: string | null | undefined): string;
388
+ /** Upload the frozen bytes as a new document derived from `source`; returns its id, if any. */
389
+ declare function uploadFrozenCopy(upload: NonNullable<DocumentToolsEnvironment['uploadDocument']>, bytes: Uint8Array, source: FrozenCopySource, redacted: boolean): Promise<string | undefined>;
390
+
391
+ /**
392
+ * Whether the document on screen can be annotated: only a PDF the viewer is actually showing.
393
+ * Text and Word files are shown as a PDF too, so they qualify; images, audio, video, files that
394
+ * cannot be previewed, drafts and streaming output do not, and neither does a read-only snapshot
395
+ * or a comparison.
396
+ */
397
+ interface AnnotatableState {
398
+ activeTab: string;
399
+ /** The PDF bytes have been fetched. */
400
+ hasPdf: boolean;
401
+ isImage: boolean;
402
+ isVideo: boolean;
403
+ isAudio: boolean;
404
+ isDownloadOnly: boolean;
405
+ isDraft: boolean;
406
+ isStreaming: boolean;
407
+ isSnapshot: boolean;
408
+ isComparing: boolean;
409
+ }
410
+ declare function canAnnotate(s: AnnotatableState): boolean;
411
+
412
+ /**
413
+ * Reactive connectivity from React Query's `onlineManager` (the browser's online events, plus
414
+ * whatever the host feeds it, e.g. a WebSocket). The markup autosave waits while it is false.
415
+ */
416
+ declare function useIsOnline(): boolean;
417
+
418
+ /**
419
+ * Who signs: the name only. A role, a firm or a place go on the page as ordinary annotation text,
420
+ * which is not part of the signature.
421
+ */
422
+ type SignerDetails = components['schemas']['SignerDetails'];
423
+ /** Same sentence as `esign.intent_text`; the dialog refuses to sign if the server's differs. */
424
+ declare function intentText(signer: SignerDetails): string;
425
+ declare function sha256Hex(blob: Blob): Promise<string>;
426
+ /** A signature box drawn on the annotation overlay, as the signing API's placement. */
427
+ declare function toAppearance(box: {
428
+ page: number;
429
+ rect: {
430
+ x: number;
431
+ y: number;
432
+ w: number;
433
+ h: number;
434
+ };
435
+ }): {
436
+ page: number;
437
+ x: number;
438
+ y: number;
439
+ width: number;
440
+ height: number;
441
+ };
442
+ declare function isLegibleSignatureBox(rect: {
443
+ w: number;
444
+ h: number;
445
+ }): boolean;
446
+ type SignatureAppearance = components['schemas']['SignatureAppearance'];
447
+ type SignatureStatusResponse = components['schemas']['SignatureStatusResponse'];
448
+ type SignatureRecord = components['schemas']['SignatureRecord'];
449
+ type SignDocumentResponse = components['schemas']['SignDocumentResponse'];
450
+ /** Whether a document version is a signed copy, and its signatures. */
451
+ declare function fetchDocumentSignatures(client: DocumentToolsClient, documentRef: string): Promise<SignatureStatusResponse>;
452
+ /**
453
+ * Is a document version a signed copy? `documentId` is a document id (its current version) or a
454
+ * version reference `doc-…@v{n}`. Needs a React Query `QueryClientProvider`.
455
+ */
456
+ declare function useDocumentSignatures(documentId: string | null | undefined, enabled?: boolean): _tanstack_react_query.UseQueryResult<NoInfer<{
457
+ signed: boolean;
458
+ intact: boolean;
459
+ timestamped: boolean;
460
+ certificate_url?: string | null;
461
+ signatures: components["schemas"]["SignatureRecord"][];
462
+ }>, Error>;
463
+ interface SignDocumentVars {
464
+ documentId: string;
465
+ /** The PDF bytes the viewer is showing: the signer signs exactly these. */
466
+ pdfBlob: Blob;
467
+ email: string;
468
+ password: string;
469
+ signer: SignerDetails;
470
+ /** Where the signature goes; omitted = the backend default (bottom of the last page). */
471
+ appearance?: SignatureAppearance;
472
+ /** Draw the signing date under the signature. Default off: only the signature is drawn. */
473
+ includeDate?: boolean;
474
+ }
475
+ /**
476
+ * Sign a document: the server prepares the statement, the browser checks that it covers the PDF
477
+ * on screen under the wording the signer read, re-derives the user's Ed25519 key from their
478
+ * password and signs it, and the server seals the signed copy as a new version.
479
+ *
480
+ * What is drawn on the page is only the signature (the signer's name as the signature mark) and,
481
+ * with `includeDate`, the date; anyone can click it to open its certificate. A role, a firm or a
482
+ * place go on the page as ordinary annotation text, which is not part of the signature.
483
+ */
484
+ declare function signDocument(client: DocumentToolsClient, deploymentDomain: string, { documentId, pdfBlob, email, password, signer, appearance, includeDate, }: SignDocumentVars): Promise<SignDocumentResponse>;
485
+ /** The signing mutation. On success the host hears the document changed (`'signed'`). */
486
+ declare function useSignDocument(): _tanstack_react_query.UseMutationResult<{
487
+ doc_ext_id: string;
488
+ version: number;
489
+ signature: components["schemas"]["SignatureRecord"];
490
+ }, Error, SignDocumentVars, unknown>;
491
+
492
+ declare const VERIFY_PATH = "/v1/sign/verify/{reference}";
493
+ type SignatureVerification = components['schemas']['SignatureVerification'];
494
+ type VerifiedSignature = components['schemas']['VerifiedSignature'];
495
+ declare function isSignatureReference(reference: string | null | undefined): boolean;
496
+ declare class SignatureVerificationError extends Error {
497
+ readonly status?: number | undefined;
498
+ constructor(message: string, status?: number | undefined);
499
+ }
500
+ declare function fetchSignatureVerification(client: DocumentToolsClient, reference: string): Promise<SignatureVerification>;
501
+ /** The certificate of a signature reference. Needs a `<DocumentToolsProvider>` (no user). */
502
+ declare function useSignatureVerification(reference: string | null | undefined): _tanstack_react_query.UseQueryResult<NoInfer<{
503
+ signatures: components["schemas"]["VerifiedSignature"][];
504
+ document_sha256: string;
505
+ intact: boolean;
506
+ }>, Error>;
507
+ /**
508
+ * What a copy is: the signed document as it stands (`current`), the document as it was when an
509
+ * earlier signer signed it (`earlier`, a counter-signed PDF's earlier revision), or neither.
510
+ */
511
+ type CopyMatch = {
512
+ kind: 'current';
513
+ } | {
514
+ kind: 'earlier';
515
+ signature: VerifiedSignature;
516
+ } | {
517
+ kind: 'none';
518
+ };
519
+ /** Compare a file with the signed PDF and its signed revisions. Hashed here; nothing is uploaded. */
520
+ declare function matchSignedCopy(file: Blob, verification: Pick<SignatureVerification, 'document_sha256' | 'signatures'>): Promise<CopyMatch>;
521
+
522
+ export { type AnnotatableState, type BuildProductionOptions, type BuiltProduction, type CopyMatch, type DocumentChange, DocumentFetchError, type DocumentFetchOptions, type DocumentToolsClient, type DocumentToolsEnvironment, type DocumentToolsNoticeKind, type DocumentToolsNoticeOptions, type DocumentToolsNotify, DocumentToolsProvider, type DocumentToolsProviderProps, type DocumentToolsUser, type DocumentUploadQuery, type DocumentUploadRequest, type FrozenCopySource, LEGACY_LAYER_PREFIX, type LegacyPrompt, MAX_MERGE_ATTEMPTS, type MarkupDocument, MarkupDownloadError, type MarkupSnapshot, type MarkupStore, MarkupStoreError, type MarkupStoreOptions, type OlderMarkupNote, PRODUCTIONS_FOLDER, type ProductionSource, type ProductionUpload, type ResolvedDocumentToolsEnvironment, SIGNED_LOCKED_REASON, SIGNED_UNCHANGED, type SignDocumentResponse, type SignDocumentVars, type SignatureAppearance, type SignatureRecord, type SignatureStatusResponse, type SignatureVerification, SignatureVerificationError, type SignerDetails, VERIFY_PATH, type VerifiedSignature, type VersionInfo, addToMarkup, buildProduction, canAnnotate, certificateLink, clientUpload, copyOpenThreads, createMarkupStore, currentHasMarkup, defaultCertificateUrl, downloadBlob, fetchDocumentFile, fetchDocumentPdf, fetchDocumentSignatures, fetchMarkupPdf, fetchProductionPdf, fetchSignatureVerification, forgetLegacyLayer, frozenCopyName, hasNoRendition, intentText, isLegibleSignatureBox, isPdfDocument, isSignatureReference, isSignedVersion, marksByVersion, matchSignedCopy, migrateLegacyLayer, openThreadsOf, productionDocumentName, productionFileName, productionFolder, productionIndexCsv, productionTitle, readLegacyLayer, redactionLogName, saveProductionFiles, sha256Hex, signDocument, toAppearance, uploadFrozenCopy, uploadQueryString, useDocumentMarkup, useDocumentSignatures, useDocumentTools, useIsOnline, useOptionalDocumentTools, useSignDocument, useSignatureVerification, versionsWithMarkup };