diff --git a/xmlui/dev-docs/ud-components.md b/xmlui/dev-docs/ud-components.md new file mode 100644 index 000000000..77676eb5e --- /dev/null +++ b/xmlui/dev-docs/ud-components.md @@ -0,0 +1,1326 @@ +# User-Defined Component Architecture + +This document explains XMLUI's user-defined component infrastructure - the rendering mechanisms that enable developers to create reusable components in `.xmlui` files with template composition through slots and children transposition. It covers the architectural foundations, the slot transposition mechanism, the role of ComponentAdapter and supporting components, and implementation details for framework developers working on the XMLUI core. + +## What Are User-Defined Components? + +**User-defined components** are reusable component definitions created by application developers using XMLUI markup in `.xmlui` files. They encapsulate visual structure, behavior, and state management patterns into named components that can be used throughout an application just like framework-provided components. + +A user-defined component is declared with the `` tag and must have a unique name starting with an uppercase letter. The component name must match the filename (e.g., `ActionBar.xmlui` contains ``). Components support properties, events, methods, variables, and slots for template composition. + +**Key Characteristics:** + +- **Declarative Definition** - Components defined entirely in XMLUI markup without requiring JavaScript/TypeScript code +- **Property Passing** - Parent components pass data through properties accessed via `$props` context variable +- **Event Emission** - Components notify parents of state changes through custom events using `emitEvent()` +- **Template Composition** - Slots enable parent components to inject custom markup into predefined component regions +- **Encapsulation** - Components maintain their own state, methods, and internal structure +- **Reusability** - Once defined, components can be used throughout the application like any framework component + +## Architectural Overview + +### Component Rendering Flow + +User-defined components follow a distinct rendering path compared to framework-provided components. The key architectural difference is that user-defined components are **compound components** - they have both a component definition (what the parent sees) and an internal implementation (what renders). + +**High-Level Flow:** + +```mermaid +%%{init: {"block": {"padding": 8}}}%% +block-beta + columns 3 + + A["Parent Component Uses <MyComponent>"] + B["ComponentAdapter receives
component definition"] + C["ComponentRegistry identifies
as compound component"] + + D["CompoundComponent wraps
internal implementation"] + E["Container provides scope
for $props, vars, methods"] + F["Slot components transpose
parent content"] + + block:Final:3 + G["SlotItem renders content
with context variables"] + end +``` + +This architecture enables template composition - parent components provide markup fragments that render within the compound component's layout, with access to data pushed from the compound component through slot properties. + +### The Compound Component Pattern + +User-defined components are implemented as **compound components** - they consist of two interconnected parts: + +1. **Component Interface** - The properties, events, and children the parent component provides +2. **Component Implementation** - The internal markup, state, and logic defined in the `.xmlui` file + +**Example Component Definition:** + +```xmlui + + + + + +

{$props.header}

+