Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.42k stars 1.99k forks source link

TourKit: First class Editor support #64256

Open mattwiebe opened 2 years ago

mattwiebe commented 2 years ago

Background

Currently TourKit optionally positions itself with respect to some element on the canvas with a set of referenceElements, further broken down into mobile and desktop selectors (eg). This works tolerably well for UI elements, but runs into problems with actual Block elements because:

  1. The Site Editor's editor canvas is encapsulated in an iframe, which can't be addressed by a simple selector (the Post Editor and others are intended to migrate to an iframe in the future as well).
  2. The desktop vs mobile distinction is over-engineered. In practice they are all identical.

Adding Editor support

Let's add a separate referenceBlock field to the WpcomStep type and use it by default, falling back to referenceElement 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-found referenceBlock, 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, eg core/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 the 0 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 use useBlockElement and/or useBlockRef from https://github.com/WordPress/gutenberg/pull/29573 here (they are buried in internals and we may need to re-implement similar logic).

Checklist

Related

64080

mattwiebe commented 2 years ago

Some concerns originally raised in #64080 that partially prompted this issue:

Maintenance concerns with the challenge of brittle DOM selectors.

rjchow commented 2 years ago

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