toeverything/blocksuite

reference-node external configuration

Closed this issue · 4 comments

How to update the config value of
const config = provider.getOptional(ReferenceNodeConfigIdentifier) ​​?? {}; after upgrading
Do I need to use ReferenceNodeConfigExtension? How to use it?
I see that affine-paragraph no longer has referenceNodeConfig

image
How to update this value externally

image

This is what I'm doing now. Is this correct?

L-Sun commented

You can add a ConfigExtension to editor.pageSpecs and editor.edgelessSpecs. For example, in the setup stage of playground editor:

  • Before
    const refNodeSlotsExtension = RefNodeSlotsExtension();
    editor.pageSpecs = patchPageRootSpec([
    refNodeSlotsExtension,
    ...specs.pageModeSpecs,
    ]);
    editor.edgelessSpecs = patchPageRootSpec([
    refNodeSlotsExtension,
    ...specs.edgelessModeSpecs,
    ]);
  • After
    const referenceNodeConfigExtension : ExtensionType = {
      setup: di => {
        const prev = di.getFactory(ReferenceNodeConfigIdentifier);
        di.override(ReferenceNodeConfigIdentifier, provider => {
          return {
            ...prev?.(provider), // If you wan to fully control the configs, remove this line
            // Your configs put here
          } satisfies ReferenceNodeConfig;
        });
      }
    } 
    
    editor.pageSpecs = patchPageRootSpec([
      refNodeSlotsExtension,
      ...specs.pageModeSpecs,
      referenceNodeConfigExtension,
    ]);
    editor.edgelessSpecs = patchPageRootSpec([
      refNodeSlotsExtension,
      ...specs.edgelessModeSpecs,
     referenceNodeConfigExtension,
    ]);
L-Sun commented

image

This is what I'm doing now. Is this correct?

Basically correct if there is no other reference node configuration. More precisely,

  • you also need to push the extension to EdgelessEditorBlockSpecs
  • you can override the configuration in this way,
  • or partially modify the configuration by following the instructions in the my comments above.