payload-live-preview 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1787,12 +1787,24 @@ interface FieldBindingAttributes {
1787
1787
  readonly 'data-payload-field': string;
1788
1788
  readonly 'data-payload-attribute'?: string;
1789
1789
  readonly 'data-payload-type'?: string;
1790
+ readonly 'data-payload-richtext'?: string;
1791
+ readonly 'data-payload-html'?: string;
1792
+ readonly 'data-payload-locale'?: string;
1790
1793
  }
1791
1794
  interface BindOptions {
1792
1795
  /** Override the bound attribute (e.g., `'src'` for `<img>`). Default: textContent. */
1793
1796
  readonly attribute?: string;
1794
1797
  /** Explicit field-type override — bypasses schema detection. */
1795
1798
  readonly type?: string;
1799
+ /**
1800
+ * Mark the binding as Lexical rich text. Usually detected automatically;
1801
+ * set it where the initial render is empty and there is nothing to detect.
1802
+ */
1803
+ readonly richtext?: boolean;
1804
+ /** Render the value as sanitised HTML rather than text. */
1805
+ readonly html?: boolean;
1806
+ /** Lock this element to one locale, overriding the message locale. */
1807
+ readonly locale?: string;
1796
1808
  }
1797
1809
  /**
1798
1810
  * String-literal binding helper.
@@ -1827,4 +1839,90 @@ declare function bind<T = Record<string, unknown>>(field: FieldName<T>, options?
1827
1839
  */
1828
1840
  declare function bindByPath<T = Record<string, unknown>>(picker: (data: T) => unknown, options?: BindOptions): FieldBindingAttributes;
1829
1841
 
1830
- export { type AnalyticsSnapshot, type BindOptions, type BlockRenderContext, type BlockRenderer, type CachedElement, type CspDirectiveMerge, type DocumentSaveHandler, type DocumentSavePluginOptions, type DocumentSaveStrategy, EventEmitter, type EventHandler, type FetchPreviewDocumentOptions, type FetchPreviewGlobalOptions, type FieldBindingAttributes, type FieldName, type FieldPath, type FieldRenderer, type FieldTransform, type FieldType, type FrameAncestorsOptions, type InlineScriptConfig, LIBRARY_PROTOCOL_VERSION, type LexicalNode, type LexicalRoot, LivePreviewClient, type LivePreviewClientConfig, type LivePreviewEventMap, type LivePreviewPlugin, OriginDetector, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type PayloadLivePreviewMessage, type PayloadMedia, type PayloadRelationship, type PluginContext, type PluginDisposer, type PluginEvents, type PreviewFetchBaseOptions, type PreviewRequestLike, type PreviewRequestOptions, type PreviewWhere, type ProtocolCapability, type ProtocolNegotiation, type RenderContext, type SanitizerDocument, type Unsubscribe, VERSION, type ValueAt, bind, bindByPath, buildBuiltinRenderers, buildFrameAncestors, buildScriptSrcWithNonce, createAnalyticsPlugin, debugPlugin, detectInitialLocale, documentSavePlugin, escapeHtml, escapeHtmlAttribute, fetchPreviewDocument, fetchPreviewGlobal, generateCspNonce, generateInlineScript, hasCapability, highlightPlugin, initLivePreview, isDevMode, isExternalHttpUrl, isInIframe, isInPopup, isInPreviewContext, isLexicalContent, isPreviewRequest, isSafeUrl, lexicalToHtml, lexicalToPlainText, mergeCspHeader, negotiateProtocol, registerBlockRenderer, registerBuiltinRenderer, runtimeBuildInfo, sanitizeHtml, setCspCrypto, setSanitizerDocument, wrapWithScriptTag };
1842
+ /**
1843
+ * Authorization-gated binding emission.
1844
+ *
1845
+ * Binding attributes are not neutral markup. `data-payload-field` names a CMS
1846
+ * field, and `data-payload-owner` names a global, a collection and often a
1847
+ * document id. Emitted unconditionally they publish the shape of the content
1848
+ * model — and the identity of documents — to every anonymous visitor and
1849
+ * crawler of the page.
1850
+ *
1851
+ * The gate belongs to the application, not to this package: it is the same
1852
+ * decision that already controls draft reads and cache policy. What this
1853
+ * module provides is a place to apply that decision **once per request** so no
1854
+ * individual call site can forget it, and an emission unit that cannot be
1855
+ * partially suppressed.
1856
+ *
1857
+ * That second property matters more than it looks. A binding is not one
1858
+ * attribute: a field travels with its type, its locale, its rich-text marker
1859
+ * and its owner. Gating only the field name leaves the companions behind,
1860
+ * which discloses the taxonomy anyway and leaves the runtime looking at a
1861
+ * binding whose field is gone.
1862
+ *
1863
+ * @module @dsl/preview-bindings
1864
+ */
1865
+
1866
+ /** Owner marker naming the document a subtree belongs to. */
1867
+ interface OwnerBindingAttributes {
1868
+ readonly 'data-payload-owner': string;
1869
+ }
1870
+ /**
1871
+ * The complete absence of binding attributes.
1872
+ *
1873
+ * Spreading this into markup contributes nothing, which is the point: an
1874
+ * unauthorized response must be byte-identical to one that never knew about
1875
+ * live preview.
1876
+ */
1877
+ type SuppressedBinding = Readonly<Record<string, never>>;
1878
+ interface PreviewBindingsOptions {
1879
+ /**
1880
+ * The application's own authorization verdict for this request.
1881
+ *
1882
+ * Never derive this from `?preview=true`, an iframe destination or a
1883
+ * referer — those are client-controlled intent signals. Use the same
1884
+ * verified result that decides whether drafts may be read.
1885
+ */
1886
+ readonly authorized: boolean;
1887
+ /**
1888
+ * Document this subtree belongs to, emitted as `data-payload-owner` by
1889
+ * {@link PreviewBindings.owner}. Required only when the page previews more
1890
+ * than one document and the runtime runs with `scopeBindingsByOwner`.
1891
+ */
1892
+ readonly owner?: string;
1893
+ }
1894
+ /** Request-scoped binding helpers that carry one authorization decision. */
1895
+ interface PreviewBindings {
1896
+ /** The verdict these helpers were built with. */
1897
+ readonly authorized: boolean;
1898
+ /** Typed field binding, or nothing at all while unauthorized. */
1899
+ bind: <T = Record<string, unknown>>(field: FieldName<T>, options?: BindOptions) => FieldBindingAttributes | SuppressedBinding;
1900
+ /** Rename-safe field binding, or nothing at all while unauthorized. */
1901
+ bindByPath: <T = Record<string, unknown>>(picker: (data: T) => unknown, options?: BindOptions) => FieldBindingAttributes | SuppressedBinding;
1902
+ /**
1903
+ * Owner marker for the element that owns this subtree, or nothing at all
1904
+ * while unauthorized or when no owner was configured.
1905
+ */
1906
+ owner: () => OwnerBindingAttributes | SuppressedBinding;
1907
+ }
1908
+ /**
1909
+ * Build request-scoped binding helpers around one authorization decision.
1910
+ *
1911
+ * ```ts
1912
+ * const preview = createPreviewBindings({
1913
+ * authorized: authorization !== null,
1914
+ * owner: `global:${slug}`,
1915
+ * });
1916
+ * ```
1917
+ * ```astro
1918
+ * <section {...preview.owner()}>
1919
+ * <h1 {...preview.bind<Homepage>('heroTitle')}>{data.heroTitle}</h1>
1920
+ * </section>
1921
+ * ```
1922
+ *
1923
+ * While unauthorized every helper returns an empty attribute set, so the
1924
+ * public response carries no `data-payload-*` at all.
1925
+ */
1926
+ declare function createPreviewBindings(options: PreviewBindingsOptions): PreviewBindings;
1927
+
1928
+ export { type AnalyticsSnapshot, type BindOptions, type BlockRenderContext, type BlockRenderer, type CachedElement, type CspDirectiveMerge, type DocumentSaveHandler, type DocumentSavePluginOptions, type DocumentSaveStrategy, EventEmitter, type EventHandler, type FetchPreviewDocumentOptions, type FetchPreviewGlobalOptions, type FieldBindingAttributes, type FieldName, type FieldPath, type FieldRenderer, type FieldTransform, type FieldType, type FrameAncestorsOptions, type InlineScriptConfig, LIBRARY_PROTOCOL_VERSION, type LexicalNode, type LexicalRoot, LivePreviewClient, type LivePreviewClientConfig, type LivePreviewEventMap, type LivePreviewPlugin, OriginDetector, type OwnerBindingAttributes, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type PayloadLivePreviewMessage, type PayloadMedia, type PayloadRelationship, type PluginContext, type PluginDisposer, type PluginEvents, type PreviewBindings, type PreviewBindingsOptions, type PreviewFetchBaseOptions, type PreviewRequestLike, type PreviewRequestOptions, type PreviewWhere, type ProtocolCapability, type ProtocolNegotiation, type RenderContext, type SanitizerDocument, type SuppressedBinding, type Unsubscribe, VERSION, type ValueAt, bind, bindByPath, buildBuiltinRenderers, buildFrameAncestors, buildScriptSrcWithNonce, createAnalyticsPlugin, createPreviewBindings, debugPlugin, detectInitialLocale, documentSavePlugin, escapeHtml, escapeHtmlAttribute, fetchPreviewDocument, fetchPreviewGlobal, generateCspNonce, generateInlineScript, hasCapability, highlightPlugin, initLivePreview, isDevMode, isExternalHttpUrl, isInIframe, isInPopup, isInPreviewContext, isLexicalContent, isPreviewRequest, isSafeUrl, lexicalToHtml, lexicalToPlainText, mergeCspHeader, negotiateProtocol, registerBlockRenderer, registerBuiltinRenderer, runtimeBuildInfo, sanitizeHtml, setCspCrypto, setSanitizerDocument, wrapWithScriptTag };
package/dist/index.d.ts CHANGED
@@ -1787,12 +1787,24 @@ interface FieldBindingAttributes {
1787
1787
  readonly 'data-payload-field': string;
1788
1788
  readonly 'data-payload-attribute'?: string;
1789
1789
  readonly 'data-payload-type'?: string;
1790
+ readonly 'data-payload-richtext'?: string;
1791
+ readonly 'data-payload-html'?: string;
1792
+ readonly 'data-payload-locale'?: string;
1790
1793
  }
1791
1794
  interface BindOptions {
1792
1795
  /** Override the bound attribute (e.g., `'src'` for `<img>`). Default: textContent. */
1793
1796
  readonly attribute?: string;
1794
1797
  /** Explicit field-type override — bypasses schema detection. */
1795
1798
  readonly type?: string;
1799
+ /**
1800
+ * Mark the binding as Lexical rich text. Usually detected automatically;
1801
+ * set it where the initial render is empty and there is nothing to detect.
1802
+ */
1803
+ readonly richtext?: boolean;
1804
+ /** Render the value as sanitised HTML rather than text. */
1805
+ readonly html?: boolean;
1806
+ /** Lock this element to one locale, overriding the message locale. */
1807
+ readonly locale?: string;
1796
1808
  }
1797
1809
  /**
1798
1810
  * String-literal binding helper.
@@ -1827,4 +1839,90 @@ declare function bind<T = Record<string, unknown>>(field: FieldName<T>, options?
1827
1839
  */
1828
1840
  declare function bindByPath<T = Record<string, unknown>>(picker: (data: T) => unknown, options?: BindOptions): FieldBindingAttributes;
1829
1841
 
1830
- export { type AnalyticsSnapshot, type BindOptions, type BlockRenderContext, type BlockRenderer, type CachedElement, type CspDirectiveMerge, type DocumentSaveHandler, type DocumentSavePluginOptions, type DocumentSaveStrategy, EventEmitter, type EventHandler, type FetchPreviewDocumentOptions, type FetchPreviewGlobalOptions, type FieldBindingAttributes, type FieldName, type FieldPath, type FieldRenderer, type FieldTransform, type FieldType, type FrameAncestorsOptions, type InlineScriptConfig, LIBRARY_PROTOCOL_VERSION, type LexicalNode, type LexicalRoot, LivePreviewClient, type LivePreviewClientConfig, type LivePreviewEventMap, type LivePreviewPlugin, OriginDetector, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type PayloadLivePreviewMessage, type PayloadMedia, type PayloadRelationship, type PluginContext, type PluginDisposer, type PluginEvents, type PreviewFetchBaseOptions, type PreviewRequestLike, type PreviewRequestOptions, type PreviewWhere, type ProtocolCapability, type ProtocolNegotiation, type RenderContext, type SanitizerDocument, type Unsubscribe, VERSION, type ValueAt, bind, bindByPath, buildBuiltinRenderers, buildFrameAncestors, buildScriptSrcWithNonce, createAnalyticsPlugin, debugPlugin, detectInitialLocale, documentSavePlugin, escapeHtml, escapeHtmlAttribute, fetchPreviewDocument, fetchPreviewGlobal, generateCspNonce, generateInlineScript, hasCapability, highlightPlugin, initLivePreview, isDevMode, isExternalHttpUrl, isInIframe, isInPopup, isInPreviewContext, isLexicalContent, isPreviewRequest, isSafeUrl, lexicalToHtml, lexicalToPlainText, mergeCspHeader, negotiateProtocol, registerBlockRenderer, registerBuiltinRenderer, runtimeBuildInfo, sanitizeHtml, setCspCrypto, setSanitizerDocument, wrapWithScriptTag };
1842
+ /**
1843
+ * Authorization-gated binding emission.
1844
+ *
1845
+ * Binding attributes are not neutral markup. `data-payload-field` names a CMS
1846
+ * field, and `data-payload-owner` names a global, a collection and often a
1847
+ * document id. Emitted unconditionally they publish the shape of the content
1848
+ * model — and the identity of documents — to every anonymous visitor and
1849
+ * crawler of the page.
1850
+ *
1851
+ * The gate belongs to the application, not to this package: it is the same
1852
+ * decision that already controls draft reads and cache policy. What this
1853
+ * module provides is a place to apply that decision **once per request** so no
1854
+ * individual call site can forget it, and an emission unit that cannot be
1855
+ * partially suppressed.
1856
+ *
1857
+ * That second property matters more than it looks. A binding is not one
1858
+ * attribute: a field travels with its type, its locale, its rich-text marker
1859
+ * and its owner. Gating only the field name leaves the companions behind,
1860
+ * which discloses the taxonomy anyway and leaves the runtime looking at a
1861
+ * binding whose field is gone.
1862
+ *
1863
+ * @module @dsl/preview-bindings
1864
+ */
1865
+
1866
+ /** Owner marker naming the document a subtree belongs to. */
1867
+ interface OwnerBindingAttributes {
1868
+ readonly 'data-payload-owner': string;
1869
+ }
1870
+ /**
1871
+ * The complete absence of binding attributes.
1872
+ *
1873
+ * Spreading this into markup contributes nothing, which is the point: an
1874
+ * unauthorized response must be byte-identical to one that never knew about
1875
+ * live preview.
1876
+ */
1877
+ type SuppressedBinding = Readonly<Record<string, never>>;
1878
+ interface PreviewBindingsOptions {
1879
+ /**
1880
+ * The application's own authorization verdict for this request.
1881
+ *
1882
+ * Never derive this from `?preview=true`, an iframe destination or a
1883
+ * referer — those are client-controlled intent signals. Use the same
1884
+ * verified result that decides whether drafts may be read.
1885
+ */
1886
+ readonly authorized: boolean;
1887
+ /**
1888
+ * Document this subtree belongs to, emitted as `data-payload-owner` by
1889
+ * {@link PreviewBindings.owner}. Required only when the page previews more
1890
+ * than one document and the runtime runs with `scopeBindingsByOwner`.
1891
+ */
1892
+ readonly owner?: string;
1893
+ }
1894
+ /** Request-scoped binding helpers that carry one authorization decision. */
1895
+ interface PreviewBindings {
1896
+ /** The verdict these helpers were built with. */
1897
+ readonly authorized: boolean;
1898
+ /** Typed field binding, or nothing at all while unauthorized. */
1899
+ bind: <T = Record<string, unknown>>(field: FieldName<T>, options?: BindOptions) => FieldBindingAttributes | SuppressedBinding;
1900
+ /** Rename-safe field binding, or nothing at all while unauthorized. */
1901
+ bindByPath: <T = Record<string, unknown>>(picker: (data: T) => unknown, options?: BindOptions) => FieldBindingAttributes | SuppressedBinding;
1902
+ /**
1903
+ * Owner marker for the element that owns this subtree, or nothing at all
1904
+ * while unauthorized or when no owner was configured.
1905
+ */
1906
+ owner: () => OwnerBindingAttributes | SuppressedBinding;
1907
+ }
1908
+ /**
1909
+ * Build request-scoped binding helpers around one authorization decision.
1910
+ *
1911
+ * ```ts
1912
+ * const preview = createPreviewBindings({
1913
+ * authorized: authorization !== null,
1914
+ * owner: `global:${slug}`,
1915
+ * });
1916
+ * ```
1917
+ * ```astro
1918
+ * <section {...preview.owner()}>
1919
+ * <h1 {...preview.bind<Homepage>('heroTitle')}>{data.heroTitle}</h1>
1920
+ * </section>
1921
+ * ```
1922
+ *
1923
+ * While unauthorized every helper returns an empty attribute set, so the
1924
+ * public response carries no `data-payload-*` at all.
1925
+ */
1926
+ declare function createPreviewBindings(options: PreviewBindingsOptions): PreviewBindings;
1927
+
1928
+ export { type AnalyticsSnapshot, type BindOptions, type BlockRenderContext, type BlockRenderer, type CachedElement, type CspDirectiveMerge, type DocumentSaveHandler, type DocumentSavePluginOptions, type DocumentSaveStrategy, EventEmitter, type EventHandler, type FetchPreviewDocumentOptions, type FetchPreviewGlobalOptions, type FieldBindingAttributes, type FieldName, type FieldPath, type FieldRenderer, type FieldTransform, type FieldType, type FrameAncestorsOptions, type InlineScriptConfig, LIBRARY_PROTOCOL_VERSION, type LexicalNode, type LexicalRoot, LivePreviewClient, type LivePreviewClientConfig, type LivePreviewEventMap, type LivePreviewPlugin, OriginDetector, type OwnerBindingAttributes, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type PayloadLivePreviewMessage, type PayloadMedia, type PayloadRelationship, type PluginContext, type PluginDisposer, type PluginEvents, type PreviewBindings, type PreviewBindingsOptions, type PreviewFetchBaseOptions, type PreviewRequestLike, type PreviewRequestOptions, type PreviewWhere, type ProtocolCapability, type ProtocolNegotiation, type RenderContext, type SanitizerDocument, type SuppressedBinding, type Unsubscribe, VERSION, type ValueAt, bind, bindByPath, buildBuiltinRenderers, buildFrameAncestors, buildScriptSrcWithNonce, createAnalyticsPlugin, createPreviewBindings, debugPlugin, detectInitialLocale, documentSavePlugin, escapeHtml, escapeHtmlAttribute, fetchPreviewDocument, fetchPreviewGlobal, generateCspNonce, generateInlineScript, hasCapability, highlightPlugin, initLivePreview, isDevMode, isExternalHttpUrl, isInIframe, isInPopup, isInPreviewContext, isLexicalContent, isPreviewRequest, isSafeUrl, lexicalToHtml, lexicalToPlainText, mergeCspHeader, negotiateProtocol, registerBlockRenderer, registerBuiltinRenderer, runtimeBuildInfo, sanitizeHtml, setCspCrypto, setSanitizerDocument, wrapWithScriptTag };