@arbidocs/react 0.4.4 → 0.4.5
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/README.md +11 -0
- package/dist/artifacts/index.cjs +458 -0
- package/dist/artifacts/index.cjs.map +1 -0
- package/dist/artifacts/index.d.cts +276 -0
- package/dist/artifacts/index.d.ts +276 -0
- package/dist/artifacts/index.js +434 -0
- package/dist/artifacts/index.js.map +1 -0
- package/dist/artifacts/redline-core.cjs +20 -0
- package/dist/artifacts/redline-core.cjs.map +1 -0
- package/dist/artifacts/redline-core.d.cts +36 -0
- package/dist/artifacts/redline-core.d.ts +36 -0
- package/dist/artifacts/redline-core.js +3 -0
- package/dist/artifacts/redline-core.js.map +1 -0
- package/dist/chunk-2DXS7L7M.cjs +302 -0
- package/dist/chunk-2DXS7L7M.cjs.map +1 -0
- package/dist/{chunk-ORKGCXG3.cjs → chunk-7BDGLRQX.cjs} +123 -427
- package/dist/chunk-7BDGLRQX.cjs.map +1 -0
- package/dist/chunk-7V7B7OEM.cjs +318 -0
- package/dist/chunk-7V7B7OEM.cjs.map +1 -0
- package/dist/{chunk-MIJRORQL.js → chunk-DVRJFLE7.js} +8 -302
- package/dist/chunk-DVRJFLE7.js.map +1 -0
- package/dist/{chunk-EJ2BMHYK.js → chunk-FSMIN5VX.js} +4 -3
- package/dist/chunk-FSMIN5VX.js.map +1 -0
- package/dist/chunk-H7ZZQ4ZV.js +305 -0
- package/dist/chunk-H7ZZQ4ZV.js.map +1 -0
- package/dist/{chunk-JKO3NR5L.js → chunk-HDCRPPBW.js} +5 -23
- package/dist/chunk-HDCRPPBW.js.map +1 -0
- package/dist/chunk-J4MX2W4H.js +26 -0
- package/dist/chunk-J4MX2W4H.js.map +1 -0
- package/dist/{chunk-6ALMBER7.js → chunk-N5SVBDLC.js} +4 -9
- package/dist/chunk-N5SVBDLC.js.map +1 -0
- package/dist/{chunk-RZQACYNQ.cjs → chunk-OBNTJEEO.cjs} +14 -20
- package/dist/chunk-OBNTJEEO.cjs.map +1 -0
- package/dist/{chunk-BXP6S34V.cjs → chunk-PGLV23SB.cjs} +13 -12
- package/dist/chunk-PGLV23SB.cjs.map +1 -0
- package/dist/chunk-RKWNX32A.js +299 -0
- package/dist/chunk-RKWNX32A.js.map +1 -0
- package/dist/chunk-S6A6FSG7.cjs +13 -0
- package/dist/chunk-S6A6FSG7.cjs.map +1 -0
- package/dist/chunk-SN5YV6FF.js +11 -0
- package/dist/chunk-SN5YV6FF.js.map +1 -0
- package/dist/{chunk-7IOCMCC5.cjs → chunk-TMPDW7J5.cjs} +3 -23
- package/dist/chunk-TMPDW7J5.cjs.map +1 -0
- package/dist/chunk-VJWAP2HJ.cjs +303 -0
- package/dist/chunk-VJWAP2HJ.cjs.map +1 -0
- package/dist/chunk-ZMTLGO3K.cjs +29 -0
- package/dist/chunk-ZMTLGO3K.cjs.map +1 -0
- package/dist/chunk-ZY53R6I4.js +276 -0
- package/dist/chunk-ZY53R6I4.js.map +1 -0
- package/dist/index.cjs +497 -690
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -282
- package/dist/index.js.map +1 -1
- package/dist/shell/index.cjs +8 -7
- package/dist/shell/index.js +3 -2
- package/dist/ui/index.cjs +156 -154
- package/dist/ui/index.js +4 -2
- package/dist/viewers/index.cjs +9 -8
- package/dist/viewers/index.cjs.map +1 -1
- package/dist/viewers/index.js +3 -2
- package/dist/viewers/index.js.map +1 -1
- package/package.json +19 -3
- package/dist/chunk-6ALMBER7.js.map +0 -1
- package/dist/chunk-7IOCMCC5.cjs.map +0 -1
- package/dist/chunk-BXP6S34V.cjs.map +0 -1
- package/dist/chunk-EJ2BMHYK.js.map +0 -1
- package/dist/chunk-JKO3NR5L.js.map +0 -1
- package/dist/chunk-MIJRORQL.js.map +0 -1
- package/dist/chunk-ORKGCXG3.cjs.map +0 -1
- package/dist/chunk-RZQACYNQ.cjs.map +0 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { RedlineWithRegions, RedlineRegion } from './redline-core.cjs';
|
|
2
|
+
export { RegionKind, buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion } from './redline-core.cjs';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { FC, ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a redline is computed. The default runs on the calling thread; a host with large
|
|
8
|
+
* documents passes an engine backed by a Web Worker (for example a Comlink proxy exposing the same
|
|
9
|
+
* three functions) so typing never waits on a diff.
|
|
10
|
+
*/
|
|
11
|
+
interface RedlineEngine {
|
|
12
|
+
buildRedline(baseText: string, compareText: string): string | Promise<string>;
|
|
13
|
+
buildRedlineWithRegions(baseText: string, compareText: string): RedlineWithRegions | Promise<RedlineWithRegions>;
|
|
14
|
+
revertRegion(baseText: string, compareText: string, regionId: string): string | Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
/** Main-thread engine: the pure functions of `redline-diff`. */
|
|
17
|
+
declare const mainThreadRedlineEngine: RedlineEngine;
|
|
18
|
+
|
|
19
|
+
/** What a redline view can show. Mirrors the status parts of `@arbidocs/blocks/artifacts`. */
|
|
20
|
+
type RedlineState = {
|
|
21
|
+
kind: 'idle';
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'computing';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'ready';
|
|
26
|
+
markdown: string;
|
|
27
|
+
regions: RedlineRegion[];
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'identical';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'unavailable';
|
|
32
|
+
};
|
|
33
|
+
interface UseRedlineOptions {
|
|
34
|
+
/** The older side. `null` means the text could not be loaded; `undefined` means not chosen. */
|
|
35
|
+
baseText: string | null | undefined;
|
|
36
|
+
/** The newer side (a loaded version, or the live edit buffer). */
|
|
37
|
+
compareText: string | null | undefined;
|
|
38
|
+
/** Either text is still being fetched. */
|
|
39
|
+
isLoading?: boolean;
|
|
40
|
+
/** Tag every change with a stable id so a view can offer per-change undo. */
|
|
41
|
+
withRegions?: boolean;
|
|
42
|
+
/** Defaults to the main thread; pass a worker-backed engine for big documents. */
|
|
43
|
+
engine?: RedlineEngine;
|
|
44
|
+
}
|
|
45
|
+
interface UseRedlineResult {
|
|
46
|
+
state: RedlineState;
|
|
47
|
+
/** Undo one change: resolves with the compare text rebuilt without it (null if nothing changed). */
|
|
48
|
+
revertRegion: (regionId: string) => Promise<string | null>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Track-changes between two texts. Stale results are dropped when the inputs change mid-compute,
|
|
52
|
+
* and a failed diff reports `unavailable` instead of throwing into the render.
|
|
53
|
+
*/
|
|
54
|
+
declare function useRedline({ baseText, compareText, isLoading, withRegions, engine, }: UseRedlineOptions): UseRedlineResult;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Version lineage of an artifact. Every save creates a NEW document whose `parent_ext_id` is the
|
|
58
|
+
* version it was saved from, so a lineage is a tree (a save from an old version is a deliberate
|
|
59
|
+
* branch). Computed from a document list the host already has; no extra request.
|
|
60
|
+
*/
|
|
61
|
+
/** The fields of a workspace document the lineage needs (structurally a subset of the API type). */
|
|
62
|
+
interface VersionedDoc {
|
|
63
|
+
external_id?: string | null;
|
|
64
|
+
parent_ext_id?: string | null;
|
|
65
|
+
file_name?: string | null;
|
|
66
|
+
created_at?: string | null;
|
|
67
|
+
}
|
|
68
|
+
/** One row of a version list. Matches `VersionEntry` of `@arbidocs/blocks/artifacts`. */
|
|
69
|
+
interface ArtifactVersion {
|
|
70
|
+
id: string;
|
|
71
|
+
/** File name as stored. */
|
|
72
|
+
name: string;
|
|
73
|
+
/** ISO timestamp. */
|
|
74
|
+
createdAt: string;
|
|
75
|
+
/** The version this one was saved from. */
|
|
76
|
+
parentId?: string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The whole lineage of `docId` (root first, then oldest to newest), or `[]` when the document is
|
|
80
|
+
* not in `docs`. Cycle-safe.
|
|
81
|
+
*/
|
|
82
|
+
declare function buildVersionChain<T extends VersionedDoc>(docs: readonly T[], docId: string | null | undefined): T[];
|
|
83
|
+
/** The lineage of `docId` as plain version rows. */
|
|
84
|
+
declare function toArtifactVersions(chain: readonly VersionedDoc[]): ArtifactVersion[];
|
|
85
|
+
/**
|
|
86
|
+
* "v2": the 1-based position of `docId` in its lineage. `null` when there is nothing to tell apart
|
|
87
|
+
* (the lineage is just this document, or it is unknown), so unversioned documents stay unlabelled.
|
|
88
|
+
*/
|
|
89
|
+
declare function versionLabel(versions: readonly ArtifactVersion[], docId: string | null | undefined): string | null;
|
|
90
|
+
/** Join parsed chunks into one markdown text (blank line between chunks). */
|
|
91
|
+
declare function flattenChunks(chunks: readonly {
|
|
92
|
+
content?: string | null;
|
|
93
|
+
}[] | null | undefined): string;
|
|
94
|
+
|
|
95
|
+
/** What a save reports back. `docId` is the new version when the backend already knows it. */
|
|
96
|
+
interface ArtifactSaveResult {
|
|
97
|
+
docId?: string;
|
|
98
|
+
}
|
|
99
|
+
interface ArtifactEditSessionOptions {
|
|
100
|
+
/** The artifact being edited. Changing it discards the buffer and any comparison. */
|
|
101
|
+
docId: string | null | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The saved text of the open version. `undefined` while it loads; whenever it changes the
|
|
104
|
+
* baseline follows it (a version arriving from the realtime channel, a finished stream).
|
|
105
|
+
*/
|
|
106
|
+
baseline: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* A new document the user types from scratch: open straight in the editor, seeded with
|
|
109
|
+
* `initialContent`, instead of showing a read-only view. Read when `docId` changes.
|
|
110
|
+
*/
|
|
111
|
+
startEditing?: boolean;
|
|
112
|
+
initialContent?: string;
|
|
113
|
+
/** The version this one was saved from. Offering "compare with previous" needs it. */
|
|
114
|
+
parentId?: string | null;
|
|
115
|
+
/** Controlled comparison target. Omit for an uncontrolled one the session owns. */
|
|
116
|
+
compareId?: string | null;
|
|
117
|
+
onCompareChange?: (id: string | null) => void;
|
|
118
|
+
/** The saved text of the compare target (the older side of the diff). */
|
|
119
|
+
compareText?: string | null;
|
|
120
|
+
compareLoading?: boolean;
|
|
121
|
+
/** Starting a comparison opens the editor with track changes on (default true). */
|
|
122
|
+
compareOpensEditor?: boolean;
|
|
123
|
+
/** Persist the buffer as a NEW version. Rejecting keeps the buffer so nothing is lost. */
|
|
124
|
+
save: (content: string) => Promise<ArtifactSaveResult | void>;
|
|
125
|
+
onSaved?: (result: ArtifactSaveResult, content: string) => void;
|
|
126
|
+
onSaveError?: (error: unknown) => void;
|
|
127
|
+
/** Every buffer change (a host keeps a draft store in sync with it). */
|
|
128
|
+
onContentChange?: (content: string) => void;
|
|
129
|
+
/** The unsaved-changes flag, for a host that warns before a panel is closed. */
|
|
130
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
131
|
+
/** Where the diff runs. Defaults to the main thread. */
|
|
132
|
+
redlineEngine?: RedlineEngine;
|
|
133
|
+
/** Typing is never debounced; the diff trails the buffer by this long. Default 300ms. */
|
|
134
|
+
diffDelayMs?: number;
|
|
135
|
+
}
|
|
136
|
+
interface ArtifactEditSession {
|
|
137
|
+
isEditing: boolean;
|
|
138
|
+
/** The saved text of the open version. */
|
|
139
|
+
baseline: string;
|
|
140
|
+
/** The text in the editor (the baseline until the first edit). */
|
|
141
|
+
content: string;
|
|
142
|
+
hasChanges: boolean;
|
|
143
|
+
isSaving: boolean;
|
|
144
|
+
canCompare: boolean;
|
|
145
|
+
compareId: string | null;
|
|
146
|
+
showTrackChanges: boolean;
|
|
147
|
+
/** Track changes between the compare target and the (debounced) buffer. */
|
|
148
|
+
redline: UseRedlineResult;
|
|
149
|
+
startEdit: () => void;
|
|
150
|
+
/** Discard the buffer and any comparison; back to the rendered view. */
|
|
151
|
+
cancel: () => void;
|
|
152
|
+
/** Save the buffer as a new version. Resolves false when it failed (the buffer is kept). */
|
|
153
|
+
save: () => Promise<boolean>;
|
|
154
|
+
/** The editor's `onChange`; also replaces the buffer (for example after an undo-this-change). */
|
|
155
|
+
change: (markdown: string) => void;
|
|
156
|
+
/** The editor's `onNormalized`: adopt its canonical form as the baseline so Save does not fire. */
|
|
157
|
+
normalized: (markdown: string) => void;
|
|
158
|
+
/** Compare with the previous version (when no id is given). */
|
|
159
|
+
compare: (id?: string) => void;
|
|
160
|
+
stopCompare: () => void;
|
|
161
|
+
setShowTrackChanges: (show: boolean) => void;
|
|
162
|
+
/** Undo one tracked change in the buffer. */
|
|
163
|
+
revertRegion: (regionId: string) => Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The state machine of an artifact edit session, with no SDK and no network: the edit buffer and
|
|
167
|
+
* its baseline, the dirty flag, immutable-version saves and a track-changes comparison. A host
|
|
168
|
+
* supplies the saved text and a `save` function (see `useArtifactSession` for the SDK binding).
|
|
169
|
+
*/
|
|
170
|
+
declare function useArtifactEditSession(options: ArtifactEditSessionOptions): ArtifactEditSession;
|
|
171
|
+
|
|
172
|
+
/** The saved markdown of a document (its parsed chunks, joined). */
|
|
173
|
+
declare function useArtifactText(docId: string | null | undefined, options?: {
|
|
174
|
+
enabled?: boolean;
|
|
175
|
+
}): {
|
|
176
|
+
text: string | null | undefined;
|
|
177
|
+
isLoading: boolean;
|
|
178
|
+
};
|
|
179
|
+
/** The version lineage of an artifact in a workspace, oldest first. */
|
|
180
|
+
declare function useArtifactVersions(workspaceId: string | undefined, docId: string | null | undefined): ArtifactVersion[];
|
|
181
|
+
interface SaveArtifactVersionInput {
|
|
182
|
+
/** File name of the new version (`.md` is added when missing). */
|
|
183
|
+
title: string;
|
|
184
|
+
content: string;
|
|
185
|
+
/** The version this one is saved from; omit for a first version. */
|
|
186
|
+
parentId?: string | null;
|
|
187
|
+
/** The processing config (auto-title, parsing) to run the upload with. */
|
|
188
|
+
configId?: string | null;
|
|
189
|
+
/** `artifact` (default) for AI-style drafts; `source` for a document the user typed. */
|
|
190
|
+
wpType?: 'artifact' | 'source';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Save markdown as a NEW immutable version (a child document of `parentId`) and refresh the
|
|
194
|
+
* workspace document list so the version list picks it up. The id of the new version is often not
|
|
195
|
+
* known yet (the document is parsed asynchronously); it then arrives through the list.
|
|
196
|
+
*/
|
|
197
|
+
declare function useSaveArtifactVersion(): _tanstack_react_query.UseMutationResult<ArtifactSaveResult, Error, SaveArtifactVersionInput & {
|
|
198
|
+
workspaceId?: string;
|
|
199
|
+
}, unknown>;
|
|
200
|
+
interface ArtifactSessionOptions extends Pick<ArtifactEditSessionOptions, 'onSaved' | 'onSaveError' | 'onCompareChange' | 'compareId' | 'compareOpensEditor' | 'redlineEngine' | 'onDirtyChange'> {
|
|
201
|
+
workspaceId: string | undefined;
|
|
202
|
+
/** The open version. */
|
|
203
|
+
docId: string | null | undefined;
|
|
204
|
+
/** Name for saved versions. Defaults to the open version's file name, else "Untitled". */
|
|
205
|
+
title?: string;
|
|
206
|
+
/** Processing config for saved versions. */
|
|
207
|
+
configId?: string | null;
|
|
208
|
+
}
|
|
209
|
+
/** Everything `ArtifactEditor` (`@arbidocs/blocks/artifacts`) takes from a session, flat. */
|
|
210
|
+
interface ArtifactSessionView {
|
|
211
|
+
content: string;
|
|
212
|
+
isEditing: boolean;
|
|
213
|
+
hasChanges: boolean;
|
|
214
|
+
isSaving: boolean;
|
|
215
|
+
canCompare: boolean;
|
|
216
|
+
comparing: boolean;
|
|
217
|
+
compareId: string | null;
|
|
218
|
+
showTrackChanges: boolean;
|
|
219
|
+
versions: ArtifactVersion[];
|
|
220
|
+
currentVersionId: string;
|
|
221
|
+
onStartEdit: () => void;
|
|
222
|
+
onCancel: () => void;
|
|
223
|
+
onSave: () => void;
|
|
224
|
+
onCompare: () => void;
|
|
225
|
+
onStopCompare: () => void;
|
|
226
|
+
onToggleTrackChanges: () => void;
|
|
227
|
+
}
|
|
228
|
+
interface ArtifactSession extends ArtifactEditSession {
|
|
229
|
+
isLoading: boolean;
|
|
230
|
+
versions: ArtifactVersion[];
|
|
231
|
+
/** "v2" for any version in the lineage. */
|
|
232
|
+
labelOf: (id: string | null | undefined) => string | null;
|
|
233
|
+
/** Props for `<ArtifactEditor>`. */
|
|
234
|
+
view: ArtifactSessionView;
|
|
235
|
+
/** Props for `<ArtifactMarkdownEditor>` (`@arbidocs/blocks/artifacts/editor`). */
|
|
236
|
+
editorProps: {
|
|
237
|
+
markdown: string;
|
|
238
|
+
onChange: (markdown: string) => void;
|
|
239
|
+
onNormalized: (markdown: string) => void;
|
|
240
|
+
};
|
|
241
|
+
/** Props for `<ArtifactRedlineView>`. */
|
|
242
|
+
redlineProps: {
|
|
243
|
+
state: ArtifactEditSession['redline']['state'];
|
|
244
|
+
onRevert: (regionId: string) => void;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Edit an artifact through the SDK: load it, edit it, save it as a new version, list its versions
|
|
249
|
+
* and compare any two with track changes. Needs an `<ArbiProvider>` and a selected workspace.
|
|
250
|
+
*
|
|
251
|
+
* ```tsx
|
|
252
|
+
* const session = useArtifactSession({ workspaceId, docId, onSaved: ({ docId }) => docId && open(docId) })
|
|
253
|
+
* <ArtifactEditor {...session.view} onOpenVersion={open}
|
|
254
|
+
* editor={<ArtifactMarkdownEditor {...session.editorProps} />}
|
|
255
|
+
* redline={<ArtifactRedlineView {...session.redlineProps} />} />
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function useArtifactSession(options: ArtifactSessionOptions): ArtifactSession;
|
|
259
|
+
|
|
260
|
+
/** The `<del>` / `<ins>` renderers `ArtifactRedlineView` hands to a markdown renderer. */
|
|
261
|
+
interface ArtifactRedlineComponents {
|
|
262
|
+
del: FC<ComponentPropsWithoutRef<'del'> & {
|
|
263
|
+
'data-cid'?: string;
|
|
264
|
+
}>;
|
|
265
|
+
ins: FC<ComponentPropsWithoutRef<'ins'> & {
|
|
266
|
+
'data-cid'?: string;
|
|
267
|
+
}>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The kit's markdown renderer as the `renderMarkdown` slot of `ArtifactEditor` and
|
|
271
|
+
* `ArtifactRedlineView`: full markdown (tables, lists, code) plus the raw `<del>` / `<ins>` tags
|
|
272
|
+
* of a redline.
|
|
273
|
+
*/
|
|
274
|
+
declare function renderArtifactMarkdown(markdown: string, components?: ArtifactRedlineComponents): ReactNode;
|
|
275
|
+
|
|
276
|
+
export { type ArtifactEditSession, type ArtifactEditSessionOptions, type ArtifactRedlineComponents, type ArtifactSaveResult, type ArtifactSession, type ArtifactSessionOptions, type ArtifactSessionView, type ArtifactVersion, type RedlineEngine, RedlineRegion, type RedlineState, RedlineWithRegions, type SaveArtifactVersionInput, type UseRedlineOptions, type UseRedlineResult, type VersionedDoc, buildVersionChain, flattenChunks, mainThreadRedlineEngine, renderArtifactMarkdown, toArtifactVersions, useArtifactEditSession, useArtifactSession, useArtifactText, useArtifactVersions, useRedline, useSaveArtifactVersion, versionLabel };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { RedlineWithRegions, RedlineRegion } from './redline-core.js';
|
|
2
|
+
export { RegionKind, buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion } from './redline-core.js';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { FC, ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a redline is computed. The default runs on the calling thread; a host with large
|
|
8
|
+
* documents passes an engine backed by a Web Worker (for example a Comlink proxy exposing the same
|
|
9
|
+
* three functions) so typing never waits on a diff.
|
|
10
|
+
*/
|
|
11
|
+
interface RedlineEngine {
|
|
12
|
+
buildRedline(baseText: string, compareText: string): string | Promise<string>;
|
|
13
|
+
buildRedlineWithRegions(baseText: string, compareText: string): RedlineWithRegions | Promise<RedlineWithRegions>;
|
|
14
|
+
revertRegion(baseText: string, compareText: string, regionId: string): string | Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
/** Main-thread engine: the pure functions of `redline-diff`. */
|
|
17
|
+
declare const mainThreadRedlineEngine: RedlineEngine;
|
|
18
|
+
|
|
19
|
+
/** What a redline view can show. Mirrors the status parts of `@arbidocs/blocks/artifacts`. */
|
|
20
|
+
type RedlineState = {
|
|
21
|
+
kind: 'idle';
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'computing';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'ready';
|
|
26
|
+
markdown: string;
|
|
27
|
+
regions: RedlineRegion[];
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'identical';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'unavailable';
|
|
32
|
+
};
|
|
33
|
+
interface UseRedlineOptions {
|
|
34
|
+
/** The older side. `null` means the text could not be loaded; `undefined` means not chosen. */
|
|
35
|
+
baseText: string | null | undefined;
|
|
36
|
+
/** The newer side (a loaded version, or the live edit buffer). */
|
|
37
|
+
compareText: string | null | undefined;
|
|
38
|
+
/** Either text is still being fetched. */
|
|
39
|
+
isLoading?: boolean;
|
|
40
|
+
/** Tag every change with a stable id so a view can offer per-change undo. */
|
|
41
|
+
withRegions?: boolean;
|
|
42
|
+
/** Defaults to the main thread; pass a worker-backed engine for big documents. */
|
|
43
|
+
engine?: RedlineEngine;
|
|
44
|
+
}
|
|
45
|
+
interface UseRedlineResult {
|
|
46
|
+
state: RedlineState;
|
|
47
|
+
/** Undo one change: resolves with the compare text rebuilt without it (null if nothing changed). */
|
|
48
|
+
revertRegion: (regionId: string) => Promise<string | null>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Track-changes between two texts. Stale results are dropped when the inputs change mid-compute,
|
|
52
|
+
* and a failed diff reports `unavailable` instead of throwing into the render.
|
|
53
|
+
*/
|
|
54
|
+
declare function useRedline({ baseText, compareText, isLoading, withRegions, engine, }: UseRedlineOptions): UseRedlineResult;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Version lineage of an artifact. Every save creates a NEW document whose `parent_ext_id` is the
|
|
58
|
+
* version it was saved from, so a lineage is a tree (a save from an old version is a deliberate
|
|
59
|
+
* branch). Computed from a document list the host already has; no extra request.
|
|
60
|
+
*/
|
|
61
|
+
/** The fields of a workspace document the lineage needs (structurally a subset of the API type). */
|
|
62
|
+
interface VersionedDoc {
|
|
63
|
+
external_id?: string | null;
|
|
64
|
+
parent_ext_id?: string | null;
|
|
65
|
+
file_name?: string | null;
|
|
66
|
+
created_at?: string | null;
|
|
67
|
+
}
|
|
68
|
+
/** One row of a version list. Matches `VersionEntry` of `@arbidocs/blocks/artifacts`. */
|
|
69
|
+
interface ArtifactVersion {
|
|
70
|
+
id: string;
|
|
71
|
+
/** File name as stored. */
|
|
72
|
+
name: string;
|
|
73
|
+
/** ISO timestamp. */
|
|
74
|
+
createdAt: string;
|
|
75
|
+
/** The version this one was saved from. */
|
|
76
|
+
parentId?: string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The whole lineage of `docId` (root first, then oldest to newest), or `[]` when the document is
|
|
80
|
+
* not in `docs`. Cycle-safe.
|
|
81
|
+
*/
|
|
82
|
+
declare function buildVersionChain<T extends VersionedDoc>(docs: readonly T[], docId: string | null | undefined): T[];
|
|
83
|
+
/** The lineage of `docId` as plain version rows. */
|
|
84
|
+
declare function toArtifactVersions(chain: readonly VersionedDoc[]): ArtifactVersion[];
|
|
85
|
+
/**
|
|
86
|
+
* "v2": the 1-based position of `docId` in its lineage. `null` when there is nothing to tell apart
|
|
87
|
+
* (the lineage is just this document, or it is unknown), so unversioned documents stay unlabelled.
|
|
88
|
+
*/
|
|
89
|
+
declare function versionLabel(versions: readonly ArtifactVersion[], docId: string | null | undefined): string | null;
|
|
90
|
+
/** Join parsed chunks into one markdown text (blank line between chunks). */
|
|
91
|
+
declare function flattenChunks(chunks: readonly {
|
|
92
|
+
content?: string | null;
|
|
93
|
+
}[] | null | undefined): string;
|
|
94
|
+
|
|
95
|
+
/** What a save reports back. `docId` is the new version when the backend already knows it. */
|
|
96
|
+
interface ArtifactSaveResult {
|
|
97
|
+
docId?: string;
|
|
98
|
+
}
|
|
99
|
+
interface ArtifactEditSessionOptions {
|
|
100
|
+
/** The artifact being edited. Changing it discards the buffer and any comparison. */
|
|
101
|
+
docId: string | null | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The saved text of the open version. `undefined` while it loads; whenever it changes the
|
|
104
|
+
* baseline follows it (a version arriving from the realtime channel, a finished stream).
|
|
105
|
+
*/
|
|
106
|
+
baseline: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* A new document the user types from scratch: open straight in the editor, seeded with
|
|
109
|
+
* `initialContent`, instead of showing a read-only view. Read when `docId` changes.
|
|
110
|
+
*/
|
|
111
|
+
startEditing?: boolean;
|
|
112
|
+
initialContent?: string;
|
|
113
|
+
/** The version this one was saved from. Offering "compare with previous" needs it. */
|
|
114
|
+
parentId?: string | null;
|
|
115
|
+
/** Controlled comparison target. Omit for an uncontrolled one the session owns. */
|
|
116
|
+
compareId?: string | null;
|
|
117
|
+
onCompareChange?: (id: string | null) => void;
|
|
118
|
+
/** The saved text of the compare target (the older side of the diff). */
|
|
119
|
+
compareText?: string | null;
|
|
120
|
+
compareLoading?: boolean;
|
|
121
|
+
/** Starting a comparison opens the editor with track changes on (default true). */
|
|
122
|
+
compareOpensEditor?: boolean;
|
|
123
|
+
/** Persist the buffer as a NEW version. Rejecting keeps the buffer so nothing is lost. */
|
|
124
|
+
save: (content: string) => Promise<ArtifactSaveResult | void>;
|
|
125
|
+
onSaved?: (result: ArtifactSaveResult, content: string) => void;
|
|
126
|
+
onSaveError?: (error: unknown) => void;
|
|
127
|
+
/** Every buffer change (a host keeps a draft store in sync with it). */
|
|
128
|
+
onContentChange?: (content: string) => void;
|
|
129
|
+
/** The unsaved-changes flag, for a host that warns before a panel is closed. */
|
|
130
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
131
|
+
/** Where the diff runs. Defaults to the main thread. */
|
|
132
|
+
redlineEngine?: RedlineEngine;
|
|
133
|
+
/** Typing is never debounced; the diff trails the buffer by this long. Default 300ms. */
|
|
134
|
+
diffDelayMs?: number;
|
|
135
|
+
}
|
|
136
|
+
interface ArtifactEditSession {
|
|
137
|
+
isEditing: boolean;
|
|
138
|
+
/** The saved text of the open version. */
|
|
139
|
+
baseline: string;
|
|
140
|
+
/** The text in the editor (the baseline until the first edit). */
|
|
141
|
+
content: string;
|
|
142
|
+
hasChanges: boolean;
|
|
143
|
+
isSaving: boolean;
|
|
144
|
+
canCompare: boolean;
|
|
145
|
+
compareId: string | null;
|
|
146
|
+
showTrackChanges: boolean;
|
|
147
|
+
/** Track changes between the compare target and the (debounced) buffer. */
|
|
148
|
+
redline: UseRedlineResult;
|
|
149
|
+
startEdit: () => void;
|
|
150
|
+
/** Discard the buffer and any comparison; back to the rendered view. */
|
|
151
|
+
cancel: () => void;
|
|
152
|
+
/** Save the buffer as a new version. Resolves false when it failed (the buffer is kept). */
|
|
153
|
+
save: () => Promise<boolean>;
|
|
154
|
+
/** The editor's `onChange`; also replaces the buffer (for example after an undo-this-change). */
|
|
155
|
+
change: (markdown: string) => void;
|
|
156
|
+
/** The editor's `onNormalized`: adopt its canonical form as the baseline so Save does not fire. */
|
|
157
|
+
normalized: (markdown: string) => void;
|
|
158
|
+
/** Compare with the previous version (when no id is given). */
|
|
159
|
+
compare: (id?: string) => void;
|
|
160
|
+
stopCompare: () => void;
|
|
161
|
+
setShowTrackChanges: (show: boolean) => void;
|
|
162
|
+
/** Undo one tracked change in the buffer. */
|
|
163
|
+
revertRegion: (regionId: string) => Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The state machine of an artifact edit session, with no SDK and no network: the edit buffer and
|
|
167
|
+
* its baseline, the dirty flag, immutable-version saves and a track-changes comparison. A host
|
|
168
|
+
* supplies the saved text and a `save` function (see `useArtifactSession` for the SDK binding).
|
|
169
|
+
*/
|
|
170
|
+
declare function useArtifactEditSession(options: ArtifactEditSessionOptions): ArtifactEditSession;
|
|
171
|
+
|
|
172
|
+
/** The saved markdown of a document (its parsed chunks, joined). */
|
|
173
|
+
declare function useArtifactText(docId: string | null | undefined, options?: {
|
|
174
|
+
enabled?: boolean;
|
|
175
|
+
}): {
|
|
176
|
+
text: string | null | undefined;
|
|
177
|
+
isLoading: boolean;
|
|
178
|
+
};
|
|
179
|
+
/** The version lineage of an artifact in a workspace, oldest first. */
|
|
180
|
+
declare function useArtifactVersions(workspaceId: string | undefined, docId: string | null | undefined): ArtifactVersion[];
|
|
181
|
+
interface SaveArtifactVersionInput {
|
|
182
|
+
/** File name of the new version (`.md` is added when missing). */
|
|
183
|
+
title: string;
|
|
184
|
+
content: string;
|
|
185
|
+
/** The version this one is saved from; omit for a first version. */
|
|
186
|
+
parentId?: string | null;
|
|
187
|
+
/** The processing config (auto-title, parsing) to run the upload with. */
|
|
188
|
+
configId?: string | null;
|
|
189
|
+
/** `artifact` (default) for AI-style drafts; `source` for a document the user typed. */
|
|
190
|
+
wpType?: 'artifact' | 'source';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Save markdown as a NEW immutable version (a child document of `parentId`) and refresh the
|
|
194
|
+
* workspace document list so the version list picks it up. The id of the new version is often not
|
|
195
|
+
* known yet (the document is parsed asynchronously); it then arrives through the list.
|
|
196
|
+
*/
|
|
197
|
+
declare function useSaveArtifactVersion(): _tanstack_react_query.UseMutationResult<ArtifactSaveResult, Error, SaveArtifactVersionInput & {
|
|
198
|
+
workspaceId?: string;
|
|
199
|
+
}, unknown>;
|
|
200
|
+
interface ArtifactSessionOptions extends Pick<ArtifactEditSessionOptions, 'onSaved' | 'onSaveError' | 'onCompareChange' | 'compareId' | 'compareOpensEditor' | 'redlineEngine' | 'onDirtyChange'> {
|
|
201
|
+
workspaceId: string | undefined;
|
|
202
|
+
/** The open version. */
|
|
203
|
+
docId: string | null | undefined;
|
|
204
|
+
/** Name for saved versions. Defaults to the open version's file name, else "Untitled". */
|
|
205
|
+
title?: string;
|
|
206
|
+
/** Processing config for saved versions. */
|
|
207
|
+
configId?: string | null;
|
|
208
|
+
}
|
|
209
|
+
/** Everything `ArtifactEditor` (`@arbidocs/blocks/artifacts`) takes from a session, flat. */
|
|
210
|
+
interface ArtifactSessionView {
|
|
211
|
+
content: string;
|
|
212
|
+
isEditing: boolean;
|
|
213
|
+
hasChanges: boolean;
|
|
214
|
+
isSaving: boolean;
|
|
215
|
+
canCompare: boolean;
|
|
216
|
+
comparing: boolean;
|
|
217
|
+
compareId: string | null;
|
|
218
|
+
showTrackChanges: boolean;
|
|
219
|
+
versions: ArtifactVersion[];
|
|
220
|
+
currentVersionId: string;
|
|
221
|
+
onStartEdit: () => void;
|
|
222
|
+
onCancel: () => void;
|
|
223
|
+
onSave: () => void;
|
|
224
|
+
onCompare: () => void;
|
|
225
|
+
onStopCompare: () => void;
|
|
226
|
+
onToggleTrackChanges: () => void;
|
|
227
|
+
}
|
|
228
|
+
interface ArtifactSession extends ArtifactEditSession {
|
|
229
|
+
isLoading: boolean;
|
|
230
|
+
versions: ArtifactVersion[];
|
|
231
|
+
/** "v2" for any version in the lineage. */
|
|
232
|
+
labelOf: (id: string | null | undefined) => string | null;
|
|
233
|
+
/** Props for `<ArtifactEditor>`. */
|
|
234
|
+
view: ArtifactSessionView;
|
|
235
|
+
/** Props for `<ArtifactMarkdownEditor>` (`@arbidocs/blocks/artifacts/editor`). */
|
|
236
|
+
editorProps: {
|
|
237
|
+
markdown: string;
|
|
238
|
+
onChange: (markdown: string) => void;
|
|
239
|
+
onNormalized: (markdown: string) => void;
|
|
240
|
+
};
|
|
241
|
+
/** Props for `<ArtifactRedlineView>`. */
|
|
242
|
+
redlineProps: {
|
|
243
|
+
state: ArtifactEditSession['redline']['state'];
|
|
244
|
+
onRevert: (regionId: string) => void;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Edit an artifact through the SDK: load it, edit it, save it as a new version, list its versions
|
|
249
|
+
* and compare any two with track changes. Needs an `<ArbiProvider>` and a selected workspace.
|
|
250
|
+
*
|
|
251
|
+
* ```tsx
|
|
252
|
+
* const session = useArtifactSession({ workspaceId, docId, onSaved: ({ docId }) => docId && open(docId) })
|
|
253
|
+
* <ArtifactEditor {...session.view} onOpenVersion={open}
|
|
254
|
+
* editor={<ArtifactMarkdownEditor {...session.editorProps} />}
|
|
255
|
+
* redline={<ArtifactRedlineView {...session.redlineProps} />} />
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function useArtifactSession(options: ArtifactSessionOptions): ArtifactSession;
|
|
259
|
+
|
|
260
|
+
/** The `<del>` / `<ins>` renderers `ArtifactRedlineView` hands to a markdown renderer. */
|
|
261
|
+
interface ArtifactRedlineComponents {
|
|
262
|
+
del: FC<ComponentPropsWithoutRef<'del'> & {
|
|
263
|
+
'data-cid'?: string;
|
|
264
|
+
}>;
|
|
265
|
+
ins: FC<ComponentPropsWithoutRef<'ins'> & {
|
|
266
|
+
'data-cid'?: string;
|
|
267
|
+
}>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The kit's markdown renderer as the `renderMarkdown` slot of `ArtifactEditor` and
|
|
271
|
+
* `ArtifactRedlineView`: full markdown (tables, lists, code) plus the raw `<del>` / `<ins>` tags
|
|
272
|
+
* of a redline.
|
|
273
|
+
*/
|
|
274
|
+
declare function renderArtifactMarkdown(markdown: string, components?: ArtifactRedlineComponents): ReactNode;
|
|
275
|
+
|
|
276
|
+
export { type ArtifactEditSession, type ArtifactEditSessionOptions, type ArtifactRedlineComponents, type ArtifactSaveResult, type ArtifactSession, type ArtifactSessionOptions, type ArtifactSessionView, type ArtifactVersion, type RedlineEngine, RedlineRegion, type RedlineState, RedlineWithRegions, type SaveArtifactVersionInput, type UseRedlineOptions, type UseRedlineResult, type VersionedDoc, buildVersionChain, flattenChunks, mainThreadRedlineEngine, renderArtifactMarkdown, toArtifactVersions, useArtifactEditSession, useArtifactSession, useArtifactText, useArtifactVersions, useRedline, useSaveArtifactVersion, versionLabel };
|