You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(usage): document new attrs, boolean attrs, and API behavior ⛵
- Extend Form Elements with required and multiple
- Add Image and Links (anchor) sections (loading, decoding, download)
- Extend tag aliases list and Accessibility (popover, dialog)
- Add event-handler skip note (on* not applied; use addEventListener) in attrs and Security
- Update Attrs and Schema2UIDefault/Export descriptions in API Reference
-**`el.root()`** — returns `Definition` with empty `root: []`. **`el.root(n1, n2, ...)`** or **`el.root([n1, n2])`** — returns `Definition` for `create()`.
82
82
-**`el.node(type, propsOrContent?, ...rest)`** — generic factory (e.g. custom elements). Second arg: optional props object, text content, or first child; `rest`: more children or content. Content (string) and children cannot be mixed. Void tags must not have content or children.
83
-
-**Tag aliases** — `el.div`, `el.span`, `el.main`, `el.header`, `el.h1`, `el.a`, `el.table`, `el.img`, `el.template`, etc. (container + void from `Constant.tagAliases`). Container tags accept props, content (string), or children (nodes). Void tags (img, br, input, …) accept props only.
|`layout`|`Layout`| no | Width, height, position, flex, gap → CSS. |
94
94
|`style`|`Style`| no | Fill, stroke, font, border → CSS. |
95
-
|`attrs`|`Attrs`| no |Arbitrary HTML attributes (href, class, etc.). |
95
+
|`attrs`|`Attrs`| no | HTML attributes (href, class, etc.). Keys starting with `on` are not applied; use `addEventListener` after render.|
96
96
|`content`|`string`| no | Text content for the node. |
97
97
|`src`|`string`| no | Image (or similar) source URL; use with `type: 'img'`. |
98
98
|`alt`|`string`| no | Alt text for img. |
@@ -115,25 +115,41 @@ Allowed keys are exactly the above. Extra keys cause validation to throw.
115
115
## Security
116
116
117
117
-**Text content** — `content` is applied via `createTextNode()`, so it is safe from HTML injection. Do not interpret `content` as HTML.
118
-
-**Attributes** — `attrs` values are set with `setAttribute()` or property assignment. Do not pass unsanitized user input into `attrs` (e.g. `href`, `src`) without validation or sanitization. For strict policies, consider [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) where supported.
118
+
-**Attributes** — `attrs` values are set with `setAttribute()` or property assignment. Use only attribute names and values from trusted sources, or sanitize them. Do not pass unsanitized user input into `attrs` (e.g. `href`, `src`) without validation or sanitization. For strict policies, consider [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) where supported.
119
+
-**Event handlers** — Attribute keys that start with `on` (e.g. `onclick`, `onerror`) are **skipped** during render and are never set on the element. Use `addEventListener()` on the rendered element instead.
119
120
120
121
## Boolean Attributes
121
122
122
-
These attributes are treated as boolean (MDN: presence = true, absence = false): `checked`, `disabled`, `readonly`, `selected`, `inert`, `hidden`. Use `true` or `false` (or string `'true'`/`'false'`). When the value is false, the attribute is removed from the DOM and the corresponding property is set to false; when true, only the property is set (no attribute string is written). This avoids invalid markup such as `disabled="false"` (which would still disable the element).
123
+
These attributes are treated as boolean (MDN: presence = true, absence = false): `autofocus`, `checked`, `disabled`, `hidden`, `inert`, `multiple`, `open`, `readonly`, `required`, `selected`. Use `true` or `false` (or string `'true'`/`'false'`). When the value is false, the attribute is removed from the DOM and the corresponding property is set to false; when true, only the property is set (no attribute string is written). This avoids invalid markup such as `disabled="false"` (which would still disable the element).
-**autofocus** — On `input`, `button`, `select`, and `textarea` the `autofocus` property is set; on other elements the attribute is set/removed. For accessibility, use sparingly: at most one autofocus control per view, and avoid moving focus away from user context (e.g. modals).
133
+
-**open** — On `details` and `dialog` the `open` property is set (disclosure expanded or dialog visible); when false the attribute is removed.
134
+
-**hidden** — For the value `'until-found'`, the attribute is set as-is (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden)); otherwise treated as boolean (presence = hidden, removed when false).
135
+
130
136
## Form Elements
131
137
132
138
-**disabled** — Applied via property on `input`, `button`, `select`, `textarea`, `fieldset`, `optgroup`, and `option`. Boolean handling as above.
133
139
-**readonly** — Applied via `readOnly` property on `input` and `textarea`.
140
+
-**required** — Applied via `required` property on `input`, `select`, and `textarea`.
141
+
-**multiple** — Applied via `multiple` property on `input` (e.g. file, email) and `select`.
134
142
-**selected** — Applied via `selected` property on `option`.
135
143
-**checked** — Applied via `checked` property on `input` (e.g. checkbox/radio).
136
144
145
+
## Image
146
+
147
+
For `type: 'img'`, `node.src` and `node.alt` are set on the element; `attrs.loading` (`'lazy'` or `'eager'`) and `attrs.decoding` (`'sync'`, `'async'`, or `'auto'`) are applied as properties for lazy loading and decode behavior.
148
+
149
+
## Links (anchor)
150
+
151
+
For `type: 'a'`, `attrs.download` is applied as the anchor’s `download` property: use `true` for “download with default filename” (empty string) or a string for the suggested filename (e.g. `'report.pdf'`). When `download` is false or omitted, the attribute is removed so the link behaves as a normal navigation link.
152
+
137
153
## SVG Attributes
138
154
139
155
Layout and style from the schema are applied only to HTML elements. For SVG nodes (e.g. `circle`, `rect`, `path` under `svg`), set dimensions and appearance via `attrs` (e.g. `attrs.fill`, `attrs.stroke`, `attrs.width`, `attrs.height`, or `attrs.viewBox` on `svg`). Use `attrs.style` for a CSS string if needed.
@@ -143,6 +159,8 @@ Layout and style from the schema are applied only to HTML elements. For SVG node
143
159
- Prefer **semantic HTML** (`type: 'header'`, `main`, `nav`, `button`, etc.) so built-in roles and behavior are available.
144
160
-**ARIA** — Pass ARIA attributes through `attrs` (e.g. `attrs['aria-label']`, `attrs['aria-live']`, `attrs['aria-hidden']`). For dynamic content that updates without a full re-render, consider `aria-live` regions so assistive technologies can announce changes.
145
161
-**inert** and **hidden** — Supported as boolean attributes (see [Boolean Attributes](#boolean-attributes)) for visibility and focus behavior.
162
+
-**popover** — Use `attrs.popover` with values such as `'auto'`, `'manual'`, or `'hint'` (HTML Popover API). Open/close behavior is controlled by the browser or by your script after render.
163
+
-**dialog** — For `type: 'dialog'`, the element is only created and appended; call `element.showModal()` or `element.close()` after render if you need to open or close it programmatically.
146
164
147
165
## API Reference
148
166
@@ -171,8 +189,9 @@ Types are re-exported under the `Types` namespace: `import type * as Types from
171
189
-**Node:** Object with `type` (string) and optional `id`, `layout`, `style`, `attrs`, `content`, `src`, `alt`, `children` (readonly array of Node). Void tags must not have `children`.
-**Attrs:**`Record<string, string | number | boolean>` — HTML attributes. Special handling for `class`/`className`, `style` (string), `value`, and boolean attributes (`checked`, `disabled`, `readonly`, `selected`, `inert`, `hidden`) on the relevant elements.
175
-
-**Schema2UIDefault:**`{ create, render }` — shape returned when calling the default export. **Schema2UIDefaultExport:** callable with `.create`, `.render`, `.el`; calling it returns `Schema2UIDefault & { el: El }`.
192
+
-**Attrs:**`Record<string, string | number | boolean>` — HTML attributes. Keys starting with `on` are skipped (event handlers are not applied). Special handling for `class`/`className`, `style` (string), `value`, boolean attributes (`autofocus`, `checked`, `disabled`, `hidden`, `inert`, `multiple`, `open`, `readonly`, `required`, `selected`), img `loading`/`decoding`, and anchor `download` on the relevant elements.
193
+
-**Schema2UIDefault:**`{ create, render }` — base API shape. Calling the default export returns this plus `el` (i.e. `{ create, render, el }`).
194
+
-**Schema2UIDefaultExport:** the default export (callable); has `.create`, `.render`, `.el`; calling it returns `{ create, render, el }`.
0 commit comments