@@ -19,12 +19,12 @@ const editor = createQalmaEditor({
1919
2020## Commands and query
2121
22- | Contract | Description |
23- | -------- | ----------- |
24- | ` setLink ` | Applies a link to the selection or stores it for future typed text. |
25- | ` selectLink ` | Selects an existing link by current state, document range, or anchor element. |
26- | ` unsetLink ` | Removes the active link mark. |
27- | ` query<LinkState>('link') ` | Returns link range, attributes, and text for the active or selected link. |
22+ | Contract | Description |
23+ | -------------------------------- | ------------------------------------------------------------------ ----------- |
24+ | ` setLink ` | Applies a link to the selection or stores it for future typed text. |
25+ | ` selectLink ` | Selects an existing link by current state, document range, or anchor element. |
26+ | ` unsetLink ` | Removes the active link mark. |
27+ | ` query<LinkState>('link') ` | Returns link range, attributes, and text for the active or selected link. |
2828
2929` setLink ` accepts a string or an object.
3030
@@ -64,17 +64,19 @@ const editor = createQalmaEditor({
6464 allowRelativeLinks: true ,
6565 defaultTarget: ' _blank' ,
6666 defaultRel: ' noopener noreferrer' ,
67+ onClick: null ,
6768 }),
6869 ],
6970});
7071```
7172
72- | Option | Default | Description |
73- | ------ | ------- | ----------- |
74- | ` allowedProtocols ` | ` ['http', 'https', 'mailto', 'tel'] ` | Protocol allow-list. Entries are names without ` : ` . |
75- | ` allowRelativeLinks ` | ` true ` | Allows links without a protocol. |
76- | ` defaultTarget ` | ` '_blank' ` | Applied when command values or pasted DOM do not provide a target. Only ` '_blank' ` is preserved. |
77- | ` defaultRel ` | ` 'noopener noreferrer' ` | Applied when command values or pasted DOM do not provide ` rel ` . Empty strings become ` null ` . |
73+ | Option | Default | Description |
74+ | -------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
75+ | ` allowedProtocols ` | ` ['http', 'https', 'mailto', 'tel'] ` | Protocol allow-list. Entries are names without ` : ` . |
76+ | ` allowRelativeLinks ` | ` true ` | Allows links without a protocol. |
77+ | ` defaultTarget ` | ` '_blank' ` | Applied when command values or pasted DOM do not provide a target. Only ` '_blank' ` is preserved. |
78+ | ` defaultRel ` | ` 'noopener noreferrer' ` | Applied when command values or pasted DOM do not provide ` rel ` . Empty strings become ` null ` . |
79+ | ` onClick ` | ` null ` | Optional callback for editor link clicks. When configured, Qalma prevents the native click and passes the link event to the host app. |
7880
7981Invalid or empty hrefs make ` setLink ` return ` false ` .
8082
@@ -118,10 +120,36 @@ editor.execute('selectLink', { from: link.from, to: link.to });
118120
119121## Click behavior
120122
121- The plugin handles clicks on editor links. It prevents the editor click,
122- normalizes the href with the same options, and opens ` _blank ` links with
123- ` window.open(href, '_blank', 'noopener,noreferrer') ` . Other links assign
124- ` window.location.href ` .
123+ The plugin does not navigate on editor link clicks by default. Navigation,
124+ routing, analytics, previews, and confirmation flows stay in your app.
125125
126- If your product needs a different link-click policy, wrap the editor or build a
127- custom plugin that handles those DOM events first.
126+ Configure ` onClick ` when you want Qalma to turn editor link clicks into a
127+ consumer-owned event. Qalma normalizes the href with the same options, prevents
128+ the native click, and passes the DOM event, anchor element, href, target, rel,
129+ and text to your callback.
130+
131+ ``` typescript
132+ import { LinkClickHandler , LinkPlugin } from ' @qalma/editor' ;
133+
134+ const handleLinkClick: LinkClickHandler = ({ href , target }) => {
135+ if (target === ' _blank' ) {
136+ window .open (href , ' _blank' , ' noopener,noreferrer' );
137+
138+ return ;
139+ }
140+
141+ window .location .assign (href );
142+ };
143+
144+ const editor = createQalmaEditor ({
145+ plugins: [
146+ LinkPlugin .configure ({
147+ onClick: handleLinkClick ,
148+ }),
149+ ],
150+ });
151+ ```
152+
153+ That example intentionally keeps navigation in application code. A routed
154+ Angular app can call its router, open a product-specific preview, or ignore the
155+ click entirely.
0 commit comments