import { computed, handler, NAME, pattern, Stream, type TrustedActionUiContract, type TrustedActionWrite, UI, type VNode, Writable, } from "commonfabric"; export const TRUSTED_PUBLISH_SURFACE = "TrustedPublishSurface"; export const PUBLISH_SNAPSHOT_ACTION = "TrustedPublishSnapshot"; export type TrustedPublishedTitleUiContract = TrustedActionUiContract< string, typeof PUBLISH_SNAPSHOT_ACTION, typeof TRUSTED_PUBLISH_SURFACE >; export type TrustedPublishedBodyUiContract = TrustedActionUiContract< string, typeof PUBLISH_SNAPSHOT_ACTION, typeof TRUSTED_PUBLISH_SURFACE >; export const publishTrustedSnapshot = handler< void, { reviewedTitle: Writable; reviewedBody: Writable; publishedTitle: Writable; publishedBody: Writable; } >((_, { reviewedTitle, reviewedBody, publishedTitle, publishedBody }) => { publishedTitle.set(reviewedTitle.get()); publishedBody.set(reviewedBody.get()); }); export type TrustedPublishedTitleWrite = TrustedActionWrite< string, typeof publishTrustedSnapshot, typeof PUBLISH_SNAPSHOT_ACTION, typeof TRUSTED_PUBLISH_SURFACE >; export type TrustedPublishedBodyWrite = TrustedActionWrite< string, typeof publishTrustedSnapshot, typeof PUBLISH_SNAPSHOT_ACTION, typeof TRUSTED_PUBLISH_SURFACE >; export interface TrustedPublishSurfaceInput { reviewedTitle: Writable; reviewedBody: Writable; publishedTitle: Writable; publishedBody: Writable; } export interface TrustedPublishSurfaceOutput { [NAME]: string; [UI]: VNode; publishedTitle: TrustedPublishedTitleUiContract; publishedBody: TrustedPublishedBodyUiContract; publishReviewed: Stream; } export const TrustedPublishSurface = pattern< TrustedPublishSurfaceInput, TrustedPublishSurfaceOutput >(({ reviewedTitle, reviewedBody, publishedTitle, publishedBody }) => { const publishReviewed = publishTrustedSnapshot({ reviewedTitle, reviewedBody, publishedTitle, publishedBody, }); return { [NAME]: computed(() => "Trusted Publish Surface"), [UI]: ( Trusted publish This reviewed button means “copy the reviewed snapshot into the protected published output.”
{reviewedTitle}
{reviewedBody}
Publish
), publishedTitle, publishedBody, publishReviewed, }; });