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 el helper and type namespace 🍷
- Add API table row and section Helper (el) with example and el.root, el.node, tag aliases
- Document default export as callable with create, render, el and Types namespace import
- Add Schema2UIDefaultExport to type reference and update tests list
|[`create(definition)`](#createdefinition)|`Schema`| Validate and freeze definition; return schema. |
48
+
|[`render(schema, container)`](#renderschema-container)|`void`| Build DOM from schema and append to container. |
49
+
|`el`| namespace | Helper: `el.root`, `el.node`, `el.div`, etc. |
48
50
49
-
Named exports: `create`, `render`, and all types from `Types` (re-exported). Default export: `{ create, render }`.
51
+
Named exports: `create`, `render`, `el`, and `Types` (re-exported). Default export: callable; calling it returns `{ create, render, el }`, and the callable itself has `.create`, `.render`, `.el` for direct use (e.g. `import Schema2UI from '@neabyte/schema2ui'` then `Schema2UI().create(...)` or `Schema2UI.create(...)`).
52
+
53
+
## Helper (el)
54
+
55
+
Use the `el` namespace to build definitions with less boilerplate. Same flow: `create(el.root(...))` → schema → `render(schema, container)`.
56
+
57
+
```typescript
58
+
// 1. Import create, render, and the el helper
59
+
import { create, render, el } from'@neabyte/schema2ui'
60
+
61
+
// 2. Build definition with el.root(...), pass to create() to get frozen schema (tag aliases: el.header, el.main, el.h1, el.a)
-**`el.root()`** — returns `Definition` with empty `root: []`. **`el.root(n1, n2, ...)`** or **`el.root([n1, n2])`** — returns `Definition` for `create()`.
77
+
-**`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.
78
+
-**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.
50
79
51
80
## Node Shape
52
81
@@ -98,16 +127,17 @@ Build DOM from `schema.root` and append each resulting node into `container`. Us
98
127
99
128
## Type Reference
100
129
101
-
Types are re-exported from the package: `import type { Attrs, Definition, Layout, Node, Schema, Style } from '@neabyte/schema2ui'`.
130
+
Types are re-exported under the `Types` namespace: `import type * as Types from '@neabyte/schema2ui'` then use `Types.Node`, `Types.Schema`, `Types.Attrs`, etc.
102
131
103
132
-**Definition:**`{ root: readonly Node[] }` — Input to `create`.
-**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`, `checked`, `disabled` on form elements.
138
+
-**Schema2UIDefault:**`{ create, render }` — shape returned when calling the default export. **Schema2UIDefaultExport:** callable with `.create`, `.render`, `.el`; calling it returns `Schema2UIDefault & { el: El }`.
109
139
110
140
## Reference
111
141
112
142
-[README](README.md) — Installation and quick start.
113
-
- Tests under `tests/` — Create, Constant, Validator, Render.
0 commit comments