@b10cks/client 1.10.0 → 1.12.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/README.md +35 -5
- package/dist/index.cjs +45 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +116 -15
- package/dist/index.mjs +559 -118
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -57,10 +57,12 @@ declare type ApiQueryParams = Omit<IBBaseQueryParams, 'token'> & Record<string,
|
|
|
57
57
|
declare type ApiResourceResponse<T> = IBResponse<T> | T;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* Wire a DOM element as a selectable block
|
|
61
|
-
* and
|
|
62
|
-
*
|
|
63
|
-
*
|
|
60
|
+
* Wire a DOM element as a selectable block. A click selects it in the editor
|
|
61
|
+
* and never reaches links or buttons inside it. Only the innermost editable
|
|
62
|
+
* under the pointer or matching the editor's selection is highlighted, with a
|
|
63
|
+
* label. Toggles `b10cks-selected`, `b10cks-hover`, and `b10cks-hidden` (while
|
|
64
|
+
* the editor hides the block) on the element. Returns a
|
|
65
|
+
* cleanup function. No-op outside preview mode.
|
|
64
66
|
*/
|
|
65
67
|
export declare function attachEditable(el: HTMLElement, options: AttachEditableOptions): () => void;
|
|
66
68
|
|
|
@@ -84,10 +86,14 @@ export declare interface AttachEditableFieldOptions {
|
|
|
84
86
|
* targets a complex value.
|
|
85
87
|
*/
|
|
86
88
|
mode?: EditableFieldMode;
|
|
89
|
+
/** Label for `select` mode. Defaults to the field name. */
|
|
90
|
+
label?: string;
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
export declare interface AttachEditableOptions {
|
|
90
94
|
id: string;
|
|
95
|
+
/** Shown on the selection and hover label. A slug like `hero_section` reads as `Hero section`. */
|
|
96
|
+
label?: string;
|
|
91
97
|
onSelectChange?: (selected: boolean) => void;
|
|
92
98
|
onHoverChange?: (hovered: boolean) => void;
|
|
93
99
|
/** Scroll the element into view when it becomes selected. Default true. */
|
|
@@ -286,6 +292,7 @@ export declare type B10cksLink = {
|
|
|
286
292
|
anchor?: string;
|
|
287
293
|
target?: '_self' | '_blank' | '_parent' | '_top';
|
|
288
294
|
rel?: string;
|
|
295
|
+
params?: B10cksLinkParams;
|
|
289
296
|
} | {
|
|
290
297
|
type: 'email';
|
|
291
298
|
email: string;
|
|
@@ -298,7 +305,7 @@ export declare type B10cksLink = {
|
|
|
298
305
|
url: string;
|
|
299
306
|
title: string;
|
|
300
307
|
content: string;
|
|
301
|
-
params?:
|
|
308
|
+
params?: B10cksLinkParams;
|
|
302
309
|
anchor?: string;
|
|
303
310
|
target?: '_self' | '_blank' | '_parent' | '_top';
|
|
304
311
|
} | {
|
|
@@ -306,6 +313,9 @@ export declare type B10cksLink = {
|
|
|
306
313
|
id: string;
|
|
307
314
|
};
|
|
308
315
|
|
|
316
|
+
/** Query params stored on a link: a key/value map (CMS format) or a raw query string. */
|
|
317
|
+
export declare type B10cksLinkParams = Record<string, string> | string;
|
|
318
|
+
|
|
309
319
|
export declare interface B10cksLinkResolved {
|
|
310
320
|
href: string;
|
|
311
321
|
target: string;
|
|
@@ -317,6 +327,47 @@ export declare interface B10cksLinkResolved {
|
|
|
317
327
|
*/
|
|
318
328
|
export declare function bindPreviewStore<T>(store: PreviewStore<T>): () => void;
|
|
319
329
|
|
|
330
|
+
/** `hide` and `show` set the block's visibility and do nothing when it already is. */
|
|
331
|
+
export declare type BlockAction = 'move-up' | 'move-down' | 'duplicate' | 'delete' | 'insert-before' | 'insert-after' | 'hide' | 'show';
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Ask the editor to run a structural action on a block. The editor validates
|
|
335
|
+
* it, applies it, and answers with CONTENT_UPDATE (and SELECT_UPDATE where the
|
|
336
|
+
* selection moves). `insert-*` opens the editor's block picker.
|
|
337
|
+
*/
|
|
338
|
+
export declare type BlockActionEvent = {
|
|
339
|
+
itemId: string;
|
|
340
|
+
action: BlockAction;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Attributes that make a block addressable as a link anchor: `{ id: block.id }`.
|
|
345
|
+
*
|
|
346
|
+
* `v-editable` (Vue) and `B10cksComponent` (React) set the id already. Spread this onto the
|
|
347
|
+
* root element of blocks rendered without them. Block ids are ULIDs and can start with a
|
|
348
|
+
* digit, so look them up with `getElementById` (or `CSS.escape` for `querySelector`).
|
|
349
|
+
*/
|
|
350
|
+
export declare function blockAnchorAttrs(block: {
|
|
351
|
+
id?: string | null;
|
|
352
|
+
} | null | undefined): {
|
|
353
|
+
id?: string;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/** Display names of the space's blocks, keyed by block slug. */
|
|
357
|
+
export declare type BlockLabelsEvent = {
|
|
358
|
+
labels: Record<string, string>;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Drag and drop: move block `itemId` before or after block `targetId`. The
|
|
363
|
+
* editor rejects moves its schema doesn't allow and answers like BLOCK_ACTION.
|
|
364
|
+
*/
|
|
365
|
+
export declare type BlockMoveEvent = {
|
|
366
|
+
itemId: string;
|
|
367
|
+
targetId: string;
|
|
368
|
+
position: 'before' | 'after';
|
|
369
|
+
};
|
|
370
|
+
|
|
320
371
|
/**
|
|
321
372
|
* Renders a trail as a schema.org `BreadcrumbList`, ready to be serialized into
|
|
322
373
|
* an `application/ld+json` script tag.
|
|
@@ -346,12 +397,27 @@ export declare interface BreadcrumbListJsonLd {
|
|
|
346
397
|
itemListElement: BreadcrumbListItem[];
|
|
347
398
|
}
|
|
348
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Bridge protocol version, sent with the ready announcement. Previews that
|
|
402
|
+
* announce without a payload (protocol 0) understand CONTENT_UPDATE,
|
|
403
|
+
* SELECT_UPDATE, HOVER_UPDATE, and CONTENT_PATCH relative to the root only, so
|
|
404
|
+
* the editor must not send them block-relative patches or labels. Protocol 1
|
|
405
|
+
* adds those and the block actions. Protocol 2 adds HIDDEN_BLOCKS and the `hide` and `show` block
|
|
406
|
+
* actions.
|
|
407
|
+
*/
|
|
408
|
+
export declare const BRIDGE_PROTOCOL = 2;
|
|
409
|
+
|
|
349
410
|
export declare type BridgeEvent = {
|
|
350
411
|
type: EventType;
|
|
351
412
|
payload: EventPayloadMap[EventType];
|
|
352
413
|
b10cksId?: string;
|
|
353
414
|
};
|
|
354
415
|
|
|
416
|
+
/** Payload of the ready announcement. */
|
|
417
|
+
export declare type BridgeReadyPayload = {
|
|
418
|
+
protocol: number;
|
|
419
|
+
};
|
|
420
|
+
|
|
355
421
|
/**
|
|
356
422
|
* Combines a b10cks `full_slug` and `language_iso` into a rooted, locale-prefixed path.
|
|
357
423
|
*
|
|
@@ -364,8 +430,12 @@ export declare interface CollectionFetchOptions {
|
|
|
364
430
|
allPages?: boolean;
|
|
365
431
|
}
|
|
366
432
|
|
|
367
|
-
/**
|
|
433
|
+
/**
|
|
434
|
+
* Granular update: replace the value at `path`. With `itemId`, `path` is
|
|
435
|
+
* relative to that block; without it, relative to the content tree's root.
|
|
436
|
+
*/
|
|
368
437
|
export declare type ContentPatchEvent = {
|
|
438
|
+
itemId?: string;
|
|
369
439
|
path: FieldPath;
|
|
370
440
|
value: unknown;
|
|
371
441
|
};
|
|
@@ -416,10 +486,11 @@ export declare type EditableFieldMode = 'inline' | 'select';
|
|
|
416
486
|
export declare type Endpoint = 'blocks' | `blocks/${string}` | `breadcrumbs/${string}` | 'contents' | `contents/${string}` | `datasources/${string}/entries` | 'datasources' | 'redirects' | 'search' | 'sitemap' | `sitemaps/${string}` | 'spaces/me';
|
|
417
487
|
|
|
418
488
|
/**
|
|
419
|
-
* Inject the preview
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
489
|
+
* Inject the preview styles once: `.b10cks-preview` carries a
|
|
490
|
+
* `scroll-margin-top` so scroll-into-view clears a fixed app header. Set the
|
|
491
|
+
* offset via {@link setPreviewScrollOffset} or the `--b10cks-scroll-offset`
|
|
492
|
+
* CSS variable. Blocks the editor hides carry `b10cks-hidden` and are dimmed.
|
|
493
|
+
* Selection and hover are drawn in a separate overlay layer.
|
|
423
494
|
*/
|
|
424
495
|
export declare function ensurePreviewStyles(): void;
|
|
425
496
|
|
|
@@ -432,9 +503,13 @@ export declare type EventPayloadMap = {
|
|
|
432
503
|
HOVER_UPDATE: SelectUpdateEvent;
|
|
433
504
|
FIELD_UPDATE: FieldUpdateEvent;
|
|
434
505
|
FIELD_SELECT: FieldSelectEvent;
|
|
506
|
+
BLOCK_LABELS: BlockLabelsEvent;
|
|
507
|
+
HIDDEN_BLOCKS: HiddenBlocksEvent;
|
|
508
|
+
BLOCK_ACTION: BlockActionEvent;
|
|
509
|
+
BLOCK_MOVE: BlockMoveEvent;
|
|
435
510
|
};
|
|
436
511
|
|
|
437
|
-
export declare type EventType = 'CONTENT_UPDATE' | 'CONTENT_PATCH' | 'SELECT_UPDATE' | 'HOVER_UPDATE' | 'FIELD_UPDATE' | 'FIELD_SELECT';
|
|
512
|
+
export declare type EventType = 'CONTENT_UPDATE' | 'CONTENT_PATCH' | 'SELECT_UPDATE' | 'HOVER_UPDATE' | 'FIELD_UPDATE' | 'FIELD_SELECT' | 'BLOCK_LABELS' | 'HIDDEN_BLOCKS' | 'BLOCK_ACTION' | 'BLOCK_MOVE';
|
|
438
513
|
|
|
439
514
|
export declare type FetchClient = (input: URL | string | RequestInfo, init?: RequestInit) => Promise<unknown>;
|
|
440
515
|
|
|
@@ -482,6 +557,14 @@ export declare interface GetConfigOptions extends Omit<IBContentQueryParams, 'to
|
|
|
482
557
|
bypassCache?: boolean;
|
|
483
558
|
}
|
|
484
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Ids of every block in the edited content, at any depth, that is hidden.
|
|
562
|
+
* Sent whenever that set changes. Protocol 2.
|
|
563
|
+
*/
|
|
564
|
+
export declare type HiddenBlocksEvent = {
|
|
565
|
+
ids: string[];
|
|
566
|
+
};
|
|
567
|
+
|
|
485
568
|
export declare interface IBBaseQueryParams extends IBPaginationParams, IBSortParams {
|
|
486
569
|
vid?: string;
|
|
487
570
|
version?: string;
|
|
@@ -847,6 +930,8 @@ export declare function normalizePathSegment(value: string | null | undefined):
|
|
|
847
930
|
export declare class PreviewBridge {
|
|
848
931
|
private static instance;
|
|
849
932
|
private readonly listeners;
|
|
933
|
+
/** Last payload received per event type, for consumers that attach late. */
|
|
934
|
+
private readonly received;
|
|
850
935
|
private initialized;
|
|
851
936
|
private allowedOrigins;
|
|
852
937
|
/** Origin of the editor, captured from the first trusted message. */
|
|
@@ -857,6 +942,11 @@ export declare class PreviewBridge {
|
|
|
857
942
|
destroy(): void;
|
|
858
943
|
isInPreviewMode(): boolean;
|
|
859
944
|
on<T extends EventType>(eventType: T, callback: EventCallback<EventPayloadMap[T]>): () => void;
|
|
945
|
+
/**
|
|
946
|
+
* The last payload the editor sent for `eventType`. The editor replays state
|
|
947
|
+
* right after the ready announcement, often before components mount.
|
|
948
|
+
*/
|
|
949
|
+
latest<T extends EventType>(eventType: T): EventPayloadMap[T] | undefined;
|
|
860
950
|
selectItem(selectedItem: string): void;
|
|
861
951
|
/** Deep-select a nested field (e.g. a rich text field) in the editor. */
|
|
862
952
|
selectField(itemId: string, path: FieldPath): void;
|
|
@@ -864,6 +954,10 @@ export declare class PreviewBridge {
|
|
|
864
954
|
updateField(itemId: string, field: string, value: string): void;
|
|
865
955
|
/** Stream an inline edit back to the editor, addressed by path. */
|
|
866
956
|
updateFieldAt(itemId: string, path: FieldPath, value: unknown): void;
|
|
957
|
+
/** Ask the editor to move, duplicate, delete, hide, show, or insert next to a block. */
|
|
958
|
+
blockAction(itemId: string, action: BlockAction): void;
|
|
959
|
+
/** Ask the editor to move a block before or after another block. */
|
|
960
|
+
moveBlock(itemId: string, targetId: string, position: BlockMoveEvent['position']): void;
|
|
867
961
|
private post;
|
|
868
962
|
private handleMessage;
|
|
869
963
|
private isOriginTrusted;
|
|
@@ -899,7 +993,11 @@ export declare class PreviewStore<T = Record<string, unknown>> {
|
|
|
899
993
|
* Unknown ids are ignored and do not notify subscribers.
|
|
900
994
|
*/
|
|
901
995
|
applyContentUpdate(update: Record<string, unknown>): void;
|
|
902
|
-
|
|
996
|
+
/**
|
|
997
|
+
* Replace the value at `path`. With `itemId`, `path` is relative to that
|
|
998
|
+
* block (the root when its id matches). Unknown ids are ignored.
|
|
999
|
+
*/
|
|
1000
|
+
patch(path: FieldPath, value: unknown, itemId?: string): void;
|
|
903
1001
|
private emit;
|
|
904
1002
|
}
|
|
905
1003
|
|
|
@@ -930,8 +1028,9 @@ export declare function renderSitemapXml(entries: IBSitemapEntry[], siteUrl?: st
|
|
|
930
1028
|
* Resolves a B10cksLink value to a plain { href, target } object.
|
|
931
1029
|
*
|
|
932
1030
|
* - `'email'` links produce a `mailto:` href with optional subject/body/cc/bcc query params.
|
|
933
|
-
* - `'url'` and `'internal'` links use the stored `url` field
|
|
934
|
-
*
|
|
1031
|
+
* - `'url'` and `'internal'` links use the stored `url` field, then append `params` as a query
|
|
1032
|
+
* string and `anchor` as a `#fragment` (`/page?x=1#01kh…`). An href that already carries a
|
|
1033
|
+
* fragment keeps it.
|
|
935
1034
|
* - `'asset'` links cannot be resolved to a URL without the asset record — returns `undefined`.
|
|
936
1035
|
* - Locale prefixing and router integration are intentionally left to the caller.
|
|
937
1036
|
*/
|
|
@@ -942,8 +1041,9 @@ export declare type RootBlock<T> = T & {
|
|
|
942
1041
|
block: string;
|
|
943
1042
|
};
|
|
944
1043
|
|
|
1044
|
+
/** `selectedItem` is null when the editor clears the selection or hover. */
|
|
945
1045
|
export declare type SelectUpdateEvent = {
|
|
946
|
-
selectedItem: string;
|
|
1046
|
+
selectedItem: string | null;
|
|
947
1047
|
};
|
|
948
1048
|
|
|
949
1049
|
export declare function serializeFilter(filter: Record<string, unknown>): Record<string, string>;
|
|
@@ -1053,6 +1153,7 @@ export declare namespace types {
|
|
|
1053
1153
|
IBSpace,
|
|
1054
1154
|
IBRedirect,
|
|
1055
1155
|
IBContentQueryParams,
|
|
1156
|
+
B10cksLinkParams,
|
|
1056
1157
|
B10cksLink,
|
|
1057
1158
|
B10cksAssetA11y,
|
|
1058
1159
|
B10cksAssetThumbnail,
|