🧩 logseq.provideUI
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.
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.
In case I'm using onBlockRendererSlotted for a block, is it possible to keep rendering using Markdown? How does "template" work?
@5hir0kur0
Is there a way to know whether the provided slot was invalid? I have a plugin that uses
onMacroRendererSlottedbut 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").
@daviddavo
In case I'm using
onBlockRendererSlottedfor 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