The picker can be used as a “drop-in” replacement for textareas, allowing Content Block embed codes from
Content Block Manager to be
highlighted.
It works by overlaying a transparent textarea on top of a styled <div> that contains the highlighted content. This ensures that standard textarea behaviour is maintained while providing visual highlighting.
Usage
To initialise the picker on a textarea, simply instantiate a new ContentBlockPicker specifying the following:
baseUrl : This is the URL of the Content Block Manager API.
textarea : This is an HTMLTextArea element where users enter document body content.
insertButton : This is the button users will click to view the list of available blocks.
embedPreviewDelayMs : (optional) This is the artificial delay between a user hovering over an embed and the preview being displayed.
The picker can show editors the content blocks available to them so they don’t need to know an embed code up front.
Clicking the button opens an overlay that fetches the blocks from GET {baseUrl}/api/blocks and lists each one by title, with its available formats nested underneath. The list is loaded fresh each time it is opened (so it always reflects the current state of the blocks) and is dismissed by pressing Escape, clicking the list, or clicking anywhere outside it.
Each textarea is wired to its own button, so multiple editors can appear on the same page. The attribute is optional — omit it and the picker behaves exactly as before.