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

Commit db7e798

Browse files
Zyntondmo-odoo
authored andcommitted
[REF] Link, Input: remove getters to special attributes
1 parent a2408b6 commit db7e798

File tree

6 files changed

+40
-46
lines changed

6 files changed

+40
-46
lines changed

packages/plugin-inline/src/Format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Format extends Modifier {
3131
// Public
3232
//--------------------------------------------------------------------------
3333

34-
render(): Node {
34+
render(): Element {
3535
const node = document.createElement(this.htmlTag);
3636
const attributes = this.modifiers.find(Attributes);
3737
if (attributes) {

packages/plugin-input/src/InputHtmlDomRenderer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export class InputHtmlDomRenderer extends AbstractRenderer<Node[]> {
1717
if (attributes) {
1818
this.engine.renderAttributes(Attributes, node, input);
1919
}
20+
if (node.inputType) {
21+
input.setAttribute('type', node.inputType);
22+
}
23+
if (node.inputName) {
24+
input.setAttribute('name', node.inputName);
25+
}
2026
input.value = node.value;
2127
return [input];
2228
}
Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
11
import { VElement } from '../../core/src/VNodes/VElement';
2-
import { Attributes } from '../../plugin-xml/src/Attributes';
32

43
export class InputNode extends VElement {
54
value: string;
6-
constructor(type?: string, name?: string, value?: string) {
5+
inputName: string;
6+
inputType: string;
7+
constructor(params: { type?: string; name?: string; value?: string } = {}) {
78
super({ htmlTag: 'INPUT' });
8-
this.inputName = name;
9-
this.inputType = type;
10-
this.value = value;
11-
}
12-
13-
//--------------------------------------------------------------------------
14-
// Public
15-
//--------------------------------------------------------------------------
16-
17-
/**
18-
* Return the `name` attribute of this Input node.
19-
*/
20-
get inputName(): string {
21-
return this.modifiers.find(Attributes)?.get('name') as string;
22-
}
23-
/**
24-
* Set the `name` attribute of this Input node.
25-
*/
26-
set inputName(name: string) {
27-
this.modifiers.find(Attributes)?.set('name', name);
28-
}
29-
/**
30-
* Return the `type` attribute of this Input node.
31-
*/
32-
get inputType(): string {
33-
return this.modifiers.find(Attributes)?.get('type') as string;
34-
}
35-
/**
36-
* Set the `type` attribute of this Input node.
37-
*/
38-
set inputType(name: string) {
39-
this.modifiers.find(Attributes)?.set('type', name);
9+
this.inputName = params.name;
10+
this.inputType = params.type;
11+
this.value = params.value;
4012
}
4113
}

packages/plugin-input/src/InputXmlDomParser.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AbstractParser } from '../../plugin-parser/src/AbstractParser';
22
import { XmlDomParsingEngine } from '../../plugin-xml/src/XmlDomParsingEngine';
33
import { InputNode } from './InputNode';
44
import { nodeName } from '../../utils/src/utils';
5+
import { Attributes } from '../../plugin-xml/src/Attributes';
56

67
export class InputXmlDomParser extends AbstractParser<Node> {
78
static id = XmlDomParsingEngine.id;
@@ -12,9 +13,17 @@ export class InputXmlDomParser extends AbstractParser<Node> {
1213
};
1314

1415
async parse(item: HTMLInputElement): Promise<InputNode[]> {
15-
const input = new InputNode();
16+
const input = new InputNode({
17+
type: item.getAttribute('type'),
18+
name: item.getAttribute('name'),
19+
value: item.value,
20+
});
1621
input.modifiers.append(this.engine.parseAttributes(item));
17-
input.value = item.value;
22+
const attributes = input.modifiers.find(Attributes);
23+
if (attributes) {
24+
attributes.remove('type'); // type is on input.inputType
25+
attributes.remove('name'); // type is on input.inputName
26+
}
1827
const nodes = await this.engine.parse(...item.childNodes);
1928
input.append(...nodes);
2029
return [input];
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { Format } from '../../plugin-inline/src/Format';
2-
import { Attributes } from '../../plugin-xml/src/Attributes';
32

43
export class LinkFormat extends Format {
5-
constructor(url?: string) {
4+
constructor(public url = '#') {
65
super('A');
7-
this.url = url;
86
}
9-
get url(): string {
10-
return this.modifiers.find(Attributes)?.get('href');
11-
}
12-
set url(url: string) {
13-
this.modifiers.get(Attributes).set('href', url);
7+
8+
//--------------------------------------------------------------------------
9+
// Public
10+
//--------------------------------------------------------------------------
11+
12+
/**
13+
* @override
14+
*/
15+
render(): Element {
16+
const element = super.render();
17+
element.setAttribute('href', this.url);
18+
return element;
1419
}
1520
}

packages/plugin-link/src/LinkXmlDomParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { XmlDomParsingEngine } from '../../plugin-xml/src/XmlDomParsingEngine';
33
import { VNode } from '../../core/src/VNodes/VNode';
44
import { LinkFormat } from './LinkFormat';
55
import { nodeName } from '../../utils/src/utils';
6+
import { Attributes } from '../../plugin-xml/src/Attributes';
67

78
export class LinkXmlDomParser extends FormatParser {
89
static id = XmlDomParsingEngine.id;
@@ -13,8 +14,9 @@ export class LinkXmlDomParser extends FormatParser {
1314
};
1415

1516
async parse(item: Element): Promise<VNode[]> {
16-
const link = new LinkFormat();
17+
const link = new LinkFormat(item.getAttribute('href'));
1718
link.modifiers.append(this.engine.parseAttributes(item));
19+
link.modifiers.find(Attributes)?.remove('href'); // href is on link.url
1820
const children = await this.engine.parse(...item.childNodes);
1921
this.applyFormat(link, children);
2022

0 commit comments

Comments
 (0)