@b10cks/client 1.12.0 → 2.0.1

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
@@ -81,9 +81,9 @@ export declare interface AttachEditableFieldOptions {
81
81
  * `inline` makes the element contenteditable and streams plain-text edits
82
82
  * back to the editor — suitable for simple string fields only. `select`
83
83
  * instead deep-selects the field so the editor opens its own editor, which
84
- * is the right choice for rich text and other complex types. Default
85
- * `inline`, or `select` automatically when no `field` is given but a `path`
86
- * targets a complex value.
84
+ * is the right choice for rich text and other complex types. Defaults to
85
+ * `select` for path-only fields and fields wrapping interactive children;
86
+ * other flat fields default to `inline`.
87
87
  */
88
88
  mode?: EditableFieldMode;
89
89
  /** Label for `select` mode. Defaults to the field name. */
@@ -100,6 +100,38 @@ export declare interface AttachEditableOptions {
100
100
  scrollOnSelect?: boolean;
101
101
  }
102
102
 
103
+ /**
104
+ * Make a rendered rich text field editable in place in the preview. A click
105
+ * selects the field in the editor, which answers with the field's settings
106
+ * when the user may edit it; the element then turns into a Tiptap editor with
107
+ * the CMS schema. Edits stream to the editor as FIELD_UPDATE, and changes made
108
+ * in the editor arrive through {@link RichTextFieldHandle.update} without
109
+ * moving the caret. Escape returns to block selection.
110
+ *
111
+ * Without the editor's go-ahead (older editors, read-only users) the field
112
+ * behaves like `attachEditableField` in `select` mode. No-op outside preview
113
+ * mode, where Tiptap is never loaded.
114
+ */
115
+ export declare function attachRichTextField(el: HTMLElement, options: AttachRichTextFieldOptions): RichTextFieldHandle;
116
+
117
+ export declare interface AttachRichTextFieldOptions {
118
+ /** Id of the block the field belongs to. */
119
+ id: string;
120
+ /** Path to the field within the block. */
121
+ path: FieldPath;
122
+ /** The field's document, as rendered into the element. */
123
+ document: RichTextDocument | null | undefined;
124
+ /** Shown on the field's highlight. Defaults to the field name. */
125
+ label?: string;
126
+ /** The options the element was rendered with, so links and placeholders look the same while editing. */
127
+ render?: RichTextHtmlOptions;
128
+ /**
129
+ * Editing started or stopped. While it runs the editor owns the element's
130
+ * content, so keep rendering the HTML you rendered before it started.
131
+ */
132
+ onEditingChange?: (editing: boolean) => void;
133
+ }
134
+
103
135
  export declare interface B10cksApiClientOptions {
104
136
  baseUrl: string;
105
137
  token: string;
@@ -402,10 +434,11 @@ export declare interface BreadcrumbListJsonLd {
402
434
  * announce without a payload (protocol 0) understand CONTENT_UPDATE,
403
435
  * SELECT_UPDATE, HOVER_UPDATE, and CONTENT_PATCH relative to the root only, so
404
436
  * 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.
437
+ * adds those and the block actions, protocol 2 HIDDEN_BLOCKS and the `hide`
438
+ * and `show` block actions, protocol 3 FIELD_CONFIG for in-place rich text
439
+ * editing.
407
440
  */
408
- export declare const BRIDGE_PROTOCOL = 2;
441
+ export declare const BRIDGE_PROTOCOL = 3;
409
442
 
410
443
  export declare type BridgeEvent = {
411
444
  type: EventType;
@@ -483,6 +516,9 @@ export declare type DateFilter = string | {
483
516
 
484
517
  export declare type EditableFieldMode = 'inline' | 'select';
485
518
 
519
+ /** The field a rich text component renders, for its `editable` prop. */
520
+ export declare type EditableRichTextField = Pick<AttachRichTextFieldOptions, 'id' | 'path' | 'label'>;
521
+
486
522
  export declare type Endpoint = 'blocks' | `blocks/${string}` | `breadcrumbs/${string}` | 'contents' | `contents/${string}` | `datasources/${string}/entries` | 'datasources' | 'redirects' | 'search' | 'sitemap' | `sitemaps/${string}` | 'spaces/me';
487
523
 
488
524
  /**
@@ -503,16 +539,28 @@ export declare type EventPayloadMap = {
503
539
  HOVER_UPDATE: SelectUpdateEvent;
504
540
  FIELD_UPDATE: FieldUpdateEvent;
505
541
  FIELD_SELECT: FieldSelectEvent;
542
+ FIELD_CONFIG: FieldConfigEvent;
506
543
  BLOCK_LABELS: BlockLabelsEvent;
507
544
  HIDDEN_BLOCKS: HiddenBlocksEvent;
508
545
  BLOCK_ACTION: BlockActionEvent;
509
546
  BLOCK_MOVE: BlockMoveEvent;
510
547
  };
511
548
 
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';
549
+ export declare type EventType = 'CONTENT_UPDATE' | 'CONTENT_PATCH' | 'SELECT_UPDATE' | 'HOVER_UPDATE' | 'FIELD_UPDATE' | 'FIELD_SELECT' | 'FIELD_CONFIG' | 'BLOCK_LABELS' | 'HIDDEN_BLOCKS' | 'BLOCK_ACTION' | 'BLOCK_MOVE';
513
550
 
514
551
  export declare type FetchClient = (input: URL | string | RequestInfo, init?: RequestInit) => Promise<unknown>;
515
552
 
553
+ /**
554
+ * The editor's answer to FIELD_SELECT for a rich text field the user may edit:
555
+ * the preview can edit it in place, with the field's settings. Not sent for
556
+ * read-only users or other field types. Protocol 3.
557
+ */
558
+ export declare type FieldConfigEvent = {
559
+ itemId: string;
560
+ path: FieldPath;
561
+ richtext: RichTextFieldConfig;
562
+ };
563
+
516
564
  /** Addresses a field within a block, supporting nested objects and arrays. */
517
565
  export declare type FieldPath = (string | number)[];
518
566
 
@@ -954,6 +1002,12 @@ export declare class PreviewBridge {
954
1002
  updateField(itemId: string, field: string, value: string): void;
955
1003
  /** Stream an inline edit back to the editor, addressed by path. */
956
1004
  updateFieldAt(itemId: string, path: FieldPath, value: unknown): void;
1005
+ /**
1006
+ * Apply a patch to the preview's own content, as if the editor had sent it.
1007
+ * For edits made in the preview itself, which the editor doesn't echo back,
1008
+ * so a content store rendering the page stays current.
1009
+ */
1010
+ patchLocal(patch: ContentPatchEvent): void;
957
1011
  /** Ask the editor to move, duplicate, delete, hide, show, or insert next to a block. */
958
1012
  blockAction(itemId: string, action: BlockAction): void;
959
1013
  /** Ask the editor to move a block before or after another block. */
@@ -1036,6 +1090,96 @@ export declare function renderSitemapXml(entries: IBSitemapEntry[], siteUrl?: st
1036
1090
  */
1037
1091
  export declare function resolveB10cksLink(link: B10cksLink | undefined | null): B10cksLinkResolved | undefined;
1038
1092
 
1093
+ declare interface RichTextDocument {
1094
+ type: string
1095
+ content?: RichTextDocument[]
1096
+ text?: string
1097
+ marks?: RichTextMark[]
1098
+ attrs?: Record<string, unknown>
1099
+ }
1100
+
1101
+ /** Features a rich text field can switch off in the CMS field settings. */
1102
+ declare type RichTextFeature =
1103
+ | 'bold'
1104
+ | 'italic'
1105
+ | 'underline'
1106
+ | 'strike'
1107
+ | 'code'
1108
+ | 'heading'
1109
+ | 'bulletList'
1110
+ | 'orderedList'
1111
+ | 'blockquote'
1112
+ | 'codeBlock'
1113
+ | 'horizontalRule'
1114
+ | 'link'
1115
+ | 'internalLink'
1116
+ | 'table'
1117
+
1118
+ /** How a rich text field is configured in the CMS. */
1119
+ declare interface RichTextFieldConfig {
1120
+ /** A feature is on unless set to `false`, like in the CMS. */
1121
+ features?: Partial<Record<RichTextFeature, boolean>>
1122
+ /** Block formats the toolbar offers, in order. */
1123
+ headingLevels?: RichTextHeadingLevel[]
1124
+ }
1125
+
1126
+ export declare interface RichTextFieldHandle {
1127
+ /** Pass the field's latest document whenever it changes. */
1128
+ update: (document: RichTextDocument | null | undefined) => void;
1129
+ destroy: () => void;
1130
+ }
1131
+
1132
+ declare type RichTextHeadingLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'
1133
+
1134
+ declare interface RichTextHtmlOptions {
1135
+ internalLinkHandler?: RichTextInternalLinkHandler
1136
+ placeholderHandler?: RichTextPlaceholderHandler
1137
+ /**
1138
+ * URL schemes (without the trailing colon) permitted in link `href` and
1139
+ * image `src` attributes. URLs with any other scheme are replaced with `'#'`
1140
+ * to prevent script-injecting URLs (e.g. `javascript:`) stored in CMS
1141
+ * content from executing. Relative URLs are always allowed.
1142
+ *
1143
+ * Defaults to {@link DEFAULT_ALLOWED_SCHEMES}. To additionally allow
1144
+ * `javascript:` URLs, pass
1145
+ * `[...DEFAULT_ALLOWED_SCHEMES, 'javascript']`.
1146
+ */
1147
+ allowedSchemes?: string[]
1148
+ }
1149
+
1150
+ declare interface RichTextInternalLinkAttrs {
1151
+ url?: string | null
1152
+ href?: string | null
1153
+ title?: string | null
1154
+ target?: string | null
1155
+ rel?: string | null
1156
+ anchor?: string | null
1157
+ content?: string | null
1158
+ cached_url?: string | null
1159
+ linktype?: string | null
1160
+ uuid?: string | null
1161
+ id?: string | null
1162
+ [key: string]: unknown
1163
+ }
1164
+
1165
+ declare type RichTextInternalLinkHandler = (
1166
+ attrs: RichTextInternalLinkAttrs
1167
+ ) => string | null | undefined
1168
+
1169
+ declare interface RichTextMark {
1170
+ type: string
1171
+ attrs?: Record<string, unknown>
1172
+ }
1173
+
1174
+ /**
1175
+ * Resolves a placeholder token to its real value.
1176
+ * Receives the token's `key` (e.g. `"companyName"`) and `label` (the display
1177
+ * hint shown in the editor, e.g. `"{companyName}"`).
1178
+ * Return the replacement string, or null/undefined to leave the token as-is
1179
+ * (rendered as a `<span data-type="placeholder-token">` for client-side use).
1180
+ */
1181
+ declare type RichTextPlaceholderHandler = (key: string, label: string) => string | null | undefined
1182
+
1039
1183
  export declare type RootBlock<T> = T & {
1040
1184
  id: string;
1041
1185
  block: string;