@bettercms-ai/sdk 1.39.0 → 1.40.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/bindings.cjs +146 -0
- package/dist/bindings.cjs.map +1 -0
- package/dist/bindings.d.cts +174 -0
- package/dist/bindings.d.ts +174 -0
- package/dist/bindings.js +109 -0
- package/dist/bindings.js.map +1 -0
- package/dist/in-editor-D1vXPgJh.d.cts +63 -0
- package/dist/in-editor-D1vXPgJh.d.ts +63 -0
- package/dist/index.d.cts +4 -216
- package/dist/index.d.ts +4 -216
- package/dist/live.cjs +158 -0
- package/dist/live.cjs.map +1 -0
- package/dist/live.d.cts +95 -0
- package/dist/live.d.ts +95 -0
- package/dist/live.js +120 -0
- package/dist/live.js.map +1 -0
- package/dist/read-AYzXKCU-.d.cts +191 -0
- package/dist/read-Bb60mWmW.d.ts +191 -0
- package/dist/read.cjs +49 -0
- package/dist/read.cjs.map +1 -1
- package/dist/read.d.cts +1 -38
- package/dist/read.d.ts +1 -38
- package/dist/read.js +44 -0
- package/dist/read.js.map +1 -1
- package/dist/sections.cjs +71 -4
- package/dist/sections.cjs.map +1 -1
- package/dist/sections.d.cts +55 -3
- package/dist/sections.d.ts +55 -3
- package/dist/sections.js +65 -4
- package/dist/sections.js.map +1 -1
- package/package.json +11 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as _bettercms_ai_types from '@bettercms-ai/types';
|
|
2
|
-
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, Fieldset, ComponentPreview, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput,
|
|
2
|
+
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, Fieldset, ComponentPreview, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Page, MediaAsset, FormField, Form, FormSubmission, Workspace, ApiKey, ApiKeyPermission, ApiKeyTokenType } from '@bettercms-ai/types';
|
|
3
3
|
export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthSession, AuthUser, BetterCMSErrorCode, BlockType, ButtonBlock, ButtonProps, ColumnsBlock, ColumnsProps, Content, ContentBlock, ContentEntry, ContentModel, ContentModelField, ContentPageResult, ContentResponse, DeepReadonly, DeliveryComponent, DeliveryEntry, DeliveryList, DeliveryPage, EmbedCard, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, ResolvedAuthor, ResolvedPost, RichTextEmbeds, RichTextResolved, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
4
|
import { D as DeliveryFormField } from './read-client-CnkVzNP0.js';
|
|
5
5
|
export { a as BCMSClientError, E as BCMSErrorCodes, a as BetterCMSError, B as BetterCMSReadClient, C as CreateClientOptions, b as DeliveryForm, c as DeliveryFormFieldType, E as ErrorCodes, F as FormSubmitError, d as FormValue, e as FormValues, G as GetEntryOptions, L as ListEntriesOptions, f as ListPagesOptions, S as SubmitFormOptions, g as SubmitFormResult, h as asStringArray, i as createClient, j as formInitialValues, k as isMultiValueField, s as shouldShowField, l as submitForm, t as toggleOption } from './read-client-CnkVzNP0.js';
|
|
6
|
+
export { C as CONTENT_APPLIED, a as ContentAppliedMessage, E as EDITOR_FRAME_NAME, c as contentApplied, i as inEditor, o as onContentApplied } from './in-editor-D1vXPgJh.js';
|
|
7
|
+
export { P as PORTABLE_TEXT_FORMAT, R as ResolvedHolder, a as RichTextValue, S as SearchHit, b as SearchOptions, T as TextOrRich, e as embeds, i as isRichText, l as lines, p as plain, c as portableText, r as resolved, d as rich, s as search } from './read-Bb60mWmW.js';
|
|
6
8
|
export { ResolvedSeo, SeoInput, SeoLocation, entrySeoInput, resolveSeo } from './seo.js';
|
|
7
|
-
export { SearchHit, SearchOptions, search } from './read.js';
|
|
8
9
|
export { ImageFit, ImageFormat, ImageSource, ImageUrlBuilder, ImageUrlOptions, imageUrl, default as imageUrlBuilder, imageValueObjectPosition, imageValueUrl } from '@bettercms-ai/image-url';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -982,194 +983,6 @@ declare function resolveStega(node: StegaNode): {
|
|
|
982
983
|
element: StegaNode;
|
|
983
984
|
} | null;
|
|
984
985
|
|
|
985
|
-
/**
|
|
986
|
-
* `bcms:content-applied` — what the visual editor tells a page after it has applied an edit to
|
|
987
|
-
* the page's DOM.
|
|
988
|
-
*
|
|
989
|
-
* An edit changes how tall a heading is. Everything on the page that measured the layout once
|
|
990
|
-
* (ScrollTrigger's start and end positions, Lenis's scroll limit, a carousel's slide widths, a
|
|
991
|
-
* text splitter's lines) is now wrong, and only the page's own code can measure again. So the
|
|
992
|
-
* editor posts one message to the frame's window after each applied edit, and the site listens:
|
|
993
|
-
*
|
|
994
|
-
* onContentApplied(() => ScrollTrigger.refresh());
|
|
995
|
-
*
|
|
996
|
-
* A published page receives no such message: nothing there posts it, and the listener is inert.
|
|
997
|
-
*/
|
|
998
|
-
/** The `type` of the message. */
|
|
999
|
-
declare const CONTENT_APPLIED = "bcms:content-applied";
|
|
1000
|
-
interface ContentAppliedMessage {
|
|
1001
|
-
type: typeof CONTENT_APPLIED;
|
|
1002
|
-
/** The field addresses whose rendering changed; empty when the editor does not say. */
|
|
1003
|
-
fields: string[];
|
|
1004
|
-
}
|
|
1005
|
-
/** The message the editor posts: `frame.contentWindow.postMessage(contentApplied(fields), origin)`. */
|
|
1006
|
-
declare const contentApplied: (fields?: readonly string[]) => ContentAppliedMessage;
|
|
1007
|
-
/** The least of `window` this needs. */
|
|
1008
|
-
interface MessageTarget {
|
|
1009
|
-
addEventListener(type: "message", listener: (event: {
|
|
1010
|
-
data: unknown;
|
|
1011
|
-
}) => void): void;
|
|
1012
|
-
removeEventListener(type: "message", listener: (event: {
|
|
1013
|
-
data: unknown;
|
|
1014
|
-
}) => void): void;
|
|
1015
|
-
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Run `handler` after every edit the editor applies to this page. Returns the function that
|
|
1018
|
-
* stops listening. Safe to call where there is no window (a server render): it does nothing.
|
|
1019
|
-
*/
|
|
1020
|
-
declare function onContentApplied(handler: (message: ContentAppliedMessage) => void, target?: MessageTarget | undefined): () => void;
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Reading a rich-text field, for any site.
|
|
1024
|
-
*
|
|
1025
|
-
* A `text` field delivers a bare string. A `richtext` field delivers the canonical envelope
|
|
1026
|
-
* `{ format, value, html }`. Those are different shapes, and switching a field's type in the
|
|
1027
|
-
* CMS switches which one your site receives — the Visual Editor offers exactly that switch,
|
|
1028
|
-
* so it happens on live projects. A template that interpolates the value directly then
|
|
1029
|
-
* renders `[object Object]` (or, in React, throws `Objects are not valid as a React child`).
|
|
1030
|
-
*
|
|
1031
|
-
* No payload can be both structured and safe to interpolate, which is why every headless CMS
|
|
1032
|
-
* requires a renderer for rich text. These are ours:
|
|
1033
|
-
*
|
|
1034
|
-
* plain(v) → text, for <title>, meta descriptions, JSON-LD, alt text, aria-label
|
|
1035
|
-
* rich(v) → HTML, for `set:html` / `dangerouslySetInnerHTML`
|
|
1036
|
-
*
|
|
1037
|
-
* Both accept a bare string, so a field can be switched in the CMS without touching the site.
|
|
1038
|
-
*
|
|
1039
|
-
* <h1 set:html={rich(page.heroTitle)} /> // Astro
|
|
1040
|
-
* <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
|
|
1041
|
-
* seo({ title: plain(page.heroTitle) })
|
|
1042
|
-
*/
|
|
1043
|
-
|
|
1044
|
-
/**
|
|
1045
|
-
* A block in a Body field's `doc`. Bounded vocabulary — the server only emits what it can
|
|
1046
|
-
* parse back, so an unknown `type` means your SDK is older than the content, not that the
|
|
1047
|
-
* content is malformed. Handle the default case rather than exhausting on it.
|
|
1048
|
-
*/
|
|
1049
|
-
type DocBlock = {
|
|
1050
|
-
/**
|
|
1051
|
-
* Stable within THIS document only — never a global key. Two different entries both have a
|
|
1052
|
-
* block called "0.0". A cross-document anchor is (entryId, fieldKey, id).
|
|
1053
|
-
*
|
|
1054
|
-
* Ids on content authored before block ids existed are derived from position, so they SHIFT
|
|
1055
|
-
* when that document is edited. Do not persist an id as a bookmark unless you know it came
|
|
1056
|
-
* from the editor rather than from the positional fallback.
|
|
1057
|
-
*/
|
|
1058
|
-
readonly id: string;
|
|
1059
|
-
readonly type: string;
|
|
1060
|
-
readonly [key: string]: unknown;
|
|
1061
|
-
};
|
|
1062
|
-
/** The `doc` rendition of a Body field — a versioned block array. */
|
|
1063
|
-
type DocValue = {
|
|
1064
|
-
readonly version: 1;
|
|
1065
|
-
readonly blocks: readonly DocBlock[];
|
|
1066
|
-
};
|
|
1067
|
-
/** The canonical rich-text envelope returned by the Delivery API. */
|
|
1068
|
-
interface RichTextValue {
|
|
1069
|
-
readonly format?: string;
|
|
1070
|
-
readonly value?: unknown;
|
|
1071
|
-
/** Server-rendered, sanitized HTML. Computed on write. */
|
|
1072
|
-
readonly html?: string;
|
|
1073
|
-
/**
|
|
1074
|
-
* Structured blocks — present on `document` (Body) fields only, and NOT guaranteed even
|
|
1075
|
-
* there: it is derived at write time, so an entry saved before this existed carries none
|
|
1076
|
-
* until its next save. There is no backfill. Always branch on its absence; `html` is the
|
|
1077
|
-
* field that is always there.
|
|
1078
|
-
*/
|
|
1079
|
-
readonly doc?: DocValue;
|
|
1080
|
-
/**
|
|
1081
|
-
* The embeds the server resolved when it built `html`: X cards keyed by canonical url (X's
|
|
1082
|
-
* script, when a site opts in, is the page's, never the value's). `html` already holds each card, so `rich()` never needs this; it is
|
|
1083
|
-
* for renderers of the STRUCTURE (`<PortableText embeds={…}>`). Absent on a value with no embed
|
|
1084
|
-
* and on any envelope written before it existed: read it through `embeds()`.
|
|
1085
|
-
*/
|
|
1086
|
-
readonly embeds?: RichTextEmbeds;
|
|
1087
|
-
/**
|
|
1088
|
-
* What the value's related posts and author bios point at, resolved by the server for THIS
|
|
1089
|
-
* response from the published entries (never stored). `html` already draws them; this is for
|
|
1090
|
-
* renderers of the structure (`<PortableText resolved={…}>`). Absent on a value with neither block.
|
|
1091
|
-
* Read it through `resolved()`.
|
|
1092
|
-
*/
|
|
1093
|
-
readonly resolved?: RichTextResolved;
|
|
1094
|
-
}
|
|
1095
|
-
/** The marker on a Portable Text envelope. `format` is a plain string, never a union — see below. */
|
|
1096
|
-
declare const PORTABLE_TEXT_FORMAT = "portable-text-1";
|
|
1097
|
-
/**
|
|
1098
|
-
* Structured blocks, when the field stores Portable Text.
|
|
1099
|
-
*
|
|
1100
|
-
* ── The compatibility guarantee, stated once ────────────────────────────────────────────
|
|
1101
|
-
* Portable Text did NOT change this envelope. `format`, `value` and `html` are the same three
|
|
1102
|
-
* keys they always were, so `isRichText`, `plain()` and `rich()` keep working untouched — and
|
|
1103
|
-
* they have to, because sites compiled months ago read `.html` directly and cannot be
|
|
1104
|
-
* rebuilt. `bettercms-starter-modern/lib/cms.ts` even carries its OWN copy of `rich()`, baked
|
|
1105
|
-
* into deployments nobody can reach. Storing a bare array instead would have made
|
|
1106
|
-
* `isRichText` return false (it rejects arrays), every shipped `rich()` call return "", and
|
|
1107
|
-
* every one of those pages go blank at 200 OK.
|
|
1108
|
-
*
|
|
1109
|
-
* `portableText()` is therefore ADDITIVE: `html` remains the always-present field, and this is
|
|
1110
|
-
* the opt-in for consumers that want to render structure with `@portabletext/react` instead.
|
|
1111
|
-
*/
|
|
1112
|
-
declare function portableText(value: TextOrRich): readonly unknown[] | null;
|
|
1113
|
-
/**
|
|
1114
|
-
* The value's resolved embeds, for a renderer of its structure (`<PortableText embeds>`), or null:
|
|
1115
|
-
* a bare string, a value with no embed, or an envelope written before embeds existed. Additive,
|
|
1116
|
-
* like `portableText()`: `rich()` reads `html`, which already holds the cards.
|
|
1117
|
-
*/
|
|
1118
|
-
declare function embeds(value: TextOrRich): RichTextEmbeds | null;
|
|
1119
|
-
/** A delivered entry as far as `resolved()` reads it: its entry-level map. */
|
|
1120
|
-
interface ResolvedHolder {
|
|
1121
|
-
readonly resolved?: RichTextResolved | null;
|
|
1122
|
-
readonly data?: unknown;
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* What a rich-text value's related posts and author bios resolved to, for a renderer of its
|
|
1126
|
-
* structure (`<PortableText resolved>`), or null when there is nothing.
|
|
1127
|
-
*
|
|
1128
|
-
* resolved(entry.data.body, entry) // a field value, with the entry it came in
|
|
1129
|
-
* resolved(entry) // the entry's merged map
|
|
1130
|
-
*
|
|
1131
|
-
* An envelope value carries its own (`value.resolved`), which wins. A Body stored as a bare block
|
|
1132
|
-
* array has nowhere to carry one, so delivery puts the entry's merged map beside `data`
|
|
1133
|
-
* (`entry.resolved`): pass the entry and that is what you get. Additive, like `embeds()`: `rich()`
|
|
1134
|
-
* reads `html`, which already draws them.
|
|
1135
|
-
*/
|
|
1136
|
-
declare function resolved(value: TextOrRich | readonly unknown[] | ResolvedHolder, entry?: ResolvedHolder | null): RichTextResolved | null;
|
|
1137
|
-
/**
|
|
1138
|
-
* A field that may arrive as either shape. Type author-editable text fields with this and the
|
|
1139
|
-
* compiler routes you through `plain()`/`rich()`, so a type switch in the CMS can never reach
|
|
1140
|
-
* production as `[object Object]`.
|
|
1141
|
-
*/
|
|
1142
|
-
type TextOrRich = string | RichTextValue | null | undefined;
|
|
1143
|
-
/** True when the value is a rich-text envelope rather than a bare string. */
|
|
1144
|
-
declare function isRichText(value: unknown): value is RichTextValue;
|
|
1145
|
-
/**
|
|
1146
|
-
* Plain text for an attribute context — `<title>`, meta description, JSON-LD, `alt`.
|
|
1147
|
-
* Strips tags and decodes the entities that survive stripping, so the result is text the
|
|
1148
|
-
* consumer can escape once without double-escaping.
|
|
1149
|
-
*/
|
|
1150
|
-
declare function plain(value: TextOrRich): string;
|
|
1151
|
-
/**
|
|
1152
|
-
* Renderable HTML. Rich text keeps its inline marks (the server sanitizes `html` on write);
|
|
1153
|
-
* a bare string is escaped, so a plain field can never inject markup.
|
|
1154
|
-
*
|
|
1155
|
-
* A lone wrapping block is unwrapped: a field switched from `text` stores its value as
|
|
1156
|
-
* `<p>…</p>`, but it renders inside the element that already is the block — and
|
|
1157
|
-
* `<h1><p>…</p></h1>` is invalid, the parser closes the heading at the `<p>` and the text
|
|
1158
|
-
* falls out of it. Values with real block structure (several paragraphs, a list) are left
|
|
1159
|
-
* alone, so a body field still renders as a document.
|
|
1160
|
-
*/
|
|
1161
|
-
declare function rich(value: TextOrRich, fallback?: string): string;
|
|
1162
|
-
/**
|
|
1163
|
-
* Renderable HTML for a ONE-LINE place: a heading, a button, a caption. `rich()`, except that several
|
|
1164
|
-
* paragraphs are that place's LINES, joined with `<br>` (a heading-styled first block counts as one).
|
|
1165
|
-
*
|
|
1166
|
-
* An author who presses Enter in a heading's editor stores a second paragraph. `rich()` leaves it a
|
|
1167
|
-
* paragraph, and `<h1><p>…</p><p>…</p></h1>` is what the build then draws, while a publish between
|
|
1168
|
-
* builds writes the same value into the built heading as lines. This draws what the publish draws.
|
|
1169
|
-
* A value holding anything else (a list, an image, a table) is returned as `rich()` returns it.
|
|
1170
|
-
*/
|
|
1171
|
-
declare function lines(value: TextOrRich, fallback?: string): string;
|
|
1172
|
-
|
|
1173
986
|
/**
|
|
1174
987
|
* The published content snapshot, read where the site RUNS — not bundled into it.
|
|
1175
988
|
*
|
|
@@ -1508,29 +1321,4 @@ interface WebhookListResponse {
|
|
|
1508
1321
|
};
|
|
1509
1322
|
}
|
|
1510
1323
|
|
|
1511
|
-
|
|
1512
|
-
* `inEditor()`: is this page running inside the BetterCMS Visual Editor's canvas?
|
|
1513
|
-
*
|
|
1514
|
-
* The editor frames the site and names the frame, so the answer is the page's own `window.name`:
|
|
1515
|
-
* there from the first script, kept through every navigation inside the frame, and never set on
|
|
1516
|
-
* a published page a visitor opens. A site asks before it starts what the canvas cannot share:
|
|
1517
|
-
*
|
|
1518
|
-
* const smooth = inEditor() ? null : new LocomotiveScroll({ el, smooth: true });
|
|
1519
|
-
*
|
|
1520
|
-
* The canvas owns the scroll, the pointer and the place on the page; the site's motion (scroll
|
|
1521
|
-
* triggers, timelines, WebGL scenes) runs there as it does live. What has to stand down is only
|
|
1522
|
-
* what takes those three away: scroll that is not the window's own, an intro that holds the
|
|
1523
|
-
* page, a cursor drawn over it.
|
|
1524
|
-
*/
|
|
1525
|
-
/** The canvas frame's name. The dashboard sets this exact word (`EDITOR_FRAME_NAME`). */
|
|
1526
|
-
declare const EDITOR_FRAME_NAME = "bcms-editor";
|
|
1527
|
-
/** The least of `window` this needs. */
|
|
1528
|
-
interface FramedWindow {
|
|
1529
|
-
name: string;
|
|
1530
|
-
self: unknown;
|
|
1531
|
-
top: unknown;
|
|
1532
|
-
}
|
|
1533
|
-
/** True inside the editor's canvas. Safe where there is no window (a server render): false. */
|
|
1534
|
-
declare function inEditor(win?: FramedWindow | undefined): boolean;
|
|
1535
|
-
|
|
1536
|
-
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, CONTENT_APPLIED, type CommandManagedLayoutInput, type ContentAppliedMessage, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, EDITOR_FRAME_NAME, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, PORTABLE_TEXT_FORMAT, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput, type PublishedContent, type ResolvedHolder, type RichTextValue, STEGA_OPEN, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaNode, type StegaPayload, type SubmissionListOptions, type TextOrRich, type UpdateApiKeyInput, type UpdateAssetInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWebhookInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type Webhook, type WebhookAdvancedConfig, type WebhookEvent, type WebhookListResponse, type WebhookWithSecret, type WriteContentInput, addModelFields, addPageFields, commandManagedLayout, contentApplied, createApiKey, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, embeds, encodeStega, getApiKeyUsage, getEntry, getForm, getManagedLayout, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inEditor, inviteMember, isRichText, lines, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, onContentApplied, plain, portableText, publishManagedLayout, publishPage, publishedContentFile, publishedEntry, readPublishedContent, regenerateApiKey, removeMember, resetPublishedContentCache, resolveStega, resolved, revokeApiKey, rich, setPageContent, signIn, signInWithGithub, signInWithGoogle, signUp, stegaClean, stripStega, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updatePageModel, updateWorkspace, uploadMedia };
|
|
1324
|
+
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, type CommandManagedLayoutInput, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput, type PublishedContent, STEGA_OPEN, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaNode, type StegaPayload, type SubmissionListOptions, type UpdateApiKeyInput, type UpdateAssetInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWebhookInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type Webhook, type WebhookAdvancedConfig, type WebhookEvent, type WebhookListResponse, type WebhookWithSecret, type WriteContentInput, addModelFields, addPageFields, commandManagedLayout, createApiKey, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, getApiKeyUsage, getEntry, getForm, getManagedLayout, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, publishManagedLayout, publishPage, publishedContentFile, publishedEntry, readPublishedContent, regenerateApiKey, removeMember, resetPublishedContentCache, resolveStega, revokeApiKey, setPageContent, signIn, signInWithGithub, signInWithGoogle, signUp, stegaClean, stripStega, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updatePageModel, updateWorkspace, uploadMedia };
|
package/dist/live.cjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/live.ts
|
|
21
|
+
var live_exports = {};
|
|
22
|
+
__export(live_exports, {
|
|
23
|
+
CONTENT_APPLIED: () => CONTENT_APPLIED,
|
|
24
|
+
EDITOR_FRAME_NAME: () => EDITOR_FRAME_NAME,
|
|
25
|
+
GENERATOR_META: () => GENERATOR_META,
|
|
26
|
+
inEditor: () => inEditor,
|
|
27
|
+
liveSrc: () => liveSrc,
|
|
28
|
+
loadVisualEditing: () => loadVisualEditing,
|
|
29
|
+
markDraft: () => markDraft,
|
|
30
|
+
onCanvasRefresh: () => onCanvasRefresh,
|
|
31
|
+
onContentApplied: () => onContentApplied,
|
|
32
|
+
startBcmsLive: () => startBcmsLive,
|
|
33
|
+
subscribeLive: () => subscribeLive,
|
|
34
|
+
withGenerator: () => withGenerator
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(live_exports);
|
|
37
|
+
|
|
38
|
+
// src/in-editor.ts
|
|
39
|
+
var EDITOR_FRAME_NAME = "bcms-editor";
|
|
40
|
+
function inEditor(win = globalThis.window) {
|
|
41
|
+
try {
|
|
42
|
+
return !!win && win.name === EDITOR_FRAME_NAME && win.self !== win.top;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/content-applied.ts
|
|
49
|
+
var CONTENT_APPLIED = "bcms:content-applied";
|
|
50
|
+
function onContentApplied(handler, target = globalThis.window) {
|
|
51
|
+
if (!target) return () => {
|
|
52
|
+
};
|
|
53
|
+
const listener = (event) => {
|
|
54
|
+
const data = event.data;
|
|
55
|
+
if (!data || typeof data !== "object" || data.type !== CONTENT_APPLIED) return;
|
|
56
|
+
handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f) => typeof f === "string") : [] });
|
|
57
|
+
};
|
|
58
|
+
target.addEventListener("message", listener);
|
|
59
|
+
return () => target.removeEventListener("message", listener);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/live.ts
|
|
63
|
+
var pools = /* @__PURE__ */ new Map();
|
|
64
|
+
function subscribeLive(src, fn) {
|
|
65
|
+
let pool = pools.get(src);
|
|
66
|
+
if (!pool) {
|
|
67
|
+
const es = new EventSource(src);
|
|
68
|
+
pool = { es, listeners: /* @__PURE__ */ new Set() };
|
|
69
|
+
es.addEventListener("change", (e) => {
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(e.data);
|
|
73
|
+
} catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
for (const l of pools.get(src)?.listeners ?? []) l(parsed);
|
|
77
|
+
});
|
|
78
|
+
pools.set(src, pool);
|
|
79
|
+
}
|
|
80
|
+
pool.listeners.add(fn);
|
|
81
|
+
return () => {
|
|
82
|
+
const p = pools.get(src);
|
|
83
|
+
if (!p) return;
|
|
84
|
+
p.listeners.delete(fn);
|
|
85
|
+
if (p.listeners.size === 0) {
|
|
86
|
+
p.es.close();
|
|
87
|
+
pools.delete(src);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function onCanvasRefresh(refresh) {
|
|
92
|
+
if (typeof window === "undefined" || window.parent === window) return () => {
|
|
93
|
+
};
|
|
94
|
+
const onMessage = (e) => {
|
|
95
|
+
if (e.origin !== window.location.origin || e.source !== window.parent) return;
|
|
96
|
+
if (e.data?.type !== "bcms:refresh") return;
|
|
97
|
+
window.parent.postMessage({ type: "bcms:refreshed" }, e.origin);
|
|
98
|
+
void refresh();
|
|
99
|
+
};
|
|
100
|
+
window.addEventListener("message", onMessage);
|
|
101
|
+
return () => window.removeEventListener("message", onMessage);
|
|
102
|
+
}
|
|
103
|
+
function loadVisualEditing(studioUrl = "https://bettercms.ai") {
|
|
104
|
+
if (typeof document === "undefined") return;
|
|
105
|
+
const src = `${studioUrl.replace(/\/+$/, "")}/bcms-visual-editing.js`;
|
|
106
|
+
if (document.querySelector(`script[src="${src}"]`)) return;
|
|
107
|
+
const el = document.createElement("script");
|
|
108
|
+
el.src = src;
|
|
109
|
+
el.defer = true;
|
|
110
|
+
el.dataset.bcmsStudio = studioUrl;
|
|
111
|
+
document.head.appendChild(el);
|
|
112
|
+
}
|
|
113
|
+
function startBcmsLive(opts) {
|
|
114
|
+
if (typeof window === "undefined") return () => {
|
|
115
|
+
};
|
|
116
|
+
if (opts.draft ?? document.documentElement.hasAttribute("data-bcms-draft")) loadVisualEditing(opts.studioUrl);
|
|
117
|
+
const stopRefresh = onCanvasRefresh(opts.refresh);
|
|
118
|
+
const stopLive = opts.src ? subscribeLive(opts.src, (event) => {
|
|
119
|
+
if (opts.tags?.length && !event.tags.some((t) => opts.tags.includes(t))) return;
|
|
120
|
+
opts.onChange?.(event);
|
|
121
|
+
void opts.refresh();
|
|
122
|
+
}) : () => {
|
|
123
|
+
};
|
|
124
|
+
return () => {
|
|
125
|
+
stopRefresh();
|
|
126
|
+
stopLive();
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
var GENERATOR_META = '<meta name="generator" content="BetterCMS">';
|
|
130
|
+
function withGenerator(html) {
|
|
131
|
+
const at = html.search(/<\/head>/i);
|
|
132
|
+
return at < 0 || html.includes(GENERATOR_META) ? html : html.slice(0, at) + GENERATOR_META + html.slice(at);
|
|
133
|
+
}
|
|
134
|
+
function markDraft(html) {
|
|
135
|
+
return html.includes("data-bcms-draft=") ? html : html.replace(/<html(?=[\s>])/i, '<html data-bcms-draft="1"');
|
|
136
|
+
}
|
|
137
|
+
function liveSrc(opts) {
|
|
138
|
+
const q = new URLSearchParams({ key: opts.apiKey });
|
|
139
|
+
if (opts.depth !== void 0) q.set("depth", String(opts.depth));
|
|
140
|
+
if (opts.drafts) q.set("drafts", "1");
|
|
141
|
+
return `${opts.apiUrl.replace(/\/+$/, "")}/api/v1/delivery/${opts.workspace}/live?${q}`;
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
CONTENT_APPLIED,
|
|
146
|
+
EDITOR_FRAME_NAME,
|
|
147
|
+
GENERATOR_META,
|
|
148
|
+
inEditor,
|
|
149
|
+
liveSrc,
|
|
150
|
+
loadVisualEditing,
|
|
151
|
+
markDraft,
|
|
152
|
+
onCanvasRefresh,
|
|
153
|
+
onContentApplied,
|
|
154
|
+
startBcmsLive,
|
|
155
|
+
subscribeLive,
|
|
156
|
+
withGenerator
|
|
157
|
+
});
|
|
158
|
+
//# sourceMappingURL=live.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/live.ts","../src/in-editor.ts","../src/content-applied.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * The site half of BetterCMS live editing, framework-agnostic. Every adapter wires its own\n * re-render into it (Next `router.refresh`, SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`,\n * a React app's refetch), so the protocol lives here once:\n *\n * const stop = startBcmsLive({ src: liveSrc, refresh: () => invalidateAll() });\n *\n * - The delivery SSE stream (`src`): a publish elsewhere re-renders this page.\n * - The canvas soft refresh: the editor asks for a re-render after a STRUCTURAL draft write and\n * waits for the ack, so it does not remount the frame (which ends an inline text session).\n * - In draft mode, the click-to-edit overlay script from the studio origin.\n */\n\n/** A `change` frame off the live stream (the backend's routes/delivery/live.ts). */\nexport interface BcmsChangeEvent<T = unknown> {\n type: \"entry\" | \"page\";\n slug: string;\n reason: \"publish\" | \"unpublish\" | \"draft\";\n /** Cache tags, `bcms:{ws}:all` + `bcms:{ws}:{type}:{slug}`. */\n tags: string[];\n projectId: string | null;\n /** When the change was committed. */\n at: string;\n /** When the server flushed this frame — `at`→`sentAt` is its own cost. */\n sentAt?: string;\n /**\n * The finished delivery payload. Absent on `unpublish`, and when the server could not hydrate\n * it (over quota, deleted, larger than the frame cap): then the client refetches.\n */\n doc?: T;\n}\n\n// One EventSource per URL, refcounted, because HTTP/1.1 browsers cap ~6 sockets per host: a page\n// with a handful of live components would otherwise spend its whole connection budget on this\n// stream and stall its own image loads.\ntype Listener = (e: BcmsChangeEvent) => void;\nconst pools = new Map<string, { es: EventSource; listeners: Set<Listener> }>();\n\n/** Listen to the live stream at `src`. Returns the function that stops listening. */\nexport function subscribeLive(src: string, fn: Listener): () => void {\n let pool = pools.get(src);\n if (!pool) {\n const es = new EventSource(src);\n pool = { es, listeners: new Set() };\n es.addEventListener(\"change\", (e) => {\n let parsed: BcmsChangeEvent;\n try {\n parsed = JSON.parse((e as MessageEvent).data) as BcmsChangeEvent;\n } catch {\n return; // malformed frame — ignore, the next one will do\n }\n for (const l of pools.get(src)?.listeners ?? []) l(parsed);\n });\n pools.set(src, pool);\n }\n pool.listeners.add(fn);\n return () => {\n const p = pools.get(src);\n if (!p) return;\n p.listeners.delete(fn);\n if (p.listeners.size === 0) {\n p.es.close();\n pools.delete(src);\n }\n };\n}\n\n/**\n * Answer the canvas's soft-refresh request with `refresh`. The editor — not the page — decides\n * which of its writes are structural; the page must never re-render on draft events itself, which\n * fire on every autosave, including the inline edit the author is in the middle of.\n *\n * Accepted only from the page's own origin AND from the parent frame (the editor serves the site\n * through a same-origin proxy), so a third-party page framing the live site can trigger nothing.\n * The ack goes out BEFORE the refresh: after a reload this frame is gone.\n */\nexport function onCanvasRefresh(refresh: () => unknown): () => void {\n if (typeof window === \"undefined\" || window.parent === window) return () => {};\n const onMessage = (e: MessageEvent) => {\n if (e.origin !== window.location.origin || e.source !== window.parent) return;\n if ((e.data as { type?: unknown } | null)?.type !== \"bcms:refresh\") return;\n window.parent.postMessage({ type: \"bcms:refreshed\" }, e.origin);\n void refresh();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n}\n\n/**\n * Load the click-to-edit overlay (`/bcms-visual-editing.js` on the studio origin). Served, never\n * bundled: a customer build is un-upgradable, so a copy baked into one could never be fixed. The\n * tag is its own guard; it is never removed, because removing it would not detach its listeners.\n */\nexport function loadVisualEditing(studioUrl = \"https://bettercms.ai\"): void {\n if (typeof document === \"undefined\") return;\n const src = `${studioUrl.replace(/\\/+$/, \"\")}/bcms-visual-editing.js`;\n if (document.querySelector(`script[src=\"${src}\"]`)) return;\n const el = document.createElement(\"script\");\n el.src = src;\n el.defer = true;\n el.dataset.bcmsStudio = studioUrl;\n document.head.appendChild(el);\n}\n\nexport interface StartBcmsLiveOptions {\n /** The page's own re-render: SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`, a refetch. */\n refresh: () => unknown;\n /** The live SSE URL (a content:read key rides in it: EventSource cannot send headers). */\n src?: string;\n /** Only react to changes carrying one of these tags. Omit to react to all. */\n tags?: string[];\n /** Every matching change, with the pushed `doc` when there is one. */\n onChange?: (event: BcmsChangeEvent) => void;\n /** Where the click-to-edit overlay loads from in drafts. Default `https://bettercms.ai`. */\n studioUrl?: string;\n /** Drafts on? Default: the page's `<html data-bcms-draft>` marker, which the server stamps. */\n draft?: boolean;\n}\n\n/** Live stream + canvas soft refresh + (in drafts) the overlay. Returns the function that stops it. */\nexport function startBcmsLive(opts: StartBcmsLiveOptions): () => void {\n if (typeof window === \"undefined\") return () => {};\n if (opts.draft ?? document.documentElement.hasAttribute(\"data-bcms-draft\")) loadVisualEditing(opts.studioUrl);\n const stopRefresh = onCanvasRefresh(opts.refresh);\n const stopLive = opts.src\n ? subscribeLive(opts.src, (event) => {\n if (opts.tags?.length && !event.tags.some((t) => opts.tags!.includes(t))) return;\n opts.onChange?.(event);\n void opts.refresh();\n })\n : () => {};\n return () => {\n stopRefresh();\n stopLive();\n };\n}\n\n/** The standard tag Wappalyzer and BuiltWith read to name the CMS. */\nexport const GENERATOR_META = '<meta name=\"generator\" content=\"BetterCMS\">';\n\n/** The tag before the first `</head>`; unchanged without one, or when the page already has it. */\nexport function withGenerator(html: string): string {\n const at = html.search(/<\\/head>/i);\n return at < 0 || html.includes(GENERATOR_META) ? html : html.slice(0, at) + GENERATOR_META + html.slice(at);\n}\n\n/**\n * `<html data-bcms-draft=\"1\">`: the only thing the canvas trusts as proof that the frame really is\n * this site rendering a draft, not the published page it falls back to. Server renders stamp it.\n */\nexport function markDraft(html: string): string {\n return html.includes(\"data-bcms-draft=\") ? html : html.replace(/<html(?=[\\s>])/i, '<html data-bcms-draft=\"1\"');\n}\n\n// The other two halves of living inside the editor's canvas, browser-safe here too.\nexport { inEditor, EDITOR_FRAME_NAME } from \"./in-editor.js\";\nexport { onContentApplied, CONTENT_APPLIED, type ContentAppliedMessage } from \"./content-applied.js\";\n\nexport interface LiveSrcOptions {\n /** Backend base, e.g. `https://api.bettercms.ai`. */\n apiUrl: string;\n workspace: string;\n /** A content:read key — exposed to the browser in the URL (EventSource cannot send headers). */\n apiKey: string;\n /** Reference hydration depth of the pushed document; default 1, like the delivery API. */\n depth?: 0 | 1 | 2;\n /**\n * Stream draft autosaves too. Needs a `content:read:draft` key (the server ignores the flag for\n * any other key). Never on a public site: that key reads unpublished content.\n */\n drafts?: boolean;\n}\n\n/** The live SSE URL for `startBcmsLive({ src })`. */\nexport function liveSrc(opts: LiveSrcOptions): string {\n const q = new URLSearchParams({ key: opts.apiKey });\n if (opts.depth !== undefined) q.set(\"depth\", String(opts.depth));\n if (opts.drafts) q.set(\"drafts\", \"1\");\n return `${opts.apiUrl.replace(/\\/+$/, \"\")}/api/v1/delivery/${opts.workspace}/live?${q}`;\n}\n","/**\n * `inEditor()`: is this page running inside the BetterCMS Visual Editor's canvas?\n *\n * The editor frames the site and names the frame, so the answer is the page's own `window.name`:\n * there from the first script, kept through every navigation inside the frame, and never set on\n * a published page a visitor opens. A site asks before it starts what the canvas cannot share:\n *\n * const smooth = inEditor() ? null : new LocomotiveScroll({ el, smooth: true });\n *\n * The canvas owns the scroll, the pointer and the place on the page; the site's motion (scroll\n * triggers, timelines, WebGL scenes) runs there as it does live. What has to stand down is only\n * what takes those three away: scroll that is not the window's own, an intro that holds the\n * page, a cursor drawn over it.\n */\n\n/** The canvas frame's name. The dashboard sets this exact word (`EDITOR_FRAME_NAME`). */\nexport const EDITOR_FRAME_NAME = \"bcms-editor\";\n\n/** The least of `window` this needs. */\ninterface FramedWindow {\n name: string;\n self: unknown;\n top: unknown;\n}\n\n/** True inside the editor's canvas. Safe where there is no window (a server render): false. */\nexport function inEditor(win: FramedWindow | undefined = (globalThis as { window?: FramedWindow }).window): boolean {\n try {\n return !!win && win.name === EDITOR_FRAME_NAME && win.self !== win.top;\n } catch {\n return false;\n }\n}\n","/**\n * `bcms:content-applied` — what the visual editor tells a page after it has applied an edit to\n * the page's DOM.\n *\n * An edit changes how tall a heading is. Everything on the page that measured the layout once\n * (ScrollTrigger's start and end positions, Lenis's scroll limit, a carousel's slide widths, a\n * text splitter's lines) is now wrong, and only the page's own code can measure again. So the\n * editor posts one message to the frame's window after each applied edit, and the site listens:\n *\n * onContentApplied(() => ScrollTrigger.refresh());\n *\n * A published page receives no such message: nothing there posts it, and the listener is inert.\n */\n\n/** The `type` of the message. */\nexport const CONTENT_APPLIED = \"bcms:content-applied\";\n\nexport interface ContentAppliedMessage {\n type: typeof CONTENT_APPLIED;\n /** The field addresses whose rendering changed; empty when the editor does not say. */\n fields: string[];\n}\n\n/** The message the editor posts: `frame.contentWindow.postMessage(contentApplied(fields), origin)`. */\nexport const contentApplied = (fields: readonly string[] = []): ContentAppliedMessage => ({ type: CONTENT_APPLIED, fields: [...fields] });\n\n/** The least of `window` this needs. */\ninterface MessageTarget {\n addEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n removeEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n}\n\n/**\n * Run `handler` after every edit the editor applies to this page. Returns the function that\n * stops listening. Safe to call where there is no window (a server render): it does nothing.\n */\nexport function onContentApplied(\n handler: (message: ContentAppliedMessage) => void,\n target: MessageTarget | undefined = (globalThis as { window?: MessageTarget }).window,\n): () => void {\n if (!target) return () => {};\n const listener = (event: { data: unknown }) => {\n const data = event.data as Partial<ContentAppliedMessage> | null;\n if (!data || typeof data !== \"object\" || data.type !== CONTENT_APPLIED) return;\n handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f): f is string => typeof f === \"string\") : [] });\n };\n target.addEventListener(\"message\", listener);\n return () => target.removeEventListener(\"message\", listener);\n}\n"],"mappings":"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","names":[]}
|
package/dist/live.d.cts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export { C as CONTENT_APPLIED, a as ContentAppliedMessage, E as EDITOR_FRAME_NAME, i as inEditor, o as onContentApplied } from './in-editor-D1vXPgJh.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The site half of BetterCMS live editing, framework-agnostic. Every adapter wires its own
|
|
5
|
+
* re-render into it (Next `router.refresh`, SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`,
|
|
6
|
+
* a React app's refetch), so the protocol lives here once:
|
|
7
|
+
*
|
|
8
|
+
* const stop = startBcmsLive({ src: liveSrc, refresh: () => invalidateAll() });
|
|
9
|
+
*
|
|
10
|
+
* - The delivery SSE stream (`src`): a publish elsewhere re-renders this page.
|
|
11
|
+
* - The canvas soft refresh: the editor asks for a re-render after a STRUCTURAL draft write and
|
|
12
|
+
* waits for the ack, so it does not remount the frame (which ends an inline text session).
|
|
13
|
+
* - In draft mode, the click-to-edit overlay script from the studio origin.
|
|
14
|
+
*/
|
|
15
|
+
/** A `change` frame off the live stream (the backend's routes/delivery/live.ts). */
|
|
16
|
+
interface BcmsChangeEvent<T = unknown> {
|
|
17
|
+
type: "entry" | "page";
|
|
18
|
+
slug: string;
|
|
19
|
+
reason: "publish" | "unpublish" | "draft";
|
|
20
|
+
/** Cache tags, `bcms:{ws}:all` + `bcms:{ws}:{type}:{slug}`. */
|
|
21
|
+
tags: string[];
|
|
22
|
+
projectId: string | null;
|
|
23
|
+
/** When the change was committed. */
|
|
24
|
+
at: string;
|
|
25
|
+
/** When the server flushed this frame — `at`→`sentAt` is its own cost. */
|
|
26
|
+
sentAt?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The finished delivery payload. Absent on `unpublish`, and when the server could not hydrate
|
|
29
|
+
* it (over quota, deleted, larger than the frame cap): then the client refetches.
|
|
30
|
+
*/
|
|
31
|
+
doc?: T;
|
|
32
|
+
}
|
|
33
|
+
type Listener = (e: BcmsChangeEvent) => void;
|
|
34
|
+
/** Listen to the live stream at `src`. Returns the function that stops listening. */
|
|
35
|
+
declare function subscribeLive(src: string, fn: Listener): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Answer the canvas's soft-refresh request with `refresh`. The editor — not the page — decides
|
|
38
|
+
* which of its writes are structural; the page must never re-render on draft events itself, which
|
|
39
|
+
* fire on every autosave, including the inline edit the author is in the middle of.
|
|
40
|
+
*
|
|
41
|
+
* Accepted only from the page's own origin AND from the parent frame (the editor serves the site
|
|
42
|
+
* through a same-origin proxy), so a third-party page framing the live site can trigger nothing.
|
|
43
|
+
* The ack goes out BEFORE the refresh: after a reload this frame is gone.
|
|
44
|
+
*/
|
|
45
|
+
declare function onCanvasRefresh(refresh: () => unknown): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Load the click-to-edit overlay (`/bcms-visual-editing.js` on the studio origin). Served, never
|
|
48
|
+
* bundled: a customer build is un-upgradable, so a copy baked into one could never be fixed. The
|
|
49
|
+
* tag is its own guard; it is never removed, because removing it would not detach its listeners.
|
|
50
|
+
*/
|
|
51
|
+
declare function loadVisualEditing(studioUrl?: string): void;
|
|
52
|
+
interface StartBcmsLiveOptions {
|
|
53
|
+
/** The page's own re-render: SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`, a refetch. */
|
|
54
|
+
refresh: () => unknown;
|
|
55
|
+
/** The live SSE URL (a content:read key rides in it: EventSource cannot send headers). */
|
|
56
|
+
src?: string;
|
|
57
|
+
/** Only react to changes carrying one of these tags. Omit to react to all. */
|
|
58
|
+
tags?: string[];
|
|
59
|
+
/** Every matching change, with the pushed `doc` when there is one. */
|
|
60
|
+
onChange?: (event: BcmsChangeEvent) => void;
|
|
61
|
+
/** Where the click-to-edit overlay loads from in drafts. Default `https://bettercms.ai`. */
|
|
62
|
+
studioUrl?: string;
|
|
63
|
+
/** Drafts on? Default: the page's `<html data-bcms-draft>` marker, which the server stamps. */
|
|
64
|
+
draft?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Live stream + canvas soft refresh + (in drafts) the overlay. Returns the function that stops it. */
|
|
67
|
+
declare function startBcmsLive(opts: StartBcmsLiveOptions): () => void;
|
|
68
|
+
/** The standard tag Wappalyzer and BuiltWith read to name the CMS. */
|
|
69
|
+
declare const GENERATOR_META = "<meta name=\"generator\" content=\"BetterCMS\">";
|
|
70
|
+
/** The tag before the first `</head>`; unchanged without one, or when the page already has it. */
|
|
71
|
+
declare function withGenerator(html: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* `<html data-bcms-draft="1">`: the only thing the canvas trusts as proof that the frame really is
|
|
74
|
+
* this site rendering a draft, not the published page it falls back to. Server renders stamp it.
|
|
75
|
+
*/
|
|
76
|
+
declare function markDraft(html: string): string;
|
|
77
|
+
|
|
78
|
+
interface LiveSrcOptions {
|
|
79
|
+
/** Backend base, e.g. `https://api.bettercms.ai`. */
|
|
80
|
+
apiUrl: string;
|
|
81
|
+
workspace: string;
|
|
82
|
+
/** A content:read key — exposed to the browser in the URL (EventSource cannot send headers). */
|
|
83
|
+
apiKey: string;
|
|
84
|
+
/** Reference hydration depth of the pushed document; default 1, like the delivery API. */
|
|
85
|
+
depth?: 0 | 1 | 2;
|
|
86
|
+
/**
|
|
87
|
+
* Stream draft autosaves too. Needs a `content:read:draft` key (the server ignores the flag for
|
|
88
|
+
* any other key). Never on a public site: that key reads unpublished content.
|
|
89
|
+
*/
|
|
90
|
+
drafts?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** The live SSE URL for `startBcmsLive({ src })`. */
|
|
93
|
+
declare function liveSrc(opts: LiveSrcOptions): string;
|
|
94
|
+
|
|
95
|
+
export { type BcmsChangeEvent, GENERATOR_META, type LiveSrcOptions, type StartBcmsLiveOptions, liveSrc, loadVisualEditing, markDraft, onCanvasRefresh, startBcmsLive, subscribeLive, withGenerator };
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export { C as CONTENT_APPLIED, a as ContentAppliedMessage, E as EDITOR_FRAME_NAME, i as inEditor, o as onContentApplied } from './in-editor-D1vXPgJh.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The site half of BetterCMS live editing, framework-agnostic. Every adapter wires its own
|
|
5
|
+
* re-render into it (Next `router.refresh`, SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`,
|
|
6
|
+
* a React app's refetch), so the protocol lives here once:
|
|
7
|
+
*
|
|
8
|
+
* const stop = startBcmsLive({ src: liveSrc, refresh: () => invalidateAll() });
|
|
9
|
+
*
|
|
10
|
+
* - The delivery SSE stream (`src`): a publish elsewhere re-renders this page.
|
|
11
|
+
* - The canvas soft refresh: the editor asks for a re-render after a STRUCTURAL draft write and
|
|
12
|
+
* waits for the ack, so it does not remount the frame (which ends an inline text session).
|
|
13
|
+
* - In draft mode, the click-to-edit overlay script from the studio origin.
|
|
14
|
+
*/
|
|
15
|
+
/** A `change` frame off the live stream (the backend's routes/delivery/live.ts). */
|
|
16
|
+
interface BcmsChangeEvent<T = unknown> {
|
|
17
|
+
type: "entry" | "page";
|
|
18
|
+
slug: string;
|
|
19
|
+
reason: "publish" | "unpublish" | "draft";
|
|
20
|
+
/** Cache tags, `bcms:{ws}:all` + `bcms:{ws}:{type}:{slug}`. */
|
|
21
|
+
tags: string[];
|
|
22
|
+
projectId: string | null;
|
|
23
|
+
/** When the change was committed. */
|
|
24
|
+
at: string;
|
|
25
|
+
/** When the server flushed this frame — `at`→`sentAt` is its own cost. */
|
|
26
|
+
sentAt?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The finished delivery payload. Absent on `unpublish`, and when the server could not hydrate
|
|
29
|
+
* it (over quota, deleted, larger than the frame cap): then the client refetches.
|
|
30
|
+
*/
|
|
31
|
+
doc?: T;
|
|
32
|
+
}
|
|
33
|
+
type Listener = (e: BcmsChangeEvent) => void;
|
|
34
|
+
/** Listen to the live stream at `src`. Returns the function that stops listening. */
|
|
35
|
+
declare function subscribeLive(src: string, fn: Listener): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Answer the canvas's soft-refresh request with `refresh`. The editor — not the page — decides
|
|
38
|
+
* which of its writes are structural; the page must never re-render on draft events itself, which
|
|
39
|
+
* fire on every autosave, including the inline edit the author is in the middle of.
|
|
40
|
+
*
|
|
41
|
+
* Accepted only from the page's own origin AND from the parent frame (the editor serves the site
|
|
42
|
+
* through a same-origin proxy), so a third-party page framing the live site can trigger nothing.
|
|
43
|
+
* The ack goes out BEFORE the refresh: after a reload this frame is gone.
|
|
44
|
+
*/
|
|
45
|
+
declare function onCanvasRefresh(refresh: () => unknown): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Load the click-to-edit overlay (`/bcms-visual-editing.js` on the studio origin). Served, never
|
|
48
|
+
* bundled: a customer build is un-upgradable, so a copy baked into one could never be fixed. The
|
|
49
|
+
* tag is its own guard; it is never removed, because removing it would not detach its listeners.
|
|
50
|
+
*/
|
|
51
|
+
declare function loadVisualEditing(studioUrl?: string): void;
|
|
52
|
+
interface StartBcmsLiveOptions {
|
|
53
|
+
/** The page's own re-render: SvelteKit `invalidateAll`, Nuxt `refreshNuxtData`, a refetch. */
|
|
54
|
+
refresh: () => unknown;
|
|
55
|
+
/** The live SSE URL (a content:read key rides in it: EventSource cannot send headers). */
|
|
56
|
+
src?: string;
|
|
57
|
+
/** Only react to changes carrying one of these tags. Omit to react to all. */
|
|
58
|
+
tags?: string[];
|
|
59
|
+
/** Every matching change, with the pushed `doc` when there is one. */
|
|
60
|
+
onChange?: (event: BcmsChangeEvent) => void;
|
|
61
|
+
/** Where the click-to-edit overlay loads from in drafts. Default `https://bettercms.ai`. */
|
|
62
|
+
studioUrl?: string;
|
|
63
|
+
/** Drafts on? Default: the page's `<html data-bcms-draft>` marker, which the server stamps. */
|
|
64
|
+
draft?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Live stream + canvas soft refresh + (in drafts) the overlay. Returns the function that stops it. */
|
|
67
|
+
declare function startBcmsLive(opts: StartBcmsLiveOptions): () => void;
|
|
68
|
+
/** The standard tag Wappalyzer and BuiltWith read to name the CMS. */
|
|
69
|
+
declare const GENERATOR_META = "<meta name=\"generator\" content=\"BetterCMS\">";
|
|
70
|
+
/** The tag before the first `</head>`; unchanged without one, or when the page already has it. */
|
|
71
|
+
declare function withGenerator(html: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* `<html data-bcms-draft="1">`: the only thing the canvas trusts as proof that the frame really is
|
|
74
|
+
* this site rendering a draft, not the published page it falls back to. Server renders stamp it.
|
|
75
|
+
*/
|
|
76
|
+
declare function markDraft(html: string): string;
|
|
77
|
+
|
|
78
|
+
interface LiveSrcOptions {
|
|
79
|
+
/** Backend base, e.g. `https://api.bettercms.ai`. */
|
|
80
|
+
apiUrl: string;
|
|
81
|
+
workspace: string;
|
|
82
|
+
/** A content:read key — exposed to the browser in the URL (EventSource cannot send headers). */
|
|
83
|
+
apiKey: string;
|
|
84
|
+
/** Reference hydration depth of the pushed document; default 1, like the delivery API. */
|
|
85
|
+
depth?: 0 | 1 | 2;
|
|
86
|
+
/**
|
|
87
|
+
* Stream draft autosaves too. Needs a `content:read:draft` key (the server ignores the flag for
|
|
88
|
+
* any other key). Never on a public site: that key reads unpublished content.
|
|
89
|
+
*/
|
|
90
|
+
drafts?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** The live SSE URL for `startBcmsLive({ src })`. */
|
|
93
|
+
declare function liveSrc(opts: LiveSrcOptions): string;
|
|
94
|
+
|
|
95
|
+
export { type BcmsChangeEvent, GENERATOR_META, type LiveSrcOptions, type StartBcmsLiveOptions, liveSrc, loadVisualEditing, markDraft, onCanvasRefresh, startBcmsLive, subscribeLive, withGenerator };
|