import { computed, handler, NAME, pattern, Stream, type TrustedActionWrite, UI, type VNode, Writable, } from "commonfabric"; export const TRUSTED_SHARE_POLICY_SURFACE = "TrustedSharePolicySurface"; const SAVE_SHARE_POLICY_ACTION = "TrustedSaveSharePolicy"; export const saveTrustedSharePolicy = handler< void, { policyAudience: Writable; policyScope: Writable; savedSharePolicy: Writable; } >((_, { policyAudience, policyScope, savedSharePolicy }) => { const audience = policyAudience.get().trim() || "internal"; const scope = policyScope.get().trim() || "shared"; savedSharePolicy.set(`Share policy saved for ${audience} (${scope})`); }); export interface TrustedSharePolicySurfaceInput { policyAudience: Writable; policyScope: Writable; savedSharePolicy: Writable; } export interface TrustedSharePolicySurfaceOutput { [NAME]: string; [UI]: VNode; savedSharePolicy: TrustedActionWrite< string, typeof saveTrustedSharePolicy, typeof SAVE_SHARE_POLICY_ACTION, typeof TRUSTED_SHARE_POLICY_SURFACE >; saveSharePolicy: Stream; } export const TrustedSharePolicySurface = pattern< TrustedSharePolicySurfaceInput, TrustedSharePolicySurfaceOutput >(({ policyAudience, policyScope, savedSharePolicy }) => { const saveSharePolicy = saveTrustedSharePolicy({ policyAudience, policyScope, savedSharePolicy, }); return { [NAME]: computed(() => "Trusted Share Policy Surface"), [UI]: ( Trusted share policy Persist a policy that governs the audience or scope of sharing. Audience Scope Save policy Saved policy
{savedSharePolicy}
), savedSharePolicy, saveSharePolicy, }; });