@designos/editor 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/dist/index.d.ts +308 -0
- package/dist/index.js +3316 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import * as _designos_core from '@designos/core';
|
|
4
|
+
import { PageDocument, DesignDocument, KitDesignManifest, ComponentRegistry, PageNode } from '@designos/core';
|
|
5
|
+
import * as zustand from 'zustand';
|
|
6
|
+
|
|
7
|
+
interface EditorPreviewOptions {
|
|
8
|
+
/** Render page content in an isolated same-origin iframe. Defaults to "iframe". */
|
|
9
|
+
mode?: "iframe" | "inline";
|
|
10
|
+
/** Mirror host style/link tags and html/body attributes into the preview frame. Defaults to true. */
|
|
11
|
+
syncHostStyles?: boolean;
|
|
12
|
+
/** Stylesheet URLs to load only inside the preview iframe. */
|
|
13
|
+
stylesheets?: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PagePublishInput {
|
|
17
|
+
/** Framework-neutral page snapshot authored by the editor. */
|
|
18
|
+
page: PageDocument;
|
|
19
|
+
/** Stable host-owned identity for the page being published. */
|
|
20
|
+
pageId: string;
|
|
21
|
+
/** Optional optimistic-concurrency token from the host's previous save/publish. */
|
|
22
|
+
expectedRevision?: string;
|
|
23
|
+
}
|
|
24
|
+
interface PagePublishResult {
|
|
25
|
+
/** Revision returned by the host and used for the next publish request. */
|
|
26
|
+
revision: string;
|
|
27
|
+
/** Optional public URL of the published page. */
|
|
28
|
+
url?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Host-supplied publishing adapter. Auth, tenant checks and persistence belong to the host. */
|
|
31
|
+
interface PagePublisher {
|
|
32
|
+
publish(input: PagePublishInput): Promise<PagePublishResult>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface DesignPublishInput {
|
|
36
|
+
/** Versioned, JSON-serializable site-wide design document supplied by the host. */
|
|
37
|
+
design: DesignDocument;
|
|
38
|
+
/** Stable host-owned identity for the site or design being published. */
|
|
39
|
+
siteId: string;
|
|
40
|
+
/** Optional optimistic-concurrency token returned by the host previously. */
|
|
41
|
+
expectedRevision?: string;
|
|
42
|
+
}
|
|
43
|
+
interface DesignPublishResult {
|
|
44
|
+
/** New host-owned design revision. */
|
|
45
|
+
revision: string;
|
|
46
|
+
}
|
|
47
|
+
/** Host adapter. The host decides whether publishing saves, stages, or deploys the design. */
|
|
48
|
+
interface DesignPublisher {
|
|
49
|
+
publish(input: DesignPublishInput): Promise<DesignPublishResult>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface DesignPanelProps {
|
|
53
|
+
/** Temporary versioned design value. It is not page history or autosaved. */
|
|
54
|
+
value: DesignDocument;
|
|
55
|
+
onChange(value: DesignDocument): void;
|
|
56
|
+
}
|
|
57
|
+
interface EditorDesignBaseOptions {
|
|
58
|
+
/** Initial versioned design document for this editor session. */
|
|
59
|
+
initialValue: DesignDocument;
|
|
60
|
+
/** Stable host-owned site or design identifier. */
|
|
61
|
+
siteId: string;
|
|
62
|
+
/** Override the built-in kit-manifest CSS-variable projection. */
|
|
63
|
+
getPreviewStyles?: (value: DesignDocument) => string;
|
|
64
|
+
/** Host-owned persistence/publishing behavior. */
|
|
65
|
+
publisher: DesignPublisher;
|
|
66
|
+
expectedRevision?: string;
|
|
67
|
+
}
|
|
68
|
+
type EditorDesignOptions = EditorDesignBaseOptions & ({
|
|
69
|
+
/** Legacy or host-specific controls for a design schema. */
|
|
70
|
+
Panel: ComponentType<DesignPanelProps>;
|
|
71
|
+
manifest?: never;
|
|
72
|
+
kitId?: never;
|
|
73
|
+
} | {
|
|
74
|
+
/** Declarative kit schema rendered by the editor's standard controls. */
|
|
75
|
+
manifest: KitDesignManifest;
|
|
76
|
+
/** Stable package ID used as the design-document token group. */
|
|
77
|
+
kitId: string;
|
|
78
|
+
Panel?: never;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
interface PageHistoryEntry {
|
|
82
|
+
/** Stable identity for this snapshot within the page history. */
|
|
83
|
+
id: string;
|
|
84
|
+
/** Framework-neutral authored page snapshot. */
|
|
85
|
+
page: PageDocument;
|
|
86
|
+
/** Human-readable mutation description shown by the History UI. */
|
|
87
|
+
label: string;
|
|
88
|
+
/** Origin of the committed change. */
|
|
89
|
+
source?: "manual" | "agent" | "restore";
|
|
90
|
+
/** Creation time in epoch milliseconds. */
|
|
91
|
+
timestamp: number;
|
|
92
|
+
}
|
|
93
|
+
interface PageHistoryLoadInput {
|
|
94
|
+
pageId: string;
|
|
95
|
+
}
|
|
96
|
+
interface PageHistorySaveInput {
|
|
97
|
+
pageId: string;
|
|
98
|
+
entries: PageHistoryEntry[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Host-owned history persistence seam. The editor remains usable without an
|
|
102
|
+
* adapter; hosts may provide memory, browser, API, or database persistence.
|
|
103
|
+
*/
|
|
104
|
+
interface PageHistoryPersistence {
|
|
105
|
+
load(input: PageHistoryLoadInput): Promise<PageHistoryEntry[]>;
|
|
106
|
+
save(input: PageHistorySaveInput): Promise<void>;
|
|
107
|
+
clear?(input: PageHistoryLoadInput): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface PageAgentPermissions {
|
|
111
|
+
canEditContent?: boolean;
|
|
112
|
+
canEditImages?: boolean;
|
|
113
|
+
canEditLinks?: boolean;
|
|
114
|
+
canChangeVariants?: boolean;
|
|
115
|
+
canAddComponents?: boolean;
|
|
116
|
+
canRemoveComponents?: boolean;
|
|
117
|
+
canReorderComponents?: boolean;
|
|
118
|
+
allowedComponentTypes?: string[];
|
|
119
|
+
lockedNodeIds?: string[];
|
|
120
|
+
maxNodes?: number;
|
|
121
|
+
}
|
|
122
|
+
interface PublicFieldDefinition {
|
|
123
|
+
name: string;
|
|
124
|
+
label: string;
|
|
125
|
+
type: string;
|
|
126
|
+
required?: boolean;
|
|
127
|
+
description?: string;
|
|
128
|
+
defaultValue?: unknown;
|
|
129
|
+
options?: Array<{
|
|
130
|
+
label: string;
|
|
131
|
+
value: string | number | boolean;
|
|
132
|
+
}>;
|
|
133
|
+
fields?: PublicFieldDefinition[];
|
|
134
|
+
item?: PublicFieldDefinition;
|
|
135
|
+
}
|
|
136
|
+
interface PublicComponentDefinition {
|
|
137
|
+
type: string;
|
|
138
|
+
displayName: string;
|
|
139
|
+
category?: string;
|
|
140
|
+
fields: PublicFieldDefinition[];
|
|
141
|
+
slots: Array<{
|
|
142
|
+
name: string;
|
|
143
|
+
label: string;
|
|
144
|
+
allowedComponents?: string[];
|
|
145
|
+
}>;
|
|
146
|
+
canHaveChildren: boolean;
|
|
147
|
+
}
|
|
148
|
+
interface PageAgentContext {
|
|
149
|
+
pageId?: string;
|
|
150
|
+
page: PageDocument;
|
|
151
|
+
selectedNodeId?: string;
|
|
152
|
+
components: PublicComponentDefinition[];
|
|
153
|
+
permissions: PageAgentPermissions;
|
|
154
|
+
history: PageHistoryEntry[];
|
|
155
|
+
baseRevision?: string;
|
|
156
|
+
}
|
|
157
|
+
interface PageChangeSummary {
|
|
158
|
+
path: string;
|
|
159
|
+
before?: unknown;
|
|
160
|
+
after?: unknown;
|
|
161
|
+
kind: "added" | "removed" | "changed";
|
|
162
|
+
}
|
|
163
|
+
interface PageAgentDiagnostic {
|
|
164
|
+
path: string;
|
|
165
|
+
message: string;
|
|
166
|
+
severity: "error" | "warning";
|
|
167
|
+
}
|
|
168
|
+
interface ApplyPageStateInput {
|
|
169
|
+
page: PageDocument;
|
|
170
|
+
summary: string;
|
|
171
|
+
baseRevision?: string;
|
|
172
|
+
}
|
|
173
|
+
interface ApplyPageStateResult {
|
|
174
|
+
status: "applied" | "rejected";
|
|
175
|
+
versionId?: string;
|
|
176
|
+
summary?: string;
|
|
177
|
+
changes: PageChangeSummary[];
|
|
178
|
+
diagnostics: PageAgentDiagnostic[];
|
|
179
|
+
}
|
|
180
|
+
interface PageAgentChatResult {
|
|
181
|
+
message: string;
|
|
182
|
+
applied?: ApplyPageStateResult;
|
|
183
|
+
}
|
|
184
|
+
interface PageAgentChatInput extends PageAgentContext {
|
|
185
|
+
request: string;
|
|
186
|
+
applyPageState(input: ApplyPageStateInput): ApplyPageStateResult;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Host-owned page assistant. The host supplies the model/chat implementation;
|
|
190
|
+
* the editor supplies a narrow, validated applyPageState tool callback.
|
|
191
|
+
*/
|
|
192
|
+
interface PageAgent {
|
|
193
|
+
chat(input: PageAgentChatInput): Promise<PageAgentChatResult>;
|
|
194
|
+
}
|
|
195
|
+
declare function projectPublicComponents(registry: ComponentRegistry, permissions?: PageAgentPermissions): PublicComponentDefinition[];
|
|
196
|
+
|
|
197
|
+
interface EditorBaseProps {
|
|
198
|
+
registry: ComponentRegistry;
|
|
199
|
+
components: Record<string, React.ComponentType<any>>;
|
|
200
|
+
preview?: EditorPreviewOptions;
|
|
201
|
+
/** Isolate editor chrome from host application styles. Defaults to true. */
|
|
202
|
+
isolateStyles?: boolean;
|
|
203
|
+
/** Host-owned local draft key, typically scoped by project and page. Defaults to the shared editor key. */
|
|
204
|
+
draftStorageKey?: string;
|
|
205
|
+
history?: PageHistoryPersistence;
|
|
206
|
+
agent?: PageAgent;
|
|
207
|
+
agentPermissions?: PageAgentPermissions;
|
|
208
|
+
design?: EditorDesignOptions;
|
|
209
|
+
}
|
|
210
|
+
type EditorProps = EditorBaseProps & ({
|
|
211
|
+
publisher: PagePublisher;
|
|
212
|
+
pageId: string;
|
|
213
|
+
expectedRevision?: string;
|
|
214
|
+
} | {
|
|
215
|
+
publisher?: undefined;
|
|
216
|
+
pageId?: string;
|
|
217
|
+
expectedRevision?: string;
|
|
218
|
+
});
|
|
219
|
+
declare function Editor({ isolateStyles, ...props }: EditorProps): react.JSX.Element;
|
|
220
|
+
|
|
221
|
+
type Viewport = "desktop" | "tablet" | "mobile";
|
|
222
|
+
interface EditorState {
|
|
223
|
+
page: PageDocument;
|
|
224
|
+
selectedNodeId?: string;
|
|
225
|
+
viewport: Viewport;
|
|
226
|
+
jsonDrawerOpen: boolean;
|
|
227
|
+
historyOpen: boolean;
|
|
228
|
+
assistantOpen: boolean;
|
|
229
|
+
designOpen: boolean;
|
|
230
|
+
previewMode: boolean;
|
|
231
|
+
past: PageHistoryEntry[];
|
|
232
|
+
future: PageHistoryEntry[];
|
|
233
|
+
canUndo: boolean;
|
|
234
|
+
canRedo: boolean;
|
|
235
|
+
copiedNode: PageNode | null;
|
|
236
|
+
setPage(page: PageDocument, options?: {
|
|
237
|
+
recordHistory?: boolean;
|
|
238
|
+
label?: string;
|
|
239
|
+
}): void;
|
|
240
|
+
applyPageState(page: PageDocument, options?: {
|
|
241
|
+
label?: string;
|
|
242
|
+
source?: "manual" | "agent";
|
|
243
|
+
changes?: PageChangeSummary[];
|
|
244
|
+
}): ApplyPageStateResult;
|
|
245
|
+
setViewport(viewport: Viewport): void;
|
|
246
|
+
toggleJsonDrawer(): void;
|
|
247
|
+
toggleHistory(): void;
|
|
248
|
+
toggleAssistant(): void;
|
|
249
|
+
toggleDesign(): void;
|
|
250
|
+
togglePreview(): void;
|
|
251
|
+
replaceHistory(entries: PageHistoryEntry[]): void;
|
|
252
|
+
jumpToHistory(entryId: string): void;
|
|
253
|
+
selectNode(nodeId?: string): void;
|
|
254
|
+
addNode(parentId: string, node: PageNode, slotName?: string): void;
|
|
255
|
+
removeNode(nodeId: string): void;
|
|
256
|
+
updateNodeProps(nodeId: string, props: Record<string, unknown>): void;
|
|
257
|
+
moveNode(nodeId: string, destinationId: string, slotName?: string): void;
|
|
258
|
+
duplicateNode(nodeId: string): void;
|
|
259
|
+
reorderNode(parentId: string, sourceIndex: number, targetIndex: number, slotName?: string): void;
|
|
260
|
+
undo(): void;
|
|
261
|
+
redo(): void;
|
|
262
|
+
reset(): void;
|
|
263
|
+
copySelectedNode(): void;
|
|
264
|
+
pasteNode(): void;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare const useEditorStore: zustand.UseBoundStore<zustand.StoreApi<EditorState>>;
|
|
268
|
+
|
|
269
|
+
declare const useEditor: zustand.UseBoundStore<zustand.StoreApi<EditorState>>;
|
|
270
|
+
|
|
271
|
+
declare function useSelectedNode(): _designos_core.PageNode | undefined;
|
|
272
|
+
|
|
273
|
+
declare function useKeyboardShortcuts(enabled?: boolean): void;
|
|
274
|
+
|
|
275
|
+
declare function useAutosave(enabled?: boolean, registry?: ComponentRegistry, storageKey?: string): void;
|
|
276
|
+
|
|
277
|
+
type RestoreStatus = "loading" | "ready" | "blocked";
|
|
278
|
+
interface RestoreController {
|
|
279
|
+
status: RestoreStatus;
|
|
280
|
+
startFreshAfterDiscardingSavedData: () => void;
|
|
281
|
+
}
|
|
282
|
+
declare function useRestorePage(registry: ComponentRegistry, storageKey?: string): RestoreController;
|
|
283
|
+
|
|
284
|
+
interface Options {
|
|
285
|
+
pageId?: string;
|
|
286
|
+
history?: PageHistoryPersistence;
|
|
287
|
+
enabled?: boolean;
|
|
288
|
+
}
|
|
289
|
+
declare function useHistoryPersistence({ pageId, history, enabled }: Options): void;
|
|
290
|
+
|
|
291
|
+
declare function summarizePageChanges(before: PageDocument, after: PageDocument): PageChangeSummary[];
|
|
292
|
+
interface PageAgentValidationResult {
|
|
293
|
+
valid: boolean;
|
|
294
|
+
diagnostics: PageAgentDiagnostic[];
|
|
295
|
+
changes: PageChangeSummary[];
|
|
296
|
+
}
|
|
297
|
+
declare function validatePageAgentState(current: PageDocument, candidate: PageDocument, registry: ComponentRegistry, permissions?: PageAgentPermissions): PageAgentValidationResult;
|
|
298
|
+
|
|
299
|
+
interface Props {
|
|
300
|
+
agent: PageAgent;
|
|
301
|
+
registry: ComponentRegistry;
|
|
302
|
+
pageId?: string;
|
|
303
|
+
permissions?: PageAgentPermissions;
|
|
304
|
+
baseRevision?: string;
|
|
305
|
+
}
|
|
306
|
+
declare function PageAssistant({ agent, registry, pageId, permissions, baseRevision }: Props): react.JSX.Element;
|
|
307
|
+
|
|
308
|
+
export { type ApplyPageStateInput, type ApplyPageStateResult, type DesignPanelProps, type DesignPublishInput, type DesignPublishResult, type DesignPublisher, Editor, type EditorDesignOptions, type EditorPreviewOptions, type EditorProps, type PageAgent, type PageAgentChatInput, type PageAgentChatResult, type PageAgentContext, type PageAgentDiagnostic, type PageAgentPermissions, PageAssistant, type PageChangeSummary, type PageHistoryEntry, type PageHistoryLoadInput, type PageHistoryPersistence, type PageHistorySaveInput, type PagePublishInput, type PagePublishResult, type PagePublisher, type PublicComponentDefinition, type PublicFieldDefinition, type RestoreController, type RestoreStatus, projectPublicComponents, summarizePageChanges, useAutosave, useEditor, useEditorStore, useHistoryPersistence, useKeyboardShortcuts, useRestorePage, useSelectedNode, validatePageAgentState };
|