-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.ts
87 lines (81 loc) · 2.22 KB
/
handlers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { handleHtmlElement } from './html-element';
import { handleArrayTag } from './tags/array';
import { handleCallTag } from './tags/call';
import { handleCommentTag } from './tags/comment';
import { handleEventTag } from './tags/event';
import { handleFunctionTag } from './tags/function';
import { handleIfElseTags } from './tags/if-else';
import { handleInjectTag } from './tags/inject';
import { handleObjectTag } from './tags/object';
import { handlePrintTag } from './tags/print';
import { handleRepeatTag } from './tags/repeat';
import { handleSwitchTag } from './tags/switch';
import { handleVarTag } from './tags/var';
interface HandlersMapping {
[key: string]: (element: Element, loopVariable?: string) => string | null;
}
const handlers_mapping: HandlersMapping = {
PRINT: handlePrintTag,
REPEAT: handleRepeatTag,
VAR: handleVarTag,
IF: handleIfElseTags,
FUNCTION: handleFunctionTag,
CALL: handleCallTag,
SWITCH: handleSwitchTag,
OBJECT: handleObjectTag,
ARRAY: handleArrayTag,
COMMENT: handleCommentTag,
EVENT: handleEventTag,
INJECT: handleInjectTag,
};
export function handleElement(
element: Element,
hostElementId?: string
): string | null {
if (isStandardHtmlElement(element)) {
return handleHtmlElement(element, hostElementId);
}
const handlerFunction = handlers_mapping[element.tagName];
return handlerFunction ? handlerFunction(element) : null;
}
export function isStandardHtmlElement(element: Element): boolean {
// List of standard HTML elements we want to support
const standardHtmlElements = [
'input',
'button',
'ul',
'li',
'div',
'span',
'p',
'h1',
'h2',
'h3',
'strong',
'a',
'img',
'form',
'label',
'select',
'option',
'textarea',
'table',
'thead',
'tbody',
'tr',
'th',
'td',
'nav',
'header',
'footer',
'section',
'article',
'aside',
'main',
'figure',
'figcaption',
'audio',
'video',
];
return standardHtmlElements.includes(element.tagName.toLowerCase());
}