plugins icon indicating copy to clipboard operation
plugins copied to clipboard

🧩 logseq.provideUI

Open utterances-bot opened this issue 2 years ago • 5 comments

https://plugins-doc.logseq.com/logseq/provideUI

utterances-bot avatar Sep 19 '23 17:09 utterances-bot

Is there a way to know whether the provided slot was invalid? I have a plugin that uses onMacroRendererSlotted but the UI needs to be updated every few seconds and I use a JavaScript timeout for that. However, when the user edits the block etc. the slot can become invalid. Logseq detects this and prints a message like can not resolve selector target #slot__whppb9x3. It would be great if provideUI could throw an exception instead of just printing to the console, so I can stop trying to update the invalid slot in this case.

5hir0kur0 avatar Sep 19 '23 17:09 5hir0kur0

Here are supported methods defined in https://github.com/logseq/logseq/blob/master/libs/src/helpers.ts#L422-L451

    'click',
    'focus',
    'focusin',
    'focusout',
    'blur',
    'dblclick',
    'keyup',
    'keypress',
    'keydown',
    'change',
    'input',
    'contextmenu',

Notice that use data-on-focusout instead of data-on-focus-out

Works fine except on-blur, which does not bubble.

Sansui233 avatar Dec 03 '23 20:12 Sansui233

In case I'm using onBlockRendererSlotted for a block, is it possible to keep rendering using Markdown? How does "template" work?

daviddavo avatar Mar 29 '24 20:03 daviddavo

@5hir0kur0

Is there a way to know whether the provided slot was invalid? I have a plugin that uses onMacroRendererSlotted but the UI needs to be updated every few seconds and I use a JavaScript timeout for that. ..............

It would not be possible to pick up an exception when using setTimeout. There is a way to use the DOM and check if the element in question exists by doing something like const element = parent.document.getElementById("edit-block-UuidHere").

YU000jp avatar Jun 22 '24 23:06 YU000jp

@daviddavo

In case I'm using onBlockRendererSlotted for a block, is it possible to keep rendering using Markdown? How does "template" work?

The Markdown is not lost during rendering, but many callbacks occur. A variable can be used to put a processing lock to the process. (let processing === false) Set it to true after processing. "provideUI" template is a the pop-up content. If the key is not changed, the content can be updated. It should be controlled so that it is not executed too frequently.

Learn more about provideUI. https://github.com/logseq/logseq/pull/3045

YU000jp avatar Jun 22 '24 23:06 YU000jp