Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 63a4c1b

Browse files
committed
handle getLinkInfo
1 parent 0098fc0 commit 63a4c1b

File tree

2 files changed

+2
-65
lines changed

2 files changed

+2
-65
lines changed

packages/bundle-odoo-website-editor/odoo-integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { InlineNode } from '../plugin-inline/src/InlineNode';
1010
import { LinkFormat } from '../plugin-link/src/LinkFormat';
1111
import { Attributes } from '../plugin-xml/src/Attributes';
1212
import { OdooStructureNode } from '../plugin-odoo/src/OdooStructureNode';
13+
import { Inline } from '../plugin-inline/src/Inline';
1314
import { getOdooCommands } from '../plugin-odoo/src/OdooCommands';
1415

1516
export {
@@ -27,4 +28,5 @@ export {
2728
LinkFormat,
2829
Attributes,
2930
OdooStructureNode,
31+
Inline,
3032
};

packages/plugin-dom-helpers/src/DomHelpers.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,6 @@ import { CharNode } from '../../plugin-char/src/CharNode';
1414
import { Inline } from '../../plugin-inline/src/Inline';
1515
import { Parser } from '../../plugin-parser/src/Parser';
1616

17-
interface SelectedLinkInfo {
18-
/**
19-
* The selected text
20-
*/
21-
text: string;
22-
/**
23-
* The url of the link
24-
*/
25-
url: string;
26-
/**
27-
* The css class associated with the link
28-
*/
29-
class: string;
30-
/**
31-
* The target of an html anchor.
32-
* Could be "_blank", "_self" ,"_parent", "_top" or the framename.
33-
*/
34-
target: string;
35-
}
36-
3717
export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<T> {
3818
commands = {
3919
'dom.addClass': {
@@ -69,9 +49,6 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
6949
'dom.moveAfter': {
7050
handler: this.moveAfter.bind(this),
7151
},
72-
'dom.getLinkInfo': {
73-
handler: this.getLinkInfo.bind(this),
74-
},
7552
};
7653

7754
//--------------------------------------------------------------------------
@@ -214,48 +191,6 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
214191
fromNode.after(toNode);
215192
}
216193
}
217-
async getSelectedText(params: CommandParams): Promise<string> {
218-
const selectedNode = params.context.range.selectedNodes().map(node => node.clone());
219-
const container = new ContainerNode();
220-
container.append(...selectedNode);
221-
const renderer = this.editor.plugins.get(Renderer);
222-
const renderedNode = await renderer.render<HTMLElement[]>(
223-
HtmlDomRenderingEngine.id,
224-
container,
225-
);
226-
// todo: what if there is more rendered nodes?
227-
return renderedNode ? renderedNode[0].innerText : '';
228-
}
229-
async getSelectedLink(params: CommandParams): Promise<string> {
230-
const selectedNode = params.context.range.selectedNodes().map(node => node.clone());
231-
const nodeWithFormat: InlineNode = selectedNode.find(
232-
node =>
233-
node.is(InlineNode) &&
234-
node.modifiers.find(modifier => modifier instanceof LinkFormat),
235-
) as InlineNode;
236-
const linkFormat: LinkFormat =
237-
nodeWithFormat &&
238-
(nodeWithFormat.modifiers.find(
239-
modifier => modifier instanceof LinkFormat,
240-
) as LinkFormat);
241-
return linkFormat ? linkFormat.url : '';
242-
}
243-
getLinkInfo(params: CommandParams): SelectedLinkInfo {
244-
const targettedNodes = params.context.range.targetedNodes(CharNode);
245-
const text = targettedNodes.map(x => x.char).join('');
246-
//
247-
const inline = this.editor.plugins.get(Inline);
248-
const modifiers = inline.getCurrentModifiers(params.context.range);
249-
return {
250-
text: text,
251-
url: modifiers.get(LinkFormat)?.url,
252-
class: modifiers.get(Attributes)?.get('class'),
253-
target: modifiers
254-
.get(LinkFormat)
255-
?.modifiers?.get(Attributes)
256-
?.get('target'),
257-
} as SelectedLinkInfo;
258-
}
259194

260195
//--------------------------------------------------------------------------
261196
// Private

0 commit comments

Comments
 (0)