@artkit-ai/react 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +145 -2
- package/dist/cache.d.ts +31 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +95 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +68 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +233 -0
- package/dist/client.js.map +1 -0
- package/dist/components/card.d.ts +22 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +16 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/editor.d.ts +41 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +111 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/icons.d.ts +8 -0
- package/dist/components/icons.d.ts.map +1 -0
- package/dist/components/icons.js +14 -0
- package/dist/components/icons.js.map +1 -0
- package/dist/components/panel.d.ts +31 -0
- package/dist/components/panel.d.ts.map +1 -0
- package/dist/components/panel.js +132 -0
- package/dist/components/panel.js.map +1 -0
- package/dist/components/shared.d.ts +67 -0
- package/dist/components/shared.d.ts.map +1 -0
- package/dist/components/shared.js +100 -0
- package/dist/components/shared.js.map +1 -0
- package/dist/components/view.d.ts +39 -0
- package/dist/components/view.d.ts.map +1 -0
- package/dist/components/view.js +76 -0
- package/dist/components/view.js.map +1 -0
- package/dist/context.d.ts +64 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +13 -0
- package/dist/context.js.map +1 -0
- package/dist/controls.d.ts +145 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +188 -0
- package/dist/controls.js.map +1 -0
- package/dist/download.d.ts +4 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +20 -0
- package/dist/download.js.map +1 -0
- package/dist/editor-session.d.ts +96 -0
- package/dist/editor-session.d.ts.map +1 -0
- package/dist/editor-session.js +192 -0
- package/dist/editor-session.js.map +1 -0
- package/dist/hooks.d.ts +64 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +205 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.d.ts +135 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +145 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/kit-css.d.ts +3 -0
- package/dist/kit-css.d.ts.map +1 -0
- package/dist/kit-css.js +5 -0
- package/dist/kit-css.js.map +1 -0
- package/dist/partial-json.d.ts +8 -0
- package/dist/partial-json.d.ts.map +1 -0
- package/dist/partial-json.js +176 -0
- package/dist/partial-json.js.map +1 -0
- package/dist/provider.d.ts +42 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +95 -0
- package/dist/provider.js.map +1 -0
- package/dist/styles.d.ts +25 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +203 -0
- package/dist/styles.js.map +1 -0
- package/dist/toolbar.d.ts +90 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +233 -0
- package/dist/toolbar.js.map +1 -0
- package/package.json +50 -3
- package/src/cache.ts +109 -0
- package/src/client.ts +342 -0
- package/src/components/card.tsx +86 -0
- package/src/components/editor.tsx +292 -0
- package/src/components/icons.tsx +14 -0
- package/src/components/panel.tsx +334 -0
- package/src/components/shared.tsx +198 -0
- package/src/components/view.tsx +196 -0
- package/src/context.ts +87 -0
- package/src/controls.tsx +587 -0
- package/src/download.ts +23 -0
- package/src/editor-session.ts +260 -0
- package/src/hooks.ts +296 -0
- package/src/i18n.ts +155 -0
- package/src/index.ts +128 -0
- package/src/kit-css.ts +5 -0
- package/src/partial-json.ts +160 -0
- package/src/provider.tsx +176 -0
- package/src/styles.ts +222 -0
- package/src/toolbar.tsx +536 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { ArtifactError, applyOperations, isArtifactError, } from '@artkit-ai/core';
|
|
2
|
+
const DEFAULT_COALESCE_MS = 1000;
|
|
3
|
+
const DEFAULT_MAX_UNDO = 200;
|
|
4
|
+
/** Draft of one artifact with local undo and redo. Batches are applied in order, one at a time. */
|
|
5
|
+
export class DraftSession {
|
|
6
|
+
registry;
|
|
7
|
+
locale;
|
|
8
|
+
coalesceMs;
|
|
9
|
+
maxUndo;
|
|
10
|
+
now;
|
|
11
|
+
base;
|
|
12
|
+
current;
|
|
13
|
+
undoStack = [];
|
|
14
|
+
redoStack = [];
|
|
15
|
+
queue = Promise.resolve();
|
|
16
|
+
pending = 0;
|
|
17
|
+
error;
|
|
18
|
+
lint;
|
|
19
|
+
changes = [];
|
|
20
|
+
snapshot;
|
|
21
|
+
listeners = new Set();
|
|
22
|
+
disposed = false;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.registry = options.registry;
|
|
25
|
+
this.locale = options.locale ?? 'en';
|
|
26
|
+
this.coalesceMs = options.coalesceMs ?? DEFAULT_COALESCE_MS;
|
|
27
|
+
this.maxUndo = options.maxUndo ?? DEFAULT_MAX_UNDO;
|
|
28
|
+
this.now = options.now ?? (() => Date.now());
|
|
29
|
+
this.base = options.artifact;
|
|
30
|
+
this.current = { artifact: options.artifact, operations: [], at: 0, typing: false };
|
|
31
|
+
this.lint = this.lintOf(options.artifact);
|
|
32
|
+
this.snapshot = this.buildSnapshot();
|
|
33
|
+
}
|
|
34
|
+
/** The current snapshot. Its identity changes only when the state changes. */
|
|
35
|
+
getSnapshot = () => this.snapshot;
|
|
36
|
+
subscribe = (listener) => {
|
|
37
|
+
this.listeners.add(listener);
|
|
38
|
+
return () => this.listeners.delete(listener);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Applies a batch to the draft. Resolves to `true` when the batch was accepted. A rejected batch leaves the draft
|
|
42
|
+
* untouched and sets `snapshot.error`.
|
|
43
|
+
*/
|
|
44
|
+
apply(operations, options = {}) {
|
|
45
|
+
if (operations.length === 0)
|
|
46
|
+
return Promise.resolve(true);
|
|
47
|
+
this.pending += 1;
|
|
48
|
+
this.publish();
|
|
49
|
+
const run = this.queue.then(async () => {
|
|
50
|
+
if (this.disposed)
|
|
51
|
+
return false;
|
|
52
|
+
const typing = options.kind === 'typing' || options.kind === 'continuous';
|
|
53
|
+
try {
|
|
54
|
+
const result = await applyOperations(this.registry, this.current.artifact, operations, {
|
|
55
|
+
locale: this.locale,
|
|
56
|
+
});
|
|
57
|
+
const next = {
|
|
58
|
+
...this.current.artifact,
|
|
59
|
+
formatVersion: result.formatVersion,
|
|
60
|
+
title: result.title,
|
|
61
|
+
locale: result.locale,
|
|
62
|
+
themeId: result.themeId,
|
|
63
|
+
content: result.content,
|
|
64
|
+
};
|
|
65
|
+
const now = this.now();
|
|
66
|
+
const coalesce = typing && this.current.typing && now - this.current.at <= this.coalesceMs;
|
|
67
|
+
if (!coalesce) {
|
|
68
|
+
this.undoStack.push(this.current);
|
|
69
|
+
if (this.undoStack.length > this.maxUndo)
|
|
70
|
+
this.undoStack.shift();
|
|
71
|
+
}
|
|
72
|
+
this.redoStack = [];
|
|
73
|
+
this.current = {
|
|
74
|
+
artifact: next,
|
|
75
|
+
operations: [...this.current.operations, ...operations],
|
|
76
|
+
at: now,
|
|
77
|
+
typing,
|
|
78
|
+
};
|
|
79
|
+
this.lint = result.lint;
|
|
80
|
+
this.changes = result.diff;
|
|
81
|
+
this.error = undefined;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
this.error = errorOf(error);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.queue = run.finally(() => {
|
|
90
|
+
this.pending -= 1;
|
|
91
|
+
this.publish();
|
|
92
|
+
});
|
|
93
|
+
return run.then((accepted) => {
|
|
94
|
+
this.publish();
|
|
95
|
+
return accepted;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Steps back one edit (local). Returns false when there is nothing to undo. */
|
|
99
|
+
undo() {
|
|
100
|
+
const previous = this.undoStack.pop();
|
|
101
|
+
if (!previous)
|
|
102
|
+
return false;
|
|
103
|
+
this.redoStack.push(this.current);
|
|
104
|
+
this.restore(previous);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
/** Steps forward after an undo. Returns false when there is nothing to redo. */
|
|
108
|
+
redo() {
|
|
109
|
+
const next = this.redoStack.pop();
|
|
110
|
+
if (!next)
|
|
111
|
+
return false;
|
|
112
|
+
this.undoStack.push(this.current);
|
|
113
|
+
this.restore(next);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Adopts an artifact loaded or saved by the application. A clean draft follows the new artifact. A draft that has
|
|
118
|
+
* changes keeps its content, and the base moves to the new version so the next save is a complete one.
|
|
119
|
+
*/
|
|
120
|
+
load(artifact) {
|
|
121
|
+
if (artifact.id !== this.base.id)
|
|
122
|
+
throw new ArtifactError('INVALID_OPERATION', 'Load the same artifact.');
|
|
123
|
+
const clean = !this.buildSnapshot().dirty;
|
|
124
|
+
const sameContent = JSON.stringify(artifact.content) === JSON.stringify(this.current.artifact.content);
|
|
125
|
+
this.base = artifact;
|
|
126
|
+
if (clean || sameContent) {
|
|
127
|
+
this.current = { artifact, operations: [], at: 0, typing: false };
|
|
128
|
+
this.undoStack = [];
|
|
129
|
+
this.redoStack = [];
|
|
130
|
+
this.lint = this.lintOf(artifact);
|
|
131
|
+
this.changes = [];
|
|
132
|
+
}
|
|
133
|
+
this.publish();
|
|
134
|
+
}
|
|
135
|
+
/** Stops the session: later batches are ignored and listeners are dropped. */
|
|
136
|
+
dispose() {
|
|
137
|
+
this.disposed = true;
|
|
138
|
+
this.listeners.clear();
|
|
139
|
+
}
|
|
140
|
+
restore(step) {
|
|
141
|
+
this.current = step;
|
|
142
|
+
this.lint = this.lintOf(step.artifact);
|
|
143
|
+
this.changes = [];
|
|
144
|
+
this.error = undefined;
|
|
145
|
+
this.publish();
|
|
146
|
+
}
|
|
147
|
+
lintOf(artifact) {
|
|
148
|
+
const adapter = this.registry.get(artifact.format, this.locale);
|
|
149
|
+
return adapter.lint(artifact.content, {
|
|
150
|
+
locale: artifact.locale,
|
|
151
|
+
theme: this.registry.theme(artifact.themeId, this.locale),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
publish() {
|
|
155
|
+
this.snapshot = this.buildSnapshot();
|
|
156
|
+
for (const listener of this.listeners)
|
|
157
|
+
listener();
|
|
158
|
+
}
|
|
159
|
+
buildSnapshot() {
|
|
160
|
+
const dirty = this.current.operations.length > 0 ||
|
|
161
|
+
JSON.stringify(this.current.artifact.content) !== JSON.stringify(this.base.content) ||
|
|
162
|
+
this.current.artifact.title !== this.base.title;
|
|
163
|
+
return {
|
|
164
|
+
baseVersion: this.base.version,
|
|
165
|
+
artifact: this.current.artifact,
|
|
166
|
+
operations: this.current.operations,
|
|
167
|
+
dirty,
|
|
168
|
+
canUndo: this.undoStack.length > 0,
|
|
169
|
+
canRedo: this.redoStack.length > 0,
|
|
170
|
+
pending: this.pending > 0,
|
|
171
|
+
...(this.error ? { error: this.error } : {}),
|
|
172
|
+
lint: this.lint,
|
|
173
|
+
changes: this.changes,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function errorOf(error) {
|
|
178
|
+
if (isArtifactError(error)) {
|
|
179
|
+
const payload = error.toPayload();
|
|
180
|
+
return {
|
|
181
|
+
code: payload.error.code,
|
|
182
|
+
message: payload.error.message,
|
|
183
|
+
issues: payload.error.issues ?? [],
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
code: 'INTERNAL_ERROR',
|
|
188
|
+
message: error instanceof Error ? error.message : String(error),
|
|
189
|
+
issues: [],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=editor-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AE,CAAC;QAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YACxB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE;SACnC,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/D,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Artifact, ArtifactError, type CommitResult } from '@artkit-ai/core';
|
|
2
|
+
import type { ClientExportResult } from './client.js';
|
|
3
|
+
export interface UseArtifactOptions {
|
|
4
|
+
/** Already-known artifact (e.g. from a chat message), shown immediately and cached. */
|
|
5
|
+
initial?: Artifact;
|
|
6
|
+
/** Revalidate the latest version on mount (default true). */
|
|
7
|
+
revalidate?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface UseArtifactResult {
|
|
10
|
+
artifact: Artifact | undefined;
|
|
11
|
+
error: unknown;
|
|
12
|
+
loading: boolean;
|
|
13
|
+
/** Fetches the latest version again (specific versions never change). */
|
|
14
|
+
refresh(): Promise<Artifact | undefined>;
|
|
15
|
+
}
|
|
16
|
+
/** Loads an artifact through the client with a shared cache (spec §13.2). Pass undefined to skip. */
|
|
17
|
+
export declare function useArtifact(id: string | undefined, options?: UseArtifactOptions): UseArtifactResult;
|
|
18
|
+
/** Latest known version of an artifact in the cache, updated when commits arrive. */
|
|
19
|
+
export declare function useLatestVersion(id: string | undefined): number | undefined;
|
|
20
|
+
export interface ApplyConflict {
|
|
21
|
+
operations: unknown[];
|
|
22
|
+
baseVersion: number;
|
|
23
|
+
currentVersion?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ApplyOptions {
|
|
26
|
+
/** Defaults to the latest cached version (loaded when unknown). */
|
|
27
|
+
baseVersion?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface UseApplyOperationsResult {
|
|
30
|
+
apply(operations: unknown[], options?: ApplyOptions): Promise<CommitResult>;
|
|
31
|
+
pending: boolean;
|
|
32
|
+
error: ArtifactError | undefined;
|
|
33
|
+
/** Set on VERSION_CONFLICT: what changed since the base, and the operations that were refused. */
|
|
34
|
+
conflict: ApplyConflict | undefined;
|
|
35
|
+
/** Sends the refused operations again on the latest version. */
|
|
36
|
+
retry(): Promise<CommitResult>;
|
|
37
|
+
reset(): void;
|
|
38
|
+
}
|
|
39
|
+
/** Sends operations with `baseVersion` and surfaces conflicts (spec §13.2). */
|
|
40
|
+
export declare function useApplyOperations(id: string): UseApplyOperationsResult;
|
|
41
|
+
export interface ExportOptions {
|
|
42
|
+
/** Triggers a browser download (default true). */
|
|
43
|
+
download?: boolean;
|
|
44
|
+
options?: Record<string, unknown>;
|
|
45
|
+
/** `auto` (default) exports in the browser when a browser-capable exporter is loaded. */
|
|
46
|
+
prefer?: 'auto' | 'browser' | 'server';
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}
|
|
49
|
+
export interface UseArtifactExportResult {
|
|
50
|
+
exportArtifact(format: string, options?: ExportOptions): Promise<ClientExportResult>;
|
|
51
|
+
pending: string | undefined;
|
|
52
|
+
error: ArtifactError | undefined;
|
|
53
|
+
warnings: string[];
|
|
54
|
+
/** Formats available for the artifact's kind (server formats plus browser exporters). */
|
|
55
|
+
formats: string[];
|
|
56
|
+
/** Loads the kind's browser exporters so `formats` includes them. */
|
|
57
|
+
loadFormats(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Exports in the browser when a loaded exporter with runtime `any`/`browser` handles the format, else
|
|
61
|
+
* through the client (spec §13.2), and triggers a download.
|
|
62
|
+
*/
|
|
63
|
+
export declare function useArtifactExport(id: string, format?: string): UseArtifactExportResult;
|
|
64
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,aAAa,EACb,KAAK,YAAY,EAIlB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAetD,MAAM,WAAW,kBAAkB;IACjC,uFAAuF;IACvF,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,yEAAyE;IACzE,OAAO,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;CAC1C;AAED,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,GAAE,kBAAuB,GAAG,iBAAiB,CAmCvG;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQ3E;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5E,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,kGAAkG;IAClG,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,gEAAgE;IAChE,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,wBAAwB,CAmDvE;AAED,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrF,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,yFAAyF;IACzF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qEAAqE;IACrE,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAyGtF"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { ArtifactError, isArtifactError, silentLogger, slugify, } from '@artkit-ai/core';
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { useArtkit } from './context.js';
|
|
4
|
+
import { triggerDownload } from './download.js';
|
|
5
|
+
const NO_ENTRY = Object.freeze({ loading: false });
|
|
6
|
+
const noop = () => { };
|
|
7
|
+
const noSubscription = () => noop;
|
|
8
|
+
function toArtifactError(error) {
|
|
9
|
+
if (isArtifactError(error))
|
|
10
|
+
return error;
|
|
11
|
+
return new ArtifactError('INTERNAL_ERROR', 'Internal error while processing the request.', {
|
|
12
|
+
cause: error,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** Loads an artifact through the client with a shared cache (spec §13.2). Pass undefined to skip. */
|
|
16
|
+
export function useArtifact(id, options = {}) {
|
|
17
|
+
const { cache } = useArtkit();
|
|
18
|
+
const { initial, revalidate = true } = options;
|
|
19
|
+
const subscribe = useCallback((listener) => (id ? cache.subscribe(id, listener) : noop), [cache, id]);
|
|
20
|
+
const read = () => (id ? cache.entry(id) : NO_ENTRY);
|
|
21
|
+
const entry = useSyncExternalStore(id ? subscribe : noSubscription, read, read);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (initial && initial.id === id)
|
|
24
|
+
cache.put(initial);
|
|
25
|
+
}, [cache, id, initial]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!id)
|
|
28
|
+
return;
|
|
29
|
+
cache.load(id, revalidate).catch(noop);
|
|
30
|
+
}, [cache, id, revalidate]);
|
|
31
|
+
const usableInitial = initial && initial.id === id ? initial : undefined;
|
|
32
|
+
const artifact = entry.artifact && (!usableInitial || entry.artifact.version >= usableInitial.version)
|
|
33
|
+
? entry.artifact
|
|
34
|
+
: (usableInitial ?? entry.artifact);
|
|
35
|
+
const refresh = useCallback(async () => {
|
|
36
|
+
if (!id)
|
|
37
|
+
return undefined;
|
|
38
|
+
return cache.load(id, true);
|
|
39
|
+
}, [cache, id]);
|
|
40
|
+
return {
|
|
41
|
+
artifact,
|
|
42
|
+
error: artifact ? undefined : entry.error,
|
|
43
|
+
loading: !artifact && !entry.error && id !== undefined,
|
|
44
|
+
refresh,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Latest known version of an artifact in the cache, updated when commits arrive. */
|
|
48
|
+
export function useLatestVersion(id) {
|
|
49
|
+
const { cache } = useArtkit();
|
|
50
|
+
const subscribe = useCallback((listener) => (id ? cache.subscribe(id, listener) : noop), [cache, id]);
|
|
51
|
+
const read = () => (id ? cache.latest(id)?.version : undefined);
|
|
52
|
+
return useSyncExternalStore(subscribe, read, read);
|
|
53
|
+
}
|
|
54
|
+
/** Sends operations with `baseVersion` and surfaces conflicts (spec §13.2). */
|
|
55
|
+
export function useApplyOperations(id) {
|
|
56
|
+
const { client, cache } = useArtkit();
|
|
57
|
+
const [state, setState] = useState({
|
|
58
|
+
pending: false,
|
|
59
|
+
});
|
|
60
|
+
const conflictRef = useRef(undefined);
|
|
61
|
+
const apply = useCallback(async (operations, options = {}) => {
|
|
62
|
+
setState({ pending: true });
|
|
63
|
+
let baseVersion = options.baseVersion;
|
|
64
|
+
try {
|
|
65
|
+
baseVersion ??= cache.latest(id)?.version ?? (await cache.load(id)).version;
|
|
66
|
+
const result = await client.apply(id, { baseVersion, operations });
|
|
67
|
+
cache.put(result.artifact);
|
|
68
|
+
conflictRef.current = undefined;
|
|
69
|
+
setState({ pending: false });
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
catch (caught) {
|
|
73
|
+
const error = toArtifactError(caught);
|
|
74
|
+
let conflict;
|
|
75
|
+
if (error.code === 'VERSION_CONFLICT') {
|
|
76
|
+
const current = error.details.currentVersion;
|
|
77
|
+
conflict = {
|
|
78
|
+
operations,
|
|
79
|
+
baseVersion: baseVersion ?? 0,
|
|
80
|
+
...(typeof current === 'number' ? { currentVersion: current } : {}),
|
|
81
|
+
};
|
|
82
|
+
cache.load(id, true).catch(noop);
|
|
83
|
+
}
|
|
84
|
+
conflictRef.current = conflict;
|
|
85
|
+
setState({ pending: false, error, ...(conflict ? { conflict } : {}) });
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}, [client, cache, id]);
|
|
89
|
+
const retry = useCallback(async () => {
|
|
90
|
+
const conflict = conflictRef.current;
|
|
91
|
+
if (!conflict)
|
|
92
|
+
throw new ArtifactError('NOT_FOUND', 'There is no conflicting batch to retry.');
|
|
93
|
+
const latest = await cache.load(id, true);
|
|
94
|
+
return apply(conflict.operations, { baseVersion: latest.version });
|
|
95
|
+
}, [apply, cache, id]);
|
|
96
|
+
const reset = useCallback(() => {
|
|
97
|
+
conflictRef.current = undefined;
|
|
98
|
+
setState({ pending: false });
|
|
99
|
+
}, []);
|
|
100
|
+
return { apply, pending: state.pending, error: state.error, conflict: state.conflict, retry, reset };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Exports in the browser when a loaded exporter with runtime `any`/`browser` handles the format, else
|
|
104
|
+
* through the client (spec §13.2), and triggers a download.
|
|
105
|
+
*/
|
|
106
|
+
export function useArtifactExport(id, format) {
|
|
107
|
+
const ctx = useArtkit();
|
|
108
|
+
const { client, cache, registry } = ctx;
|
|
109
|
+
const [pending, setPending] = useState(undefined);
|
|
110
|
+
const [error, setError] = useState(undefined);
|
|
111
|
+
const [warnings, setWarnings] = useState([]);
|
|
112
|
+
const [loaded, setLoaded] = useState([]);
|
|
113
|
+
const knownFormat = format ?? cache.latest(id)?.format;
|
|
114
|
+
const browserExporters = useCallback(async (artifactKind) => {
|
|
115
|
+
const fromRegistry = registry.exporters(artifactKind).filter((exporter) => exporter.runtime !== 'node');
|
|
116
|
+
if (!ctx.hasExporters(artifactKind))
|
|
117
|
+
return fromRegistry;
|
|
118
|
+
const lazy = (await ctx.loadExporters(artifactKind)).filter((exporter) => exporter.format === artifactKind && exporter.runtime !== 'node');
|
|
119
|
+
return [...lazy, ...fromRegistry];
|
|
120
|
+
}, [ctx, registry]);
|
|
121
|
+
const loadFormats = useCallback(async () => {
|
|
122
|
+
if (!knownFormat)
|
|
123
|
+
return;
|
|
124
|
+
try {
|
|
125
|
+
setLoaded(await browserExporters(knownFormat));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Without browser exporters the server formats still work.
|
|
129
|
+
}
|
|
130
|
+
}, [browserExporters, knownFormat]);
|
|
131
|
+
const formats = useMemo(() => {
|
|
132
|
+
if (!knownFormat)
|
|
133
|
+
return [];
|
|
134
|
+
const set = new Set(ctx.exportFormats[knownFormat] ?? []);
|
|
135
|
+
for (const exporter of registry.exporters(knownFormat))
|
|
136
|
+
if (exporter.runtime !== 'node')
|
|
137
|
+
set.add(exporter.target);
|
|
138
|
+
for (const exporter of loaded)
|
|
139
|
+
set.add(exporter.target);
|
|
140
|
+
return [...set];
|
|
141
|
+
}, [ctx.exportFormats, knownFormat, loaded, registry]);
|
|
142
|
+
const exportArtifact = useCallback(async (format, options = {}) => {
|
|
143
|
+
setPending(format);
|
|
144
|
+
setError(undefined);
|
|
145
|
+
setWarnings([]);
|
|
146
|
+
try {
|
|
147
|
+
const artifact = cache.latest(id) ?? (await cache.load(id));
|
|
148
|
+
let result;
|
|
149
|
+
if (options.prefer !== 'server') {
|
|
150
|
+
const exporter = (await browserExporters(artifact.format).catch(() => [])).find((candidate) => candidate.target === format);
|
|
151
|
+
if (exporter) {
|
|
152
|
+
const collected = [];
|
|
153
|
+
let bytes;
|
|
154
|
+
try {
|
|
155
|
+
bytes = await exporter.export(artifact.content, {
|
|
156
|
+
title: artifact.title,
|
|
157
|
+
theme: ctx.themeFor(artifact.themeId),
|
|
158
|
+
locale: artifact.locale,
|
|
159
|
+
assets: ctx.assets ?? {
|
|
160
|
+
resolve: (ref) => Promise.reject(new ArtifactError('NOT_FOUND', `Asset not available in the browser: ${ref}.`)),
|
|
161
|
+
},
|
|
162
|
+
logger: silentLogger,
|
|
163
|
+
warn: (message) => collected.push(message),
|
|
164
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
165
|
+
...(options.options ? { options: options.options } : {}),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
catch (cause) {
|
|
169
|
+
throw isArtifactError(cause)
|
|
170
|
+
? cause
|
|
171
|
+
: new ArtifactError('EXPORT_FAILED', `Failed to export to ${format}.`, { cause });
|
|
172
|
+
}
|
|
173
|
+
result = {
|
|
174
|
+
bytes,
|
|
175
|
+
mimeType: exporter.mimeType,
|
|
176
|
+
filename: `${slugify(artifact.title)}.${exporter.extension}`,
|
|
177
|
+
warnings: collected,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
else if (options.prefer === 'browser') {
|
|
181
|
+
throw new ArtifactError('EXPORT_FAILED', `No browser exporter for format ${format}.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
result ??= await client.export(id, {
|
|
185
|
+
format,
|
|
186
|
+
...(options.options ? { options: options.options } : {}),
|
|
187
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
188
|
+
});
|
|
189
|
+
setWarnings(result.warnings);
|
|
190
|
+
if (options.download !== false)
|
|
191
|
+
triggerDownload(result);
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
catch (caught) {
|
|
195
|
+
const failure = toArtifactError(caught);
|
|
196
|
+
setError(failure);
|
|
197
|
+
throw failure;
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
setPending(undefined);
|
|
201
|
+
}
|
|
202
|
+
}, [browserExporters, cache, client, ctx, id]);
|
|
203
|
+
return { exportArtifact, pending, error, warnings, formats, loadFormats };
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAEb,eAAe,EACf,YAAY,EACZ,OAAO,GACR,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,oBA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|
4
|
+
loading: string;
|
|
5
|
+
generating: string;
|
|
6
|
+
provisional: string;
|
|
7
|
+
noRenderer: string;
|
|
8
|
+
loadFailed: string;
|
|
9
|
+
retry: string;
|
|
10
|
+
close: string;
|
|
11
|
+
open: string;
|
|
12
|
+
openTitle: string;
|
|
13
|
+
version: string;
|
|
14
|
+
versionShort: string;
|
|
15
|
+
latest: string;
|
|
16
|
+
tabView: string;
|
|
17
|
+
tabCode: string;
|
|
18
|
+
tabEdit: string;
|
|
19
|
+
save: string;
|
|
20
|
+
tabsLabel: string;
|
|
21
|
+
copy: string;
|
|
22
|
+
copied: string;
|
|
23
|
+
export: string;
|
|
24
|
+
exportAs: string;
|
|
25
|
+
exporting: string;
|
|
26
|
+
exported: string;
|
|
27
|
+
exportWarnings: string;
|
|
28
|
+
noExportFormats: string;
|
|
29
|
+
rejectReason: string;
|
|
30
|
+
confirmReject: string;
|
|
31
|
+
cancel: string;
|
|
32
|
+
loadMore: string;
|
|
33
|
+
by: string;
|
|
34
|
+
actor_agent: string;
|
|
35
|
+
actor_user: string;
|
|
36
|
+
actor_system: string;
|
|
37
|
+
changes: string;
|
|
38
|
+
noChanges: string;
|
|
39
|
+
change_added: string;
|
|
40
|
+
change_removed: string;
|
|
41
|
+
change_changed: string;
|
|
42
|
+
change_moved: string;
|
|
43
|
+
diffUnified: string;
|
|
44
|
+
diffSplit: string;
|
|
45
|
+
diffViewLabel: string;
|
|
46
|
+
lineAdded: string;
|
|
47
|
+
lineRemoved: string;
|
|
48
|
+
undo: string;
|
|
49
|
+
redo: string;
|
|
50
|
+
undone: string;
|
|
51
|
+
redone: string;
|
|
52
|
+
saving: string;
|
|
53
|
+
saved: string;
|
|
54
|
+
unsaved: string;
|
|
55
|
+
rolledBack: string;
|
|
56
|
+
dismiss: string;
|
|
57
|
+
readOnly: string;
|
|
58
|
+
lockedBy: string;
|
|
59
|
+
lockedUntil: string;
|
|
60
|
+
reapplyMine: string;
|
|
61
|
+
editorLabel: string;
|
|
62
|
+
lintWarnings: string;
|
|
63
|
+
};
|
|
64
|
+
'pt-BR': {
|
|
65
|
+
loading: string;
|
|
66
|
+
generating: string;
|
|
67
|
+
provisional: string;
|
|
68
|
+
noRenderer: string;
|
|
69
|
+
loadFailed: string;
|
|
70
|
+
retry: string;
|
|
71
|
+
close: string;
|
|
72
|
+
open: string;
|
|
73
|
+
openTitle: string;
|
|
74
|
+
version: string;
|
|
75
|
+
versionShort: string;
|
|
76
|
+
latest: string;
|
|
77
|
+
tabView: string;
|
|
78
|
+
tabCode: string;
|
|
79
|
+
tabEdit: string;
|
|
80
|
+
save: string;
|
|
81
|
+
tabsLabel: string;
|
|
82
|
+
copy: string;
|
|
83
|
+
copied: string;
|
|
84
|
+
export: string;
|
|
85
|
+
exportAs: string;
|
|
86
|
+
exporting: string;
|
|
87
|
+
exported: string;
|
|
88
|
+
exportWarnings: string;
|
|
89
|
+
noExportFormats: string;
|
|
90
|
+
rejectReason: string;
|
|
91
|
+
confirmReject: string;
|
|
92
|
+
cancel: string;
|
|
93
|
+
loadMore: string;
|
|
94
|
+
by: string;
|
|
95
|
+
actor_agent: string;
|
|
96
|
+
actor_user: string;
|
|
97
|
+
actor_system: string;
|
|
98
|
+
changes: string;
|
|
99
|
+
noChanges: string;
|
|
100
|
+
change_added: string;
|
|
101
|
+
change_removed: string;
|
|
102
|
+
change_changed: string;
|
|
103
|
+
change_moved: string;
|
|
104
|
+
diffUnified: string;
|
|
105
|
+
diffSplit: string;
|
|
106
|
+
diffViewLabel: string;
|
|
107
|
+
lineAdded: string;
|
|
108
|
+
lineRemoved: string;
|
|
109
|
+
undo: string;
|
|
110
|
+
redo: string;
|
|
111
|
+
undone: string;
|
|
112
|
+
redone: string;
|
|
113
|
+
saving: string;
|
|
114
|
+
saved: string;
|
|
115
|
+
unsaved: string;
|
|
116
|
+
rolledBack: string;
|
|
117
|
+
dismiss: string;
|
|
118
|
+
readOnly: string;
|
|
119
|
+
lockedBy: string;
|
|
120
|
+
lockedUntil: string;
|
|
121
|
+
reapplyMine: string;
|
|
122
|
+
editorLabel: string;
|
|
123
|
+
lintWarnings: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
export type UiMessageKey = keyof (typeof uiMessages)['en'];
|
|
127
|
+
export type UiMessages = Record<UiMessageKey, string>;
|
|
128
|
+
/** Extra or overriding catalogs, keyed by BCP-47 tag (`es`, `pt-PT`) or language. */
|
|
129
|
+
export type UiMessageOverrides = Record<string, Partial<UiMessages>>;
|
|
130
|
+
export type Translate = (key: UiMessageKey, params?: Record<string, string | number>) => string;
|
|
131
|
+
/**
|
|
132
|
+
* Resolution order: exact override, language override, built-in catalog (pt* → pt-BR, else en), English.
|
|
133
|
+
*/
|
|
134
|
+
export declare function createTranslator(locale: string, overrides?: UiMessageOverrides): Translate;
|
|
135
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,eAAO,MAAM,UAAU;;QAEnB,OAAO;QACP,UAAU;QACV,WAAW;QACX,UAAU;QACV,UAAU;QACV,KAAK;QACL,KAAK;QACL,IAAI;QACJ,SAAS;QACT,OAAO;QACP,YAAY;QACZ,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,IAAI;QACJ,SAAS;QACT,IAAI;QACJ,MAAM;QACN,MAAM;QACN,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,cAAc;QACd,eAAe;QACf,YAAY;QACZ,aAAa;QACb,MAAM;QACN,QAAQ;QACR,EAAE;QACF,WAAW;QACX,UAAU;QACV,YAAY;QACZ,OAAO;QACP,SAAS;QACT,YAAY;QACZ,cAAc;QACd,cAAc;QACd,YAAY;QACZ,WAAW;QACX,SAAS;QACT,aAAa;QACb,SAAS;QACT,WAAW;QACX,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,MAAM;QACN,MAAM;QACN,KAA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