Open mattwiebe opened 2 years ago
Some concerns originally raised in #64080 that partially prompted this issue:
In case you missed it - https://github.com/Automattic/wp-calypso/pull/64647#issuecomment-1157360901
It's probably worth having a look at floating-ui as it's the successor of popperjs and undergoing active development
Background
Currently
TourKit
optionally positions itself with respect to some element on the canvas with a set ofreferenceElements
, further broken down intomobile
anddesktop
selectors (eg). This works tolerably well for UI elements, but runs into problems with actual Block elements because:desktop
vsmobile
distinction is over-engineered. In practice they are all identical.Adding Editor support
Let's add a separate
referenceBlock
field to theWpcomStep
type and use it by default, falling back toreferenceElement
if present and a statically positioned step in the absence of both. If the element isn't found it should fallback to no positioning. (We will also want to introduce a callback in another issue to deal with a not-foundreferenceBlock
, possibly prompting the user to insert one, such as ensuring there's a Post Content block in the currently-edited Template, and offering to insert one.)To start, the
referenceBlock
field will simply name a block type, egcore/paragraph
to select. There is a very handy__experimentalGetGlobalBlocksByName
selector in the@wordpress/block-editor
package for just this purpose. To start with, let's simply return the0
index of the found blocks.This will return some
clientIDs
that we can then use to derive the actual DOM element for ultimately passing internally to the Popper.js library. Investigate if we can useuseBlockElement
and/oruseBlockRef
from https://github.com/WordPress/gutenberg/pull/29573 here (they are buried in internals and we may need to re-implement similar logic).Checklist
referenceElement
to a single selectorreferenceBlock
member toWpcomStep
core/block-editor
storescrollIntoView
logic for when the desired block is offscreenreturn [0, 0]
) in the Site Editor so beware. We might want to remove that modifier altogether in favour of what we do in the next step:offset
Popper modifierRelated
64080