24 lines
2.0 KiB
Markdown
24 lines
2.0 KiB
Markdown
# `dapi node insert <parentId> (<path> | --code <str>) [--index <N>]`
|
|
|
|
Compiles a Solid JSX project module and executes it in the app; the same pipeline as [`mount`](../mount.md), including declared asset generation, but instead of mounting the rendered roots into the document, inserts them as children of an existing entity. Because the result is inserted rather than reconciled, root elements take no `key`: every run inserts fresh entities; there is no replace-or-create matching and nothing is deleted.
|
|
|
|
The full JSX code syntax lives in [jsx/](../jsx/README.md).
|
|
|
|
The rendered roots must be valid as children of the target parent, following the JSX containment rules: a node parent takes any element or paint root except `<scene>` (scenes only exist at the document top level) and `<colorStop>`; a gradient paint parent takes only `<colorStop>` roots. That is how a stop is added to an existing gradient (`node insert <paintId> --code '<colorStop offset={0.5} color="#FF0055" />'`); other sub-entities take no children.
|
|
|
|
## Input
|
|
|
|
- `<parentId>`: entity id of the parent to insert into (required)
|
|
- Project module, exactly one of:
|
|
- `<path>`: path to the module file
|
|
- `--code <str>`: inline module source; the `export default () =>` wrapper is optional, a bare JSX expression is wrapped automatically (e.g. `--code '<rect width={100} height={100} />'`)
|
|
- `-i, --index <N>`: the inserted node's 0-based position among the parent's children, a non-negative integer (optional; default = append after the last child; values past the end are clamped). Node roots only: paints stack in insertion order and color stops render sorted by `offset`, so `--index` is rejected for them.
|
|
|
|
## Output
|
|
|
|
None.
|
|
|
|
## Errors
|
|
|
|
Exits non-zero if `<parentId>` doesn't resolve to a live entity, if compilation or evaluation fails, if a rendered root is invalid as a child of the parent (e.g. a `<scene>`, or a non-`<colorStop>` in a gradient paint), or if `--index` is given for a paint or color stop root. On any of these, **nothing is inserted**.
|