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

onBlockRendererSlotted hook is not working #7518

Closed
jsjant opened this issue Nov 29, 2022 · 7 comments
Closed

onBlockRendererSlotted hook is not working #7518

jsjant opened this issue Nov 29, 2022 · 7 comments
Assignees
Labels
plugins :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section.

Comments

@jsjant
Copy link

jsjant commented Nov 29, 2022

Hi!

onBlockRendererSlotted hook is described in docs, but it's not in the code. So I wonder if it is possible to use it?

Also, could you please tell me if there's a way to change how a block is rendered using plugins (and most importantly to intercept rendering process)? I'd like to have an ability to make hyperlink from text matching certain pattern. For instance, if it says JIRA-2009, then it's a link to your JIRA installation somewhere.

@xyhp915
Copy link
Collaborator

xyhp915 commented Dec 1, 2022

Hi @jsjant Thank you for the reminder. This API was temporarily shelved for implementation at the time due to plans to support unique block types. But the block type implementation has a low priority in the near future. So I will implement this API as soon as possible to support intercepting block rendering by block UUID.

@cnrpman cnrpman added the :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section. label Dec 2, 2022
@sbenhaim
Copy link

+1 – This API hook would support a significant range of interesting plugins that are currently difficult or impossible to write cleanly. (Including the one I'm currently trying to write for embedding mini-apps into docs a la Coda.io 😉).

Obsidian's API, for instance, provides access to the relevant DOM element prior to rendering, making it very easy to manipulate it at will, for instance, by injecting React components inside of it.

@xyhp915 xyhp915 mentioned this issue Dec 14, 2022
7 tasks
@jsjant
Copy link
Author

jsjant commented Dec 23, 2022

@xyhp915 Hi!

I saw that #7555 is merged. Does it close this one? If so, could you please provide an example usage? I tried on 0.8.13, but didn't understand how to use this new API.

Thank you in advance!

@xyhp915
Copy link
Collaborator

xyhp915 commented Dec 23, 2022

Cool @jsjant This feature is released into 0.8.14, so you can try the latest version. Also, do not forget to upgrade plugin SDK @logseq/libs to the latest (0.0.14). Here's a simple demo plugin for you :)
test-block-render-plugin.zip
CleanShot 2022-12-23 at 16 21 23@2x

@jsjant
Copy link
Author

jsjant commented Dec 23, 2022

Cool @jsjant This feature is released into 0.8.14, so you can try the latest version. Also, do not forget to upgrade plugin SDK @logseq/libs to the latest (0.0.14). Here's a simple demo plugin for you :)
test-block-render-plugin.zip
CleanShot 2022-12-23 at 16 21 23@2x

It worked! Thank you!

@jsjant jsjant closed this as completed Dec 23, 2022
@chuan137
Copy link

@xyhp915 @jsjant
is there API to remove such a block hook?

@dagron
Copy link

dagron commented Jun 7, 2023

It returns a cleanup function. If the code is to be believed :)

onBlockRendererSlotted(
    uuid,
    callback: (payload: any) => void) {
    if (!shouldValidUUID(uuid)) return

    const pid = this.baseInfo.id
    const hook = `hook:editor:${safeSnakeCase(`slot:${uuid}`)}`

    this.caller.on(hook, callback)
    this.App._installPluginHook(pid, hook)

    return () => {
      this.caller.off(hook, callback)
      this.App._uninstallPluginHook(pid, hook)
    }
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section.
Projects
None yet
Development

No branches or pull requests

6 participants