Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow start page and get error in vue #6209

Closed
jooler opened this issue Feb 9, 2024 · 10 comments
Closed

follow start page and get error in vue #6209

jooler opened this issue Feb 9, 2024 · 10 comments
Labels
mod:widget Related to positioned menus type:bug Something isn't working

Comments

@jooler
Copy link

jooler commented Feb 9, 2024

I have add blocksuite follow this page
https://blocksuite.io/guide/quick-start.html
And some CORS error here

Access to font at 'https://cdn.affine.pro/fonts/Inter-Light-BETA.woff' from origin 'http://localhost:9000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

there are too many...

22222

@doodlewind doodlewind added type:bug Something isn't working mod:widget Related to positioned menus labels Feb 11, 2024
@doodlewind
Copy link
Member

Thanks for the feedback!

This should be the default font list used for rendering canvas text, we are moving towards making this configurable via the per-widget configs (see _specs.ts as the way composing widgets and blocks, there should be declarative APIs for customizing the font list config and etc.).

I suppose this will be handled by team member after the Lunar New Year holiday. Cheers! cc @Flrande

@Flrande
Copy link
Member

Flrande commented Feb 13, 2024

This is because the canvas text in edgeless requires specific font files, which can be avoided by directly overriding loadFonts or handling the font file location yourself.

https://github.com/toeverything/AFFiNE/blob/9e7eb5629cd6cf35bdf127d9e7d502093dbacc4e/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs.ts#L15-L35

Usually, we don't need the functionality of edgeless, that is, we only need to use DocPageSpec. In this case, we should not import CanvasTextFonts. This is an area that needs improvement, and I will make changes later to avoid the dependency of doc mode on CanvasTextFonts. This way, you only need to avoid this error by replacing the spec (if you don't need edgeless)

@kyrylolvov
Copy link

@doodlewind @Flrande Are there any updates on this or some workaround?

@Flrande
Copy link
Member

Flrande commented Feb 14, 2024

@doodlewind @Flrande Are there any updates on this or some workaround?

Look at my recent comment, you can workaround by overriding the spec

This is because the canvas text in edgeless requires specific font files, which can be avoided by directly overriding loadFonts or handling the font file location yourself.

https://github.com/toeverything/AFFiNE/blob/9e7eb5629cd6cf35bdf127d9e7d502093dbacc4e/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs.ts#L15-L35

@kyrylolvov
Copy link

@Flrande Are there any examples on how to override behaviour in the editors?

I am using const editor = new AffineEditorContainer();

@Flrande
Copy link
Member

Flrande commented Feb 15, 2024

@Flrande Are there any examples on how to override behaviour in the editors?

I am using const editor = new AffineEditorContainer();

Create a new spec and pass it by docSpecs and edgelessSpecs in AffineEditorContainer

https://blocksuite.io/guide/working-with-block-tree.html#defining-new-blocks

#5339

@kyrylolvov
Copy link

Thanks! Was able to disable font loading this way

import { DocEditorBlockSpecs, EdgelessEditorBlockSpecs, DocPageService, EdgelessPageService } from '@blocksuite/blocks';

class CustomDocPageService extends DocPageService {
  loadFonts() {}
}

class CustomEdgelessPageService extends EdgelessPageService {
  loadFonts() {}
}

export const getSpecs = () => {
  const docModeSpecs = DocEditorBlockSpecs.map((preset) => {
    if (preset.schema.model.flavour === 'affine:page') {
      return {
        ...preset,
        service: CustomDocPageService,
      };
    }

    return preset;
  });

  const edgelessModeSpecs = EdgelessEditorBlockSpecs.map((preset) => {
    if (preset.schema.model.flavour === 'affine:page') {
      return {
        ...preset,
        service: CustomEdgelessPageService,
      };
    }

    return preset;
  });

  return {
    docModeSpecs,
    edgelessModeSpecs,
  };
};
const editor = new AffineEditorContainer();
editor.docSpecs = presets.docModeSpecs;
editor.edgelessPreset = presets.edgelessModeSpecs;

@jooler
Copy link
Author

jooler commented Feb 15, 2024

Thanks! Was able to disable font loading this way

import { DocEditorBlockSpecs, EdgelessEditorBlockSpecs, DocPageService, EdgelessPageService } from '@blocksuite/blocks';

class CustomDocPageService extends DocPageService {
  loadFonts() {}
}

class CustomEdgelessPageService extends EdgelessPageService {
  loadFonts() {}
}

export const getSpecs = () => {
  const docModeSpecs = DocEditorBlockSpecs.map((preset) => {
    if (preset.schema.model.flavour === 'affine:page') {
      return {
        ...preset,
        service: CustomDocPageService,
      };
    }

    return preset;
  });

  const edgelessModeSpecs = EdgelessEditorBlockSpecs.map((preset) => {
    if (preset.schema.model.flavour === 'affine:page') {
      return {
        ...preset,
        service: CustomEdgelessPageService,
      };
    }

    return preset;
  });

  return {
    docModeSpecs,
    edgelessModeSpecs,
  };
};
const editor = new AffineEditorContainer();
editor.docSpecs = presets.docModeSpecs;
editor.edgelessPreset = presets.edgelessModeSpecs;

hwo to make it in vue?
pls....thx...

@kyrylolvov
Copy link

@jooler So if you followed the quick-start guide on the website

import '@blocksuite/presets/themes/affine.css';

import { createEmptyPage, DocEditor } from '@blocksuite/presets';
import { Text } from '@blocksuite/store';

(async () => {
  // Init editor with default block tree
  const page = await createEmptyPage().init();
  const editor = new DocEditor();
  editor.page = page;
  document.body.appendChild(editor);

  // Update block node with some initial text content
  const paragraphs = page.getBlockByFlavour('affine:paragraph');
  const paragraph = paragraphs[0];
  page.updateBlock(paragraph, { text: new Text('Hello World!') });
})();

I assume you can just create the same getSpecs() function, just without edgelessMode and then pass it like editor.docSpecs = presets.docModeSpecs;

@jooler
Copy link
Author

jooler commented Feb 16, 2024

@kyrylolvov thank you, it works now...

@linear linear bot removed mod:widget Related to positioned menus type:bug Something isn't working labels Mar 11, 2024
@fourdim fourdim added type:bug Something isn't working mod:widget Related to positioned menus labels Mar 20, 2024
@fourdim fourdim closed this as completed Mar 20, 2024
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod:widget Related to positioned menus type:bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

5 participants