@artkit-ai/react 0.1.0 → 0.2.0
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/cache.d.ts +7 -11
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +32 -53
- package/dist/cache.js.map +1 -1
- package/dist/client.d.ts +4 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -29
- package/dist/client.js.map +1 -1
- package/dist/components/card.d.ts +2 -2
- package/dist/components/card.d.ts.map +1 -1
- package/dist/components/card.js +3 -3
- package/dist/components/card.js.map +1 -1
- package/dist/components/editor.d.ts +31 -18
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +81 -131
- package/dist/components/editor.js.map +1 -1
- package/dist/components/icons.d.ts +2 -2
- package/dist/components/icons.d.ts.map +1 -1
- package/dist/components/icons.js +2 -2
- package/dist/components/icons.js.map +1 -1
- package/dist/components/panel.d.ts +13 -16
- package/dist/components/panel.d.ts.map +1 -1
- package/dist/components/panel.js +13 -97
- package/dist/components/panel.js.map +1 -1
- package/dist/components/shared.d.ts +2 -6
- package/dist/components/shared.d.ts.map +1 -1
- package/dist/components/shared.js +2 -6
- package/dist/components/shared.js.map +1 -1
- package/dist/components/view.d.ts +7 -8
- package/dist/components/view.d.ts.map +1 -1
- package/dist/components/view.js +16 -15
- package/dist/components/view.js.map +1 -1
- package/dist/context.d.ts +14 -9
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/editor-session.d.ts +77 -165
- package/dist/editor-session.d.ts.map +1 -1
- package/dist/editor-session.js +164 -586
- package/dist/editor-session.js.map +1 -1
- package/dist/hooks.d.ts +2 -23
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +24 -116
- package/dist/hooks.js.map +1 -1
- package/dist/i18n.d.ts +4 -66
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +6 -68
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +12 -12
- package/dist/provider.js.map +1 -1
- package/dist/styles.d.ts +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +4 -4
- package/package.json +2 -2
- package/src/cache.ts +32 -55
- package/src/client.ts +7 -55
- package/src/components/card.tsx +6 -7
- package/src/components/editor.tsx +208 -308
- package/src/components/icons.tsx +2 -2
- package/src/components/panel.tsx +43 -300
- package/src/components/shared.tsx +3 -12
- package/src/components/view.tsx +26 -29
- package/src/context.ts +16 -11
- package/src/editor-session.ts +197 -675
- package/src/hooks.ts +25 -140
- package/src/i18n.ts +6 -68
- package/src/index.ts +7 -39
- package/src/provider.tsx +13 -13
- package/src/styles.ts +4 -4
- package/dist/components/approval.d.ts +0 -34
- package/dist/components/approval.d.ts.map +0 -1
- package/dist/components/approval.js +0 -80
- package/dist/components/approval.js.map +0 -1
- package/dist/components/version-diff.d.ts +0 -35
- package/dist/components/version-diff.d.ts.map +0 -1
- package/dist/components/version-diff.js +0 -85
- package/dist/components/version-diff.js.map +0 -1
- package/dist/line-diff.d.ts +0 -25
- package/dist/line-diff.d.ts.map +0 -1
- package/dist/line-diff.js +0 -96
- package/dist/line-diff.js.map +0 -1
- package/src/components/approval.tsx +0 -219
- package/src/components/version-diff.tsx +0 -266
- package/src/line-diff.ts +0 -111
package/dist/editor-session.d.ts
CHANGED
|
@@ -1,184 +1,96 @@
|
|
|
1
|
-
import { type Artifact,
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface SendRequest {
|
|
1
|
+
import { type Artifact, type ArtifactRegistry, type ChangeSummary, type LintIssue } from '@artkit-ai/core';
|
|
2
|
+
/**
|
|
3
|
+
* Local draft of one artifact (spec §11.6). The editor never talks to the server while the user edits: every batch is
|
|
4
|
+
* applied here, with the same pure engine as the server (`applyOperations`), and kept until the application saves.
|
|
5
|
+
* Saving is the application's decision: the editor emits the draft and the application persists it (or not).
|
|
6
|
+
*/
|
|
7
|
+
export interface DraftSnapshot {
|
|
8
|
+
/** Version of the artifact the draft started from (the last one the application loaded or saved). */
|
|
10
9
|
baseVersion: number;
|
|
11
|
-
|
|
12
|
-
idempotencyKey: string;
|
|
13
|
-
}
|
|
14
|
-
export interface EditorSessionOptions {
|
|
15
|
-
registry: ArtifactRegistry;
|
|
16
|
-
/** Last confirmed version. */
|
|
10
|
+
/** The draft as the user sees it. */
|
|
17
11
|
artifact: Artifact;
|
|
18
|
-
/**
|
|
19
|
-
send(request: SendRequest): Promise<CommitResult>;
|
|
20
|
-
/** Loads the latest version, or a specific one, after a conflict or a rebased commit. */
|
|
21
|
-
load(version?: number): Promise<Artifact>;
|
|
22
|
-
/** Typing operations emitted within this window become one batch (default 600 ms). */
|
|
23
|
-
groupingWindowMs?: number;
|
|
24
|
-
/** Upper bound for one typing batch while the user keeps typing (default 5 s). */
|
|
25
|
-
maxGroupingMs?: number;
|
|
26
|
-
/** Undo entries kept (default 100). */
|
|
27
|
-
maxUndo?: number;
|
|
28
|
-
/** Locale of error messages produced locally. */
|
|
29
|
-
locale?: string;
|
|
30
|
-
createKey?(): string;
|
|
31
|
-
onCommitted?(result: CommitResult): void;
|
|
32
|
-
}
|
|
33
|
-
export type SessionStatus = 'idle' | 'editing' | 'saving' | 'conflict';
|
|
34
|
-
export interface SessionConflict {
|
|
35
|
-
/**
|
|
36
|
-
* `server`: the server answered VERSION_CONFLICT; `rebase`: a newer version arrived and the pending
|
|
37
|
-
* operations no longer apply on it; `undo`/`redo`: the artifact changed after the edit being undone.
|
|
38
|
-
*/
|
|
39
|
-
reason: 'server' | 'rebase' | 'undo' | 'redo';
|
|
40
|
-
/** What changed in the newer version, for the conflict diff. */
|
|
41
|
-
changes: ChangeSummary[];
|
|
42
|
-
/** The local operations that would be reapplied. */
|
|
12
|
+
/** Operations applied since `baseVersion`, in order. */
|
|
43
13
|
operations: unknown[];
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
export type SessionEvent = {
|
|
47
|
-
type: 'saved';
|
|
48
|
-
version: number;
|
|
49
|
-
} | {
|
|
50
|
-
type: 'undone';
|
|
51
|
-
version: number;
|
|
52
|
-
} | {
|
|
53
|
-
type: 'redone';
|
|
54
|
-
version: number;
|
|
55
|
-
} | {
|
|
56
|
-
type: 'rebased';
|
|
57
|
-
version: number;
|
|
58
|
-
} | {
|
|
59
|
-
type: 'rejected';
|
|
60
|
-
error: ArtifactError;
|
|
61
|
-
} | {
|
|
62
|
-
type: 'rolled_back';
|
|
63
|
-
error: ArtifactError;
|
|
64
|
-
} | {
|
|
65
|
-
type: 'conflict';
|
|
66
|
-
reason: SessionConflict['reason'];
|
|
67
|
-
} | {
|
|
68
|
-
type: 'conflict_resolved';
|
|
69
|
-
choice: ConflictChoice;
|
|
70
|
-
};
|
|
71
|
-
export type ConflictChoice = 'keep-theirs' | 'reapply';
|
|
72
|
-
export interface EditorSessionState {
|
|
73
|
-
confirmed: Artifact;
|
|
74
|
-
/** Optimistic state: confirmed version plus every unconfirmed local operation. */
|
|
75
|
-
view: EnvelopeState;
|
|
76
|
-
status: SessionStatus;
|
|
77
|
-
/** Local operations not confirmed yet (buffered, queued or in flight). */
|
|
14
|
+
/** True when the draft differs from the base. */
|
|
78
15
|
dirty: boolean;
|
|
79
16
|
canUndo: boolean;
|
|
80
17
|
canRedo: boolean;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
18
|
+
/** An edit is being applied. */
|
|
19
|
+
pending: boolean;
|
|
20
|
+
/** Last rejected batch, cleared by the next accepted one. */
|
|
21
|
+
error?: {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
issues: {
|
|
25
|
+
path: string;
|
|
26
|
+
message: string;
|
|
27
|
+
hint?: string;
|
|
28
|
+
}[];
|
|
88
29
|
};
|
|
30
|
+
/** Lint issues of the draft. */
|
|
31
|
+
lint: LintIssue[];
|
|
32
|
+
/** Changes of the last accepted batch. */
|
|
33
|
+
changes: ChangeSummary[];
|
|
89
34
|
}
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
35
|
+
export interface DraftSessionOptions {
|
|
36
|
+
registry: ArtifactRegistry;
|
|
37
|
+
artifact: Artifact;
|
|
38
|
+
/** Locale of the model-facing messages produced by the engine (pt-BR or en). */
|
|
39
|
+
locale?: string;
|
|
40
|
+
/** Times within which consecutive typing batches share one undo step. */
|
|
41
|
+
coalesceMs?: number;
|
|
42
|
+
/** Undo steps kept in memory. */
|
|
43
|
+
maxUndo?: number;
|
|
44
|
+
now?: () => number;
|
|
45
|
+
}
|
|
46
|
+
export interface EmitOptions {
|
|
47
|
+
/** Continuous gestures (typing, dragging) share one undo step; discrete changes always get their own. */
|
|
48
|
+
kind?: 'typing' | 'continuous' | 'discrete';
|
|
49
|
+
}
|
|
50
|
+
type Listener = () => void;
|
|
51
|
+
/** Draft of one artifact with local undo and redo. Batches are applied in order, one at a time. */
|
|
52
|
+
export declare class DraftSession {
|
|
53
|
+
private readonly registry;
|
|
54
|
+
private readonly locale;
|
|
55
|
+
private readonly coalesceMs;
|
|
108
56
|
private readonly maxUndo;
|
|
109
|
-
private
|
|
110
|
-
private
|
|
111
|
-
private
|
|
112
|
-
private bufferStartedAt;
|
|
113
|
-
private timer;
|
|
114
|
-
private lockTimer;
|
|
115
|
-
private queue;
|
|
116
|
-
private inflight;
|
|
57
|
+
private readonly now;
|
|
58
|
+
private base;
|
|
59
|
+
private current;
|
|
117
60
|
private undoStack;
|
|
118
61
|
private redoStack;
|
|
62
|
+
private queue;
|
|
63
|
+
private pending;
|
|
119
64
|
private error;
|
|
120
|
-
private
|
|
121
|
-
private
|
|
122
|
-
private deferredRemote;
|
|
123
|
-
private event;
|
|
124
|
-
private seq;
|
|
125
|
-
private disposed;
|
|
126
|
-
private readonly listeners;
|
|
127
|
-
private idleWaiters;
|
|
65
|
+
private lint;
|
|
66
|
+
private changes;
|
|
128
67
|
private snapshot;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
private buildSnapshot;
|
|
136
|
-
private notify;
|
|
137
|
-
private announce;
|
|
138
|
-
private isLocked;
|
|
139
|
-
private applyLocal;
|
|
140
|
-
private pendingOperations;
|
|
141
|
-
/**
|
|
142
|
-
* Recomputes the optimistic view from the confirmed version. When the unconfirmed operations no
|
|
143
|
-
* longer apply, they move into a `rebase` conflict and the view falls back to the confirmed version.
|
|
144
|
-
*/
|
|
145
|
-
private rebaseView;
|
|
146
|
-
private changesBetween;
|
|
147
|
-
/**
|
|
148
|
-
* Called by the kind editor. Operations are applied optimistically right away; invalid ones are
|
|
149
|
-
* rejected locally (returns false) and never reach the server.
|
|
150
|
-
*/
|
|
151
|
-
emit: (operations: unknown[], options?: EmitOptions) => boolean;
|
|
152
|
-
/** Sends buffered typing operations now (e.g. on blur or before navigation). */
|
|
153
|
-
flush(): void;
|
|
154
|
-
private key;
|
|
155
|
-
private schedule;
|
|
156
|
-
private clearTimer;
|
|
157
|
-
private flushBuffer;
|
|
158
|
-
undo: () => void;
|
|
159
|
-
redo: () => void;
|
|
160
|
-
dismissError: () => void;
|
|
161
|
-
private pump;
|
|
162
|
-
private resolveHistoryCommand;
|
|
163
|
-
private onCommitted;
|
|
164
|
-
/** Incorporates a version that arrived while a request was in flight. */
|
|
165
|
-
private applyDeferred;
|
|
166
|
-
private pushUndo;
|
|
167
|
-
private onRejected;
|
|
168
|
-
private setLocked;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
private disposed;
|
|
70
|
+
constructor(options: DraftSessionOptions);
|
|
71
|
+
/** The current snapshot. Its identity changes only when the state changes. */
|
|
72
|
+
getSnapshot: () => DraftSnapshot;
|
|
73
|
+
subscribe: (listener: Listener) => (() => void);
|
|
169
74
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
75
|
+
* Applies a batch to the draft. Resolves to `true` when the batch was accepted. A rejected batch leaves the draft
|
|
76
|
+
* untouched and sets `snapshot.error`.
|
|
172
77
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
78
|
+
apply(operations: unknown[], options?: EmitOptions): Promise<boolean>;
|
|
79
|
+
/** Steps back one edit (local). Returns false when there is nothing to undo. */
|
|
80
|
+
undo(): boolean;
|
|
81
|
+
/** Steps forward after an undo. Returns false when there is nothing to redo. */
|
|
82
|
+
redo(): boolean;
|
|
176
83
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
84
|
+
* Adopts an artifact loaded or saved by the application. A clean draft follows the new artifact. A draft that has
|
|
85
|
+
* changes keeps its content, and the base moves to the new version so the next save is a complete one.
|
|
179
86
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
87
|
+
load(artifact: Artifact): void;
|
|
88
|
+
/** Stops the session: later batches are ignored and listeners are dropped. */
|
|
89
|
+
dispose(): void;
|
|
90
|
+
private restore;
|
|
91
|
+
private lintOf;
|
|
92
|
+
private publish;
|
|
93
|
+
private buildSnapshot;
|
|
183
94
|
}
|
|
95
|
+
export {};
|
|
184
96
|
//# sourceMappingURL=editor-session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-session.d.ts","sourceRoot":"","sources":["../src/editor-session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"editor-session.d.ts","sourceRoot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