Idea for a Help plugin

This should be very useful for anyone new to TW, if it were possible:

A small [?] mark up in a corner that can be drag’n dropped onto any element in TW so to get information about that element.

Questions:

  1. Would this be possible to do without having to modify all elements (e.g without needing to wrap them in a droppablewidget)?
  2. Is there some modus operandi to decide what the [?] is actually being dropped at - e.g if the user drops on, say, the title, did he meand that or did he mean the full titlebar or maybe the full tiddler, or even the story river, etc.

(This is a hypothetical question. I’m not attempting to build it.)

TidGi app already have this, just like Obsidian’s Help vault, see also TidGi Desktop v0.9.0 release

Help wiki usually very big, you won’t want it to be a plugin in your wiki.

1 Like

Are you saying it has the drag’n drop feature I ask about? I.e basically the same as being able to merely point to something and get help about it. For this particular aspect of help, it is not sufficient if the beginner needs to type into a search box because a beginner does not know what words to type.

BTW, I get this for https://tidgi.fun

If you want to drop / context click on an element to get metadata, it is simillar to [IDEA] Plugin sourcing, find out UI element is caused by which plugin/tiddler · Issue #6345 · TiddlyWiki/TiddlyWiki5 · GitHub , just need to add some data-xxx attributes to HTML tags.

https://tidgi.fun maybe unstable due to the tunneling service I’m using, it is up after a while.

Do you know if it is possible to click on an element to extract its position in the dom?

While, as stated, this whole idea is merely hypothetical, it’s still interesting to know what could be possible. But it is not an option to add to, or significntly modify, the core for what I have in mind here.

Possible with JS, use a Startup script to register global click listener (or only register drag & drop listener on “?” element), you will get every event as a JS Object, which contains x,y,and any metadata on it.

Only in the spirit of proving that this should be possible, I can supply a very early proof of concept, for use in the developer’s console (launched with CTRL-SHIFT-J / CMD-SHIFT-J on many browsers). By entering the code below in the console launched from tiddlywiki.com (or your preferred wiki), and then dragging some draggable element—the items in the Open tab work—and dropping them on an element, you should get console output like this:

HTML : 
  BODY : tc-body
    DIV :  tc-page-container-wrapper
      DIV : 
        DIV : tc-page-container tc-page-view-classic tc-language-en-GB
          DIV : tc-dropzone tc-page-container-inner
            SECTION : tc-story-river
              DIV : tc-tiddler-frame tc-tiddler-view-frame tc-tiddler-exists  tc-tagged-TableOfContents
                DIV : tc-tiddler-body tc-reveal
                       """Welcome to TiddlyWiki, a unique non-linear notebook for capturing, organising and sharing complex information\n\nUse it to keep your to-do list, to pl..."""

or this:

HTML : 
  BODY : tc-body
    DIV :  tc-page-container-wrapper
      DIV : 
        DIV : tc-page-container tc-page-view-classic tc-language-en-GB
          DIV : tc-dropzone tc-page-container-inner
            DIV : tc-sidebar-scrollable
              DIV : 
                DIV : tc-sidebar-header
                  DIV :  tc-reveal
                    DIV :  tc-reveal
                      P : 
                        DIV : tc-page-controls
                          BUTTON : tc-btn-invisible tc-btn-%24%3A%2Fcore%2Fui%2FButtons%2Fnew-tiddler
                            svg : tc-image-new-button tc-image-button
                                  """(no text)"""

This is the code:

const walkUp = (node) => node == null ? [] : [node, ...walkUp(node.parentNode)]

const elementString = (el) => 
  [el.nodeName, ...(el.id ? ['#' + el.id] : []), el.classList] .join (' : ')

const indent = (depth) => '  '.repeat(depth)

const shortenText = (length) => (s = "(no text)", text = s.replace(/\n/g, "\\n")) => 
  '"""' + text.slice(0, length) + (text.length > length ? '...' : '') + '"""'

document.body.addEventListener('dragover', (event) => {event.preventDefault()})

document.body.addEventListener('drop', (event) => {
  const target = event.target
  const hierarchy = walkUp(target).reverse().slice(1)
  const display = hierarchy.map((node, i) => indent(i) + elementString(node)).join('\n')
  const text = target.innerText
  console.log(display)
  console.log(indent(hierarchy.length + 2) + shortenText(150)(text)) 
  event.preventDefault();
})

With a little work, we could ensure that your question mark is draggable and that this code only fires when that mark is the element being dragged. And of course, we could put this output in an overlay or something instead of the developer console.

But before considering how to do that, is this the sort of output you’re looking for? It’s easy enough to get DOM content like this. If you’re trying to get something TiddlyWiki-specific, I don’t even know if there are any techniques that would offer this, never mind how to use them.

I’m expecting this would have to be in a JS module of some sort and not in wikitext, but people have often proven me wrong when I’ve said that.

Oh! That seems very much like what I’m envisioning. Again, though, the concept is at this stage purely hypothetical (as there is a certain other project that is much more important).

Is there a way that the “system” could know that I really want “tc-sidebar-scrollable” when I’m hovering/dropping the ? over the “tc-sidebar-header”? I’m guessing it would need to assume I want maximum “path depth” and so I must not hover “tc-sidebar-header” if I want “tc-sidbar-scrollable”. I wonder if every element has space to hover, i.e where inner elements don’t reach the outer elemtents edges…

While wikitext would be nice, I don’t think it is necessary for this. BUT it would be useful if the presented “help content” could be stored in, and thus fetched from, editable tiddlers. Perhaps even in a simple dictionary.

…but - thinking out loud - what would happen if, say, some plugin modifies the path structure? How would the system know which help to present? …

Yes, hover is not going to find any elements whose children cover their every pixel.

Sure, it’s easy enough to imagine a UI that lets you SAVE the results, giving it a memorable name, presumably in $:/temp. Whether that’s in a dictionary, or uses a dedicated tag or a naming convention is a minor detail.

I’m not following that. This code is essentially examining the live document and finding the path that leads to the bottommost hovered element. I’ve captured the node name, id (rare in TW), and classes for each node, and grabbed a short text extract from that bottommost element. We could capture other information, but it’s all about the live document. That code has nothing to do with Tiddlywiki. You could run it anywhere that has draggable elements. It does nothing you can’t already do with the DOM inspector, but it might offer a path toward your goal.

Precisely what I was thinking and had a draft response waiting to post when the inspiration for how to do it arrived. But it didn’t :frowning:

Good stuff Scott!

Yes, very clear to devs.

@twMat Because even the browser/DevTools isn’t sure what you want, it offers a whole menu of options to do what Scott’s code is hinting it. Right click on any element in the DOM - I’m choosing a title:

You should take a look at those, not because they provide a solution to the OP but just because you’ll be aware of the current approaches available before we wade into a wikitext (or js) solution.