1414 * limitations under the License.
1515 */
1616
17- import type { IConfigService as IConfigServiceType , Injector } from '@univerjs/core' ;
17+ import type { Injector } from '@univerjs/core' ;
1818import type { IEmbedBlockContribution , IEmbedChildContainerContext , IEmbedChildViewContribution } from '@univerjs/embed-ui' ;
1919import type { IDocFitToWidthOptions , IUniverDocsUIConfig } from './config/config' ;
20- import { IConfigService , UniverInstanceType } from '@univerjs/core' ;
21- import { createEmbedRibbonBlockContribution , mountEmbedRenderChildUnit } from '@univerjs/embed-ui' ;
20+ import { UniverInstanceType } from '@univerjs/core' ;
21+ import { createEmbedRibbonBlockContribution , createEmbedScopedConfigInjector , mountEmbedRenderChildUnit } from '@univerjs/embed-ui' ;
2222import { IRenderManagerService } from '@univerjs/engine-render' ;
2323import { DOCS_UI_PLUGIN_CONFIG_KEY } from './config/config' ;
2424import { DocFloatMenuService } from './services/float-menu.service' ;
@@ -46,8 +46,11 @@ export function createDocsEmbedChildViewContribution(): IEmbedChildViewContribut
4646 beforeDeactivate : deactivateEmbeddedDocSelection ,
4747 mount : ( context ) => {
4848 if ( context . renderScope . mode === 'float' ) {
49- applyDocsEmbedFitToWidthConfig ( context . runtimeScope . injector ) ;
49+ return mountEmbedRenderChildUnit ( context , IRenderManagerService , undefined , {
50+ scopedInjector : createDocsEmbedRenderScopedInjector ( context . runtimeScope . injector ) ,
51+ } ) ;
5052 }
53+
5154 return mountEmbedRenderChildUnit ( context , IRenderManagerService ) ;
5255 } ,
5356 } ;
@@ -63,34 +66,10 @@ function deactivateEmbeddedDocSelection(context: IEmbedChildContainerContext): v
6366 docSelectionRenderService ?. blur ( ) ;
6467}
6568
66- function applyDocsEmbedFitToWidthConfig ( injector : Injector ) : void {
67- if ( ! injector . has ( IConfigService ) ) {
68- return ;
69- }
70-
71- const configService = injector . get < IConfigServiceType > ( IConfigService ) ;
72- injector . add ( [ IConfigService , {
73- useValue : createDocsEmbedConfigService ( configService ) ,
74- } ] ) ;
75- }
76-
77- function createDocsEmbedConfigService ( configService : IConfigServiceType ) : IConfigServiceType {
78- return new Proxy ( configService , {
79- get ( target , property , receiver ) {
80- if ( property === 'getConfig' ) {
81- return < T > ( id : string | symbol ) : T => {
82- const config = target . getConfig < T > ( id ) ;
83- if ( id !== DOCS_UI_PLUGIN_CONFIG_KEY ) {
84- return config ;
85- }
86-
87- return withDocsEmbedFitToWidthConfig ( config as Partial < IUniverDocsUIConfig > | undefined ) as T ;
88- } ;
89- }
90-
91- return Reflect . get ( target , property , receiver ) ;
92- } ,
93- } ) ;
69+ function createDocsEmbedRenderScopedInjector ( injector : Injector ) : Injector | undefined {
70+ return createEmbedScopedConfigInjector ( injector , new Map ( [
71+ [ DOCS_UI_PLUGIN_CONFIG_KEY , ( config ) => withDocsEmbedFitToWidthConfig ( config as Partial < IUniverDocsUIConfig > | undefined ) ] ,
72+ ] ) ) ;
9473}
9574
9675function withDocsEmbedFitToWidthConfig ( config : Partial < IUniverDocsUIConfig > | undefined ) : Partial < IUniverDocsUIConfig > {
0 commit comments