/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { type IFluidMountableView, type 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 { CodeMirrorComponent, SmdeFactory } from "./codeMirror.js"; import { CodeMirrorReactView } from "./codeMirrorView.js"; export { CodeMirrorComponent, SmdeFactory } from "./codeMirror.js"; export { CodeMirrorReactView } from "./codeMirrorView.js"; const defaultComponentId = "default"; const smde = new SmdeFactory(); class CodeMirrorFactory 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 codeMirror = await getDataStoreEntryPoint( containerRuntime, defaultComponentId, ); const view = createElement(CodeMirrorReactView, { text: codeMirror.text, presenceManager: codeMirror.presenceManager, }) as unknown as IFluidMountableView; let getMountableDefaultView = async (): Promise => view; if (MountableView.canMount(view)) { getMountableDefaultView = async () => new MountableView(view); } return { getDefaultDataObject: async () => codeMirror as FluidObject, getMountableDefaultView, }; }, }); return runtime; } } /** * @internal */ export const fluidExport = new CodeMirrorFactory();