/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { IFluidMountableViewEntryPoint, MountableView, exampleOldestSupportedClient, getDataStoreEntryPoint, } from "@fluid-example/example-utils"; import { IContainerContext, IRuntime } from "@fluidframework/container-definitions/legacy"; import { loadContainerRuntime } from "@fluidframework/container-runtime/legacy"; import { IContainerRuntime } from "@fluidframework/container-runtime-definitions/legacy"; import { FluidObject } from "@fluidframework/core-interfaces"; import { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions/legacy"; import { RuntimeFactoryHelper } from "@fluidframework/runtime-utils/legacy"; import { createElement } from "react"; import { ProseMirror, ProseMirrorFactory, ProseMirrorReactView } from "./prosemirror.js"; export { ProseMirror, ProseMirrorFactory, ProseMirrorReactView } from "./prosemirror.js"; const defaultComponentId = "default"; const smde = new ProseMirrorFactory(); class ProseMirrorRuntimeFactory extends RuntimeFactoryHelper { public async instantiateFirstTime(runtime: IContainerRuntime): Promise { const dataStore = await runtime.createDataStore(smde.type); await dataStore.trySetAlias(defaultComponentId); } public async preInitialize( context: IContainerContext, existing: boolean, ): Promise { const registryEntries = new Map>([ [smde.type, Promise.resolve(smde)], ]); const runtime = await loadContainerRuntime({ context, registryEntries, existing, oldestSupportedClient: exampleOldestSupportedClient, containerScope: context.scope, provideEntryPoint: async ( containerRuntime: IContainerRuntime, ): Promise => { const proseMirror = await getDataStoreEntryPoint( containerRuntime, defaultComponentId, ); const view = new MountableView( createElement(ProseMirrorReactView, { collabManager: proseMirror.collabManager, }), ) as any; let getMountableDefaultView = async (): Promise => view; if (MountableView.canMount(view)) { getMountableDefaultView = async (): Promise => new MountableView(view); } return { getDefaultDataObject: async () => proseMirror as FluidObject, getMountableDefaultView, }; }, }); return runtime; } } /** * @internal */ export const fluidExport = new ProseMirrorRuntimeFactory();