@standhigher/puck-page-builder 0.9.0 → 0.10.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 CHANGED
@@ -1,12 +1,13 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ExtensionRegistry } from './extensions.js';
4
- export { BlockDefinition, BlockEditorProps, BlockVariantDefinition, DataSourceDefinition, EditorAction, EditorActionPosition, ExtensionActionContext, ExtensionRegistryError, ExtensionRegistryErrorCode, ExtensionRegistryOptions, ExtensionTarget, FieldConfig, FieldDefinition, FieldProps, LifecycleHooks, PageBuilderExtension, RendererDefinition, TemplateDefinition, TemplateRegistry, TemplateSource, UISlotContribution, UISlotName, ValidationIssue, createExtensionRegistry, createTemplateRegistry } from './extensions.js';
3
+ import { f as EditorOperationPolicy, c as BlockPolicy, V as ValidationIssue, h as ExtensionRegistry } from './registry-eNtkEC6o.js';
4
+ export { B as BlockDefinition, a as BlockEditorProps, b as BlockOperation, d as BlockVariantDefinition, D as DataSourceDefinition, E as EditorAction, e as EditorActionPosition, g as ExtensionActionContext, i as ExtensionRegistryError, j as ExtensionRegistryErrorCode, k as ExtensionRegistryOptions, l as ExtensionTarget, F as FieldConfig, m as FieldDefinition, n as FieldProps, o as FieldValidation, L as LifecycleHooks, P as PageBuilderExtension, R as RendererDefinition, T as TemplateDefinition, p as TemplateRegistry, q as TemplateSource, U as UISlotContribution, r as UISlotName, s as createExtensionRegistry, t as createTemplateRegistry } from './registry-eNtkEC6o.js';
5
5
  import { PageDocument, BlockNode, JsonValue } from './schema.js';
6
6
  export { BlockStyleOverrides, DataBinding, PageDocumentIssue, PageDocumentMigration, PageDocumentSchemaVersion, PageSettings, RenderTarget, createPageDocument, migratePageDocument, validatePageDocument } from './schema.js';
7
7
  export { ThemeTokenName, ThemeTokens, mergeThemeTokens, normalizeThemeTokens, systemThemeTokens, toThemeStyle } from './theme.js';
8
8
  import { Data } from '@puckeditor/core';
9
9
  export { WebRenderer, WebRendererProps } from './renderer.js';
10
+ export { maximumBlockInstances, mergeBlockPolicies, minimumBlockInstances, validateBlockPolicy, validateFieldValue, validatePageDocumentWithRegistry } from './extensions.js';
10
11
 
11
12
  type BlockView = "blocks" | "outline";
12
13
  type Device = "desktop" | "tablet" | "mobile" | "full";
@@ -44,6 +45,100 @@ type EditorShellProps = {
44
45
  };
45
46
  declare function EditorShell({ initialState, iframe }: EditorShellProps): react.JSX.Element;
46
47
 
48
+ /** Host-level rules that supplement policies declared by extension blocks. */
49
+ type PageDocumentEditorPolicy = {
50
+ operations?: EditorOperationPolicy;
51
+ blocks?: Record<string, BlockPolicy>;
52
+ };
53
+
54
+ /** An opaque lease returned by the host's single-editor lock service. */
55
+ type EditorSession = {
56
+ id: string;
57
+ expiresAt?: string;
58
+ };
59
+ type EditorSessionState = "acquiring" | "active" | "locked" | "lost" | "readonly";
60
+ type EditorSessionAcquireResult = {
61
+ state: "active";
62
+ session: EditorSession;
63
+ } | {
64
+ state: "locked";
65
+ message?: string;
66
+ editorName?: string;
67
+ } | {
68
+ state: "readonly";
69
+ message?: string;
70
+ };
71
+ /**
72
+ * Host-owned single-editor locking. The package never stores locks or makes
73
+ * authorization decisions; it only coordinates the supplied lease.
74
+ */
75
+ type EditorSessionAdapter = {
76
+ acquire(input: {
77
+ pageId: string;
78
+ }): Promise<EditorSessionAcquireResult>;
79
+ heartbeat?(input: {
80
+ pageId: string;
81
+ session: EditorSession;
82
+ }): Promise<void>;
83
+ release?(input: {
84
+ pageId: string;
85
+ session: EditorSession;
86
+ }): Promise<void>;
87
+ heartbeatIntervalMs?: number;
88
+ };
89
+ type DraftSaveInput = {
90
+ document: PageDocument;
91
+ expectedRevision?: number;
92
+ session?: EditorSession;
93
+ };
94
+ type DraftSaveResult = {
95
+ revision?: number;
96
+ savedAt?: string;
97
+ };
98
+ /** Host-owned draft persistence used by manual and automatic saves. */
99
+ type DraftPersistenceAdapter = {
100
+ saveDraft(input: DraftSaveInput): Promise<DraftSaveResult | void>;
101
+ };
102
+ type PublishActionInput = DraftSaveInput & {
103
+ validationIssues: readonly ValidationIssue[];
104
+ };
105
+ type PublishActionResult = {
106
+ versionId?: string;
107
+ versionLabel?: string;
108
+ publishedAt?: string;
109
+ };
110
+ /** Host-owned publication transaction. It should validate and publish atomically. */
111
+ type PublishAction = {
112
+ publish(input: PublishActionInput): Promise<PublishActionResult | void>;
113
+ };
114
+ type AssetStatus = "ready" | "processing" | "failed" | "missing";
115
+ type AssetReference = {
116
+ id: string;
117
+ url: string;
118
+ alt?: string;
119
+ status?: AssetStatus;
120
+ };
121
+ /**
122
+ * Opens a host-owned, shop-scoped asset picker. Upload, access checks, and
123
+ * storage remain outside the editor package.
124
+ */
125
+ type AssetPickerAdapter = {
126
+ selectAsset(input: {
127
+ pageId: string;
128
+ blockId: string;
129
+ current?: Partial<AssetReference>;
130
+ }): Promise<AssetReference | null>;
131
+ };
132
+ type PagePublicationStatus = "unpublished" | "published";
133
+ /** Presentational data for the reusable page state card. */
134
+ type PageStatus = {
135
+ draftLabel?: string;
136
+ publicationStatus: PagePublicationStatus;
137
+ publishedVersionLabel?: string;
138
+ lastSavedAt?: string;
139
+ editingBy?: string;
140
+ };
141
+
47
142
  type EditorLoadState = "loading" | "ready" | "empty" | "error" | "disabled" | "success";
48
143
  type EditorActionState = {
49
144
  canUndo: boolean;
@@ -58,32 +153,48 @@ type EditorContextValue = {
58
153
  document: PageDocument;
59
154
  selectedBlockId: string | null;
60
155
  selectedBlock: BlockNode | null;
156
+ pendingDeleteBlock: BlockNode | null;
61
157
  canvasSelectionRequest: string | null;
62
158
  device: Device;
63
159
  loadState: EditorLoadState;
160
+ sessionState: EditorSessionState;
161
+ session?: EditorSession;
162
+ sessionMessage?: string;
163
+ isEditable: boolean;
64
164
  isDirty: boolean;
65
165
  actionState: EditorActionState;
166
+ canAddBlock(type: string): boolean;
167
+ canDragBlock(id: string): boolean;
66
168
  /** Request a canvas selection. The inspector changes only after Puck confirms it. */
67
169
  requestCanvasSelection(id: string): void;
68
170
  /** Called from the canvas/Puck selection event. */
69
171
  confirmCanvasSelection(id: string | null): void;
70
172
  /** Applies an edit that originated in the canvas engine. */
71
- updateFromCanvas(document: PageDocument): void;
173
+ updateFromCanvas(document: PageDocument): boolean;
72
174
  setDevice(device: Device): void;
73
175
  addBlock(type: string, beforeId?: string): string | null;
74
176
  duplicateBlock(id: string): void;
177
+ requestDeleteBlock(id: string): void;
178
+ cancelDeleteBlock(): void;
179
+ confirmDeleteBlock(): void;
75
180
  deleteBlock(id: string): void;
76
181
  moveBlock(id: string, direction: -1 | 1): void;
77
182
  reorderBlock(id: string, beforeId: string): void;
78
183
  updateBlockProps(id: string, props: Record<string, JsonValue>): void;
184
+ updateBlockPresentation(id: string, presentation: Pick<BlockNode, "variant" | "style">): void;
79
185
  undo(): void;
80
186
  redo(): void;
81
- markSaved(): void;
187
+ /** Marks the persisted snapshot clean without discarding edits made while saving. */
188
+ markSaved(document?: PageDocument): void;
82
189
  };
83
- declare function EditorProvider({ initialDocument, registry, loadState, leaveWarning, onDocumentChange, children }: {
190
+ declare function EditorProvider({ initialDocument, registry, policy, loadState, sessionState, session, sessionMessage, leaveWarning, onDocumentChange, children }: {
84
191
  initialDocument: PageDocument;
85
192
  registry?: ExtensionRegistry;
193
+ policy?: PageDocumentEditorPolicy;
86
194
  loadState?: EditorLoadState;
195
+ sessionState?: EditorSessionState;
196
+ session?: EditorSession;
197
+ sessionMessage?: string;
87
198
  leaveWarning?: string;
88
199
  onDocumentChange?: (document: PageDocument) => void;
89
200
  children: ReactNode;
@@ -94,17 +205,62 @@ type PageDocumentEditorShellProps = {
94
205
  initialDocument: PageDocument;
95
206
  iframe?: boolean;
96
207
  registry?: ExtensionRegistry;
208
+ /** Limits the add-block library; existing document blocks remain editable. */
209
+ availableBlockTypes?: readonly string[];
210
+ /** Enables generic Variant and token-only style editing in the inspector. */
211
+ appearanceControls?: boolean;
212
+ /** Host rules that supplement block-declared operation and cardinality policies. */
213
+ policy?: PageDocumentEditorPolicy;
214
+ /** Copy or presentation overrides for the built-in, two-step deletion dialog. */
215
+ deleteConfirmation?: DeleteConfirmationConfig;
97
216
  /** Presentation states are explicit so host applications can provide a consistent Admin experience. */
98
217
  loadState?: EditorLoadState;
99
218
  adminLocale?: string;
100
219
  onDocumentChange?: (document: PageDocument) => void;
101
- /** Persist the current draft. The shell marks the document clean only after this resolves. */
220
+ /** @deprecated Prefer draftPersistence so revision and edit-session metadata are preserved. */
102
221
  onSave?: (document: PageDocument) => Promise<void> | void;
103
- /** Publish the current document. Hosts should persist it atomically with publication. */
222
+ /** @deprecated Prefer publishAction so revision and edit-session metadata are preserved. */
104
223
  onPublish?: (document: PageDocument) => Promise<void> | void;
224
+ /** Host-owned single-editor lock. Without this adapter the package stays backwards-compatible and editable. */
225
+ sessionAdapter?: EditorSessionAdapter;
226
+ onSessionStateChange?: (state: EditorSessionState) => void;
227
+ /** Host-owned draft persistence shared by the manual-save and 800ms autosave paths. */
228
+ draftPersistence?: DraftPersistenceAdapter;
229
+ draftRevision?: number;
230
+ autoSave?: boolean;
231
+ autoSaveDelayMs?: number;
232
+ /** Host-owned atomic publish transaction. */
233
+ publishAction?: PublishAction;
234
+ /** Host-owned picker/uploader for shop-scoped assets. */
235
+ assetPicker?: AssetPickerAdapter;
236
+ /** Optional reusable page lifecycle summary. */
237
+ pageStatus?: PageStatus;
238
+ onBack?: () => void;
239
+ onPreview?: (input: {
240
+ document: PageDocument;
241
+ draftRevision?: number;
242
+ session?: EditorSession;
243
+ }) => Promise<void> | void;
244
+ onAddToStore?: (input: {
245
+ document: PageDocument;
246
+ session?: EditorSession;
247
+ }) => Promise<void> | void;
248
+ };
249
+ type DeleteConfirmationConfig = {
250
+ title?: string;
251
+ message?: (block: BlockNode) => ReactNode;
252
+ cancelLabel?: string;
253
+ confirmLabel?: string;
105
254
  };
106
255
  declare function PageDocumentEditorShell(props: PageDocumentEditorShellProps): react.JSX.Element;
107
256
 
257
+ type PageStatusCardProps = {
258
+ status: PageStatus;
259
+ sessionState?: EditorSessionState;
260
+ };
261
+ /** A small, host-data-driven summary suitable for an editor header or page list. */
262
+ declare function PageStatusCard({ status, sessionState }: PageStatusCardProps): react.JSX.Element;
263
+
108
264
  type AdminLocale = "zh-CN" | "en";
109
265
  declare const messages: {
110
266
  readonly "zh-CN": {
@@ -116,6 +272,10 @@ declare const messages: {
116
272
  readonly redo: "恢复";
117
273
  readonly duplicate: "复制";
118
274
  readonly remove: "删除";
275
+ readonly confirmDeleteTitle: "确认删除区块?";
276
+ readonly confirmDeleteMessage: "删除后可使用撤销恢复。";
277
+ readonly cancel: "取消";
278
+ readonly confirm: "确认删除";
119
279
  readonly moveUp: "上移";
120
280
  readonly moveDown: "下移";
121
281
  readonly loading: "正在加载编辑器…";
@@ -130,8 +290,21 @@ declare const messages: {
130
290
  readonly publish: "发布";
131
291
  readonly publishing: "正在发布…";
132
292
  readonly saveFailed: "保存草稿失败";
293
+ readonly retrySave: "重试保存";
294
+ readonly offline: "当前离线,恢复网络后将自动保存";
133
295
  readonly publishFailed: "发布失败";
134
296
  readonly published: "已发布";
297
+ readonly back: "返回";
298
+ readonly confirmLeaveTitle: "离开编辑器?";
299
+ readonly leave: "离开";
300
+ readonly zoom: "缩放";
301
+ readonly zoomAuto: "自动缩放";
302
+ readonly preview: "正式预览";
303
+ readonly addToStore: "添加到店铺";
304
+ readonly acquiringLock: "正在获取编辑锁…";
305
+ readonly locked: "该页面正在被编辑";
306
+ readonly lockLost: "编辑锁已失效";
307
+ readonly readonly: "页面为只读状态";
135
308
  readonly leaveWarning: "你有未保存的更改。确定要离开吗?";
136
309
  readonly selectBlock: "选择一个区块以编辑。";
137
310
  readonly desktop: "桌面";
@@ -147,6 +320,10 @@ declare const messages: {
147
320
  readonly redo: "Redo";
148
321
  readonly duplicate: "Duplicate";
149
322
  readonly remove: "Delete";
323
+ readonly confirmDeleteTitle: "Delete this block?";
324
+ readonly confirmDeleteMessage: "You can restore it with Undo after deleting.";
325
+ readonly cancel: "Cancel";
326
+ readonly confirm: "Delete block";
150
327
  readonly moveUp: "Move up";
151
328
  readonly moveDown: "Move down";
152
329
  readonly loading: "Loading editor…";
@@ -161,8 +338,21 @@ declare const messages: {
161
338
  readonly publish: "Publish";
162
339
  readonly publishing: "Publishing…";
163
340
  readonly saveFailed: "Could not save draft";
341
+ readonly retrySave: "Retry save";
342
+ readonly offline: "Offline — changes will save when connection returns";
164
343
  readonly publishFailed: "Could not publish";
165
344
  readonly published: "Published";
345
+ readonly back: "Back";
346
+ readonly confirmLeaveTitle: "Leave the editor?";
347
+ readonly leave: "Leave";
348
+ readonly zoom: "Zoom";
349
+ readonly zoomAuto: "Auto zoom";
350
+ readonly preview: "Preview";
351
+ readonly addToStore: "Add to store";
352
+ readonly acquiringLock: "Acquiring edit lock…";
353
+ readonly locked: "This page is being edited";
354
+ readonly lockLost: "The edit lock has expired";
355
+ readonly readonly: "This page is read-only";
166
356
  readonly leaveWarning: "You have unsaved changes. Are you sure you want to leave?";
167
357
  readonly selectBlock: "Select a block to edit it.";
168
358
  readonly desktop: "Desktop";
@@ -174,10 +364,10 @@ type AdminMessageKey = keyof typeof messages["zh-CN"];
174
364
  /** Minimal, dependency-free Admin copy catalog. Product locale remains PageDocument.settings.locale. */
175
365
  declare function createAdminI18n(locale?: string): {
176
366
  locale: AdminLocale;
177
- t: (key: AdminMessageKey) => "Desktop" | "Tablet" | "Mobile" | "未保存变更" | "Outline" | "区块" | "结构" | "撤销" | "恢复" | "属性" | "添加区块" | "复制" | "删除" | "上移" | "下移" | "正在加载编辑器…" | "页面还没有区块" | "编辑器无法加载" | "编辑器当前不可编辑" | "操作已完成" | "所有更改已保留在当前会话中" | "保存草稿" | "正在保存…" | "发布" | "正在发布…" | "保存草稿失败" | "发布失败" | "已发布" | "你有未保存的更改。确定要离开吗?" | "选择一个区块以编辑。" | "桌面" | "平板" | "手机" | "Blocks" | "Properties" | "Add block" | "Undo" | "Redo" | "Duplicate" | "Delete" | "Move up" | "Move down" | "Loading editor…" | "This page has no blocks" | "The editor could not load" | "The editor is currently read-only" | "Action completed" | "Unsaved changes" | "Changes are kept in this session" | "Save draft" | "Saving…" | "Publish" | "Publishing…" | "Could not save draft" | "Could not publish" | "Published" | "You have unsaved changes. Are you sure you want to leave?" | "Select a block to edit it.";
367
+ t: (key: AdminMessageKey) => "Desktop" | "Tablet" | "Mobile" | "未保存变更" | "Outline" | "Preview" | "缩放" | "区块" | "结构" | "撤销" | "恢复" | "Delete" | "Duplicate" | "编辑锁已失效" | "属性" | "添加区块" | "复制" | "删除" | "确认删除区块?" | "删除后可使用撤销恢复。" | "取消" | "确认删除" | "上移" | "下移" | "正在加载编辑器…" | "页面还没有区块" | "编辑器无法加载" | "编辑器当前不可编辑" | "操作已完成" | "所有更改已保留在当前会话中" | "保存草稿" | "正在保存…" | "发布" | "正在发布…" | "保存草稿失败" | "重试保存" | "当前离线,恢复网络后将自动保存" | "发布失败" | "已发布" | "返回" | "离开编辑器?" | "离开" | "自动缩放" | "正式预览" | "添加到店铺" | "正在获取编辑锁…" | "该页面正在被编辑" | "页面为只读状态" | "你有未保存的更改。确定要离开吗?" | "选择一个区块以编辑。" | "桌面" | "平板" | "手机" | "Blocks" | "Properties" | "Add block" | "Undo" | "Redo" | "Delete this block?" | "You can restore it with Undo after deleting." | "Cancel" | "Delete block" | "Move up" | "Move down" | "Loading editor…" | "This page has no blocks" | "The editor could not load" | "The editor is currently read-only" | "Action completed" | "Unsaved changes" | "Changes are kept in this session" | "Save draft" | "Saving…" | "Publish" | "Publishing…" | "Could not save draft" | "Retry save" | "Offline — changes will save when connection returns" | "Could not publish" | "Published" | "Back" | "Leave the editor?" | "Leave" | "Zoom" | "Auto zoom" | "Add to store" | "Acquiring edit lock…" | "This page is being edited" | "The edit lock has expired" | "This page is read-only" | "You have unsaved changes. Are you sure you want to leave?" | "Select a block to edit it.";
178
368
  };
179
369
 
180
370
  declare function toEngineData(document: PageDocument, registry?: ExtensionRegistry): Data;
181
371
  declare function fromEngineData(data: Data, base: PageDocument, registry?: ExtensionRegistry): PageDocument;
182
372
 
183
- export { type AdminLocale, type AdminMessageKey, BlockNode, type DemoBlock, type Device, type EditorActionState, type EditorLoadState, EditorProvider, EditorShell, type EditorShellProps, type EditorState, ExtensionRegistry, JsonValue, PageDocument, PageDocumentEditorShell, type PageDocumentEditorShellProps, type PreviewMode, type PublishState, type SaveState, type Zoom, createAdminI18n, fromEngineData, toEngineData, useEditorContext };
373
+ export { type AdminLocale, type AdminMessageKey, type AssetPickerAdapter, type AssetReference, type AssetStatus, BlockNode, BlockPolicy, type DeleteConfirmationConfig, type DemoBlock, type Device, type DraftPersistenceAdapter, type DraftSaveInput, type DraftSaveResult, type EditorActionState, type EditorLoadState, EditorOperationPolicy, EditorProvider, type EditorSession, type EditorSessionAcquireResult, type EditorSessionAdapter, type EditorSessionState, EditorShell, type EditorShellProps, type EditorState, ExtensionRegistry, JsonValue, PageDocument, type PageDocumentEditorPolicy, PageDocumentEditorShell, type PageDocumentEditorShellProps, type PagePublicationStatus, type PageStatus, PageStatusCard, type PageStatusCardProps, type PreviewMode, type PublishAction, type PublishActionInput, type PublishActionResult, type PublishState, type SaveState, ValidationIssue, type Zoom, createAdminI18n, fromEngineData, toEngineData, useEditorContext };