codex-team / codex-team/editor.js
Inline Tool API: Export Selection Utility Functions
- Dominant language
- TypeScript
- Stars
- 31.9k
- Forks
- 2.2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
It would be nice to use the Selection Utility functionality in custom inline tools for some of the following tasks:
- creating fake background (with temporary span node)
- save/restore/clear range state when focus is lost when the renderActions() custom tooling is doing some user interactions (like accepting interacting with the user, etc)
#### Additional notes (1/28)
Here is an example use case. How would it be possible to create a new inline tool (call it Alternative Link) that uses its own custom tag (for the sake of argument `a-alt`), where when you click the icon to add a link, you get an input box and the same kind of experience as when you build a normal `a` link with the default `inline-tools/inline-tool-link` component.
The problem I have found trying to create this are:
- the Selection API (the the ability to save()/restore() range state) is not available to 3rd party tools
- the Selection API for putting in the fake selection background is not available to 3rd party tools
- it is hard to mentally understand/reason about all the state necessary to build an inline tool that can co-exist with other tools while replicating the "fake background" experience
- (Primarily b/c there are multiple selections and ranges that have to be taken into account)
- Should you put your markup inline and fill in the inputted data later? There is no good tutorial on how to manage the state of multiple inline tools
- The core selectionChanged (https://github.com/codex-team/editor.js/blob/master/src/components/modules/ui.ts#L615-L622) function assumes that focus has been shifted into an input (so that the closest() returns a node, if it doesn't it will close the whole toolbar (this seems like a bug, it might be a bad assumption: what happens if the 3rd party tool doesn't have an input that has taken focus)
- similarly, the inline `allowedToShow` (https://github.com/codex-team/editor.js/blob/master/src/components/modules/toolbar/inline.ts#L315-L332) uses the Selection API to determine if there is currently selected text, but what happens if the 3rd party tool is making its own fake background and there is currently no actual selection?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.