Skip to content

Commit 1413287

Browse files
committed
refactor(render): split Render into module and extend constants ♻️
- Remove file-level JSDoc from Types.ts - Add Render module (Attrs, Element, Layout, Main, Style) and barrel index - Expand allowedNodeKeys order, booleanAttrKeys, etc - Normalize brace style in Create.freezeNode and Helper.node else branches - Replace single Render.ts with import from Render/index.ts
1 parent d3d11c3 commit 1413287

File tree

12 files changed

+699
-422
lines changed

12 files changed

+699
-422
lines changed

src/Constant.ts

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
export default class Constant {
66
/** Allowed keys for schema node (validation, helper). */
77
static readonly allowedNodeKeys: Set<string> = new Set<string>([
8-
'type',
9-
'id',
10-
'layout',
11-
'style',
8+
'alt',
129
'attrs',
10+
'children',
1311
'content',
12+
'id',
13+
'layout',
1414
'src',
15-
'alt',
16-
'children'
15+
'style',
16+
'type'
1717
])
1818
/** Allowed keys in node props (no type, children). */
1919
static readonly allowedPropsKeys: Set<string> = new Set(
@@ -23,45 +23,91 @@ export default class Constant {
2323
)
2424
/** Boolean attribute names; presence means true. */
2525
static readonly booleanAttrKeys: Set<string> = new Set<string>([
26+
'autofocus',
2627
'checked',
2728
'disabled',
28-
'readonly',
29-
'selected',
29+
'hidden',
3030
'inert',
31-
'hidden'
31+
'multiple',
32+
'open',
33+
'readonly',
34+
'required',
35+
'selected'
3236
])
3337
/** Container tag names for el.* (non-void). */
3438
static readonly containerTags: readonly string[] = [
35-
'div',
36-
'span',
37-
'main',
38-
'header',
39-
'footer',
40-
'section',
39+
'a',
40+
'abbr',
41+
'address',
4142
'article',
4243
'aside',
43-
'nav',
44-
'p',
44+
'audio',
45+
'blockquote',
46+
'button',
47+
'caption',
48+
'cite',
49+
'code',
50+
'colgroup',
51+
'datalist',
52+
'details',
53+
'dialog',
54+
'div',
55+
'dd',
56+
'del',
57+
'dl',
58+
'dt',
59+
'em',
60+
'fieldset',
61+
'figcaption',
62+
'figure',
63+
'footer',
64+
'form',
4565
'h1',
4666
'h2',
4767
'h3',
4868
'h4',
4969
'h5',
5070
'h6',
51-
'a',
52-
'ul',
53-
'ol',
71+
'header',
72+
'hgroup',
73+
'iframe',
74+
'ins',
75+
'label',
76+
'legend',
5477
'li',
78+
'main',
79+
'mark',
80+
'menu',
81+
'meter',
82+
'nav',
83+
'ol',
84+
'optgroup',
85+
'option',
86+
'output',
87+
'p',
88+
'picture',
89+
'pre',
90+
'progress',
91+
'q',
92+
'section',
93+
'search',
94+
'select',
95+
'slot',
96+
'span',
97+
'strong',
98+
'summary',
5599
'table',
56-
'thead',
57100
'tbody',
58-
'tr',
59-
'th',
60101
'td',
61-
'form',
62-
'label',
63-
'button',
64-
'template'
102+
'template',
103+
'textarea',
104+
'tfoot',
105+
'th',
106+
'thead',
107+
'time',
108+
'tr',
109+
'ul',
110+
'video'
65111
]
66112
/** SVG namespace URI for createElementNS. */
67113
static readonly svgNamespace: string = 'http://www.w3.org/2000/svg'

src/Create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export default class Create {
3939
const frozenChildren = node.children.map((childNode) => Create.freezeNode(childNode))
4040
Object.freeze(frozenChildren)
4141
return Object.freeze({ ...node, children: frozenChildren }) as Readonly<Types.Node>
42+
} else {
43+
return Object.freeze(node) as Readonly<Types.Node>
4244
}
43-
return Object.freeze(node) as Readonly<Types.Node>
4445
}
4546
}

src/Helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ export default class Helper {
108108
const childList = rest.flatMap((item) => {
109109
if (Array.isArray(item)) {
110110
return item
111+
} else {
112+
return [item]
111113
}
112-
return [item]
113114
}) as Types.Node[]
114115
return { type: tag, ...props, children: childList } as Types.Node
115116
}

0 commit comments

Comments
 (0)