Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZUIEditor link and button extensions #2477

Merged

Conversation

richardolsson
Copy link
Member

@richardolsson richardolsson commented Jan 17, 2025

Description

This PR finishes link and button extensions for the new ZUIEditor, initially implemented by @ziggabyte and then finished by me.

They use a common TextAndHrefOverlay component for their UI.

Screenshots

Button

image

Link

image

Changes

  • Creates LinkExtensionUI and ButtonExtensionUI components that both render a TextAndHrefOverlay
  • Adds commands to set text and href for buttons
  • Adds commands to set text and href on links, as well as to clean away empty links

Notes to reviewer

Note especially how I solved the two new commands in the ButtonExtension, which rely heavily on resolve() to find the relevant positions. The resolve() function could also be useful in situations where we need to find the relevant nodes, since it returns a depth and node() function to retrieve the node and it's ancestors at the current position.

For the new "Create link" feature, that inserts a link without converting an existing text range, I chose to insert a link node consisting of a single non-breaking space (String.fromCharCode(160)) and select it. For some reason, a regular space (' ') did not work reliably.

Related issues

Undocumented

@richardolsson richardolsson changed the title ZUIEditor link extension (WIP) ZUIEditor link and button extensions Jan 17, 2025
@richardolsson richardolsson marked this pull request as ready for review January 17, 2025 14:06
@richardolsson
Copy link
Member Author

I'm going to merge this into the editor branch to avoid more conflicts, but I still think you should have a look when you get a chance @ziggabyte.

@richardolsson richardolsson merged commit bbebed7 into undocumented/ZUI-text-editor Jan 18, 2025
6 checks passed
@richardolsson richardolsson deleted the undocumented/ZUI-editor-tools branch January 18, 2025 05:25
const mark = this.type.create();
const node = this.type.schema.text(String.fromCharCode(160), [mark]);
const pos = state.selection.$head.pos;
tr = tr.insert(pos, node);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone should check if tr == tr.insert(pos, node), i.e. if the tr object changes or is immutable and gets copied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants