Skip to content

Commit 617769c

Browse files
committed
docs
1 parent aa3fa6b commit 617769c

24 files changed

+1818
-518
lines changed

docs-site/src/content/docs/api/createComponent.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To create a Regor component, call the `createComponent` function with the follow
2222

2323
- `options` (optional): An array of strings that defines component properties or an object that allows you to configure various options for the component, such as whether to use interpolation, props, the component's default name, or the component context.
2424
- `context` (optional): A function that defines the Regor context for the component. This function receives a `ComponentHead` object, which you can use to specify the component's behavior and props. It should return the Regor context.
25-
- `head.autoProps`: Automatically assigns properties defined in the `:props` binding to the component context. Defaults to `true`.
25+
- `head.autoProps`: Automatically assigns properties defined in the `:context` binding to the component context. Defaults to `true`.
2626
- `head.entangle`: Keeps refs defined in the component context entangled with `head.props` refs. Defaults to `true`.
2727
- `head.enableSwitch`: Enables slot context switching to the parent. Defaults to `false`.
2828
- `head.onAutoPropsAssigned`: Callback invoked after auto props get assigned to the component context.
@@ -94,3 +94,4 @@ The `createComponent` function returns a component object with the following pro
9494
- [`toJsonTemplate`](/api/toJsonTemplate)
9595

9696
[Back to the API list](/api/)
97+
Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,83 @@
11
---
22
title: Regor API
33
sidebar:
4-
order: 5
4+
order: 6
55
---
66

7-
In this section, you will find a list of Regor's API methods organized by categories. Click on each method to view its detailed documentation.
7+
This section contains the function-level reference for Regor.
88

9-
**App / Component Template Functions:**
9+
Use this page as an index, then open each API page for signature details and examples.
1010

11-
- [`createApp`](/api/createApp)
12-
- [`createComponent`](/api/createComponent)
13-
- [`toFragment`](/api/toFragment)
14-
- [`toJsonTemplate`](/api/toJsonTemplate)
15-
- [`RegorConfig`](/api/regorConfig)
11+
## App and Components
1612

17-
**Cleanup Functions:**
13+
1. [`createApp`](./createApp)
14+
2. [`createComponent`](./createComponent)
15+
3. [`toFragment`](./toFragment)
16+
4. [`toJsonTemplate`](./toJsonTemplate)
17+
5. [`RegorConfig`](./regorConfig)
1818

19-
- [`addUnbinder`](/api/addUnbinder)
20-
- [`getBindData`](/api/getBindData)
21-
- [`removeNode`](/api/removeNode)
22-
- [`unbind`](/api/unbind)
19+
## Reactivity
2320

24-
**Compute Functions:**
21+
1. [`ref`](./ref)
22+
2. [`sref`](./sref)
23+
3. [`isRef`](./isRef)
24+
4. [`isDeepRef`](./isDeepRef)
25+
5. [`unref`](./unref)
26+
6. [`pause`](./pause)
27+
7. [`resume`](./resume)
28+
8. [`trigger`](./trigger)
29+
9. [`entangle`](./entangle)
2530

26-
- [`computed`](/api/computed)
27-
- [`computeRef`](/api/computeRef)
28-
- [`computeMany`](/api/computeMany)
29-
- [`watchEffect`](/api/watchEffect)
30-
- [`collectRefs`](/api/collectRefs)
31-
- [`silence`](/api/silence)
31+
## Computed and Effects
3232

33-
**Misc Functions:**
33+
1. [`computed`](./computed)
34+
2. [`computeRef`](./computeRef)
35+
3. [`computeMany`](./computeMany)
36+
4. [`watchEffect`](./watchEffect)
37+
5. [`collectRefs`](./collectRefs)
38+
6. [`silence`](./silence)
3439

35-
- [`flatten`](/api/flatten)
36-
- [`isRaw`](/api/isRaw)
37-
- [`markRaw`](/api/markRaw)
38-
- [`persist`](/api/persist)
39-
- [`html`](/api/html)
40-
- [`raw`](/api/raw)
40+
## Observation and Batch
4141

42-
**Observe Functions:**
42+
1. [`observe`](./observe)
43+
2. [`observeMany`](./observeMany)
44+
3. [`observerCount`](./observerCount)
45+
4. [`batch`](./batch)
46+
5. [`startBatch`](./startBatch)
47+
6. [`endBatch`](./endBatch)
4348

44-
- [`observe`](/api/observe)
45-
- [`observeMany`](/api/observeMany)
46-
- [`observerCount`](/api/observerCount)
47-
- [`batch`](/api/batch)
48-
- [`startBatch`](/api/startBatch)
49-
- [`endBatch`](/api/endBatch)
49+
## Lifecycle and Scope
5050

51-
**Reactivity Functions:**
51+
1. [`useScope`](./useScope)
52+
2. [`onMounted`](./onMounted)
53+
3. [`onUnmounted`](./onUnmounted)
5254

53-
- [`ref`](/api/ref)
54-
- [`sref`](/api/sref)
55-
- [`isDeepRef`](/api/isDeepRef)
56-
- [`isRef`](/api/isRef)
57-
- [`pause`](/api/pause)
58-
- [`resume`](/api/resume)
59-
- [`trigger`](/api/trigger)
60-
- [`unref`](/api/unref)
61-
- [`entangle`](/api/entangle)
55+
## Cleanup and Unbind
6256

63-
**Composition Functions:**
57+
1. [`addUnbinder`](./addUnbinder)
58+
2. [`getBindData`](./getBindData)
59+
3. [`removeNode`](./removeNode)
60+
4. [`unbind`](./unbind)
6461

65-
- [`useScope`](/api/useScope)
66-
- [`onMounted`](/api/onMounted)
67-
- [`onUnmounted`](/api/onUnmounted)
62+
## Utilities
6863

69-
**Log Configuration:**
64+
1. [`flatten`](./flatten)
65+
2. [`markRaw`](./markRaw)
66+
3. [`isRaw`](./isRaw)
67+
4. [`persist`](./persist)
68+
5. [`html`](./html)
69+
6. [`raw`](./raw)
7070

71-
- [`warningHandler`](/api/warningHandler)
71+
## Logging
7272

73-
Each link will take you to a dedicated documentation page for the respective method, where you can find detailed information, examples, and usage guidelines.
73+
1. [`warningHandler`](./warningHandler)
7474

75-
[Back to the main](/)
75+
## Recommendation
76+
77+
Start with:
78+
79+
1. [`createApp`](./createApp)
80+
2. [`ref`](./ref)
81+
3. [`sref`](./sref)
82+
4. [`computed`](./computed)
83+
5. [`watchEffect`](./watchEffect)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: :context Directive
3+
---
4+
5+
`:context` assigns an object into a component instance context, reactively.
6+
`r-context` is an alias with the same behavior.
7+
8+
Use it when you want to pass multiple values to a component in one place, including fields that are not declared in `props`.
9+
10+
## What it does
11+
12+
```html
13+
<MyComponent :context="{ title: pageTitle, theme: activeTheme }"></MyComponent>
14+
<MyComponent r-context="{ title: pageTitle, theme: activeTheme }"></MyComponent>
15+
```
16+
17+
In the component, `title` and `theme` become available as component context fields (or update existing ref fields when applicable).
18+
When `pageTitle` or `activeTheme` changes, the component values are updated.
19+
20+
## When to use `:context`
21+
22+
Use `:context` for object-style component input.
23+
`r-context` is equivalent and can be used interchangeably.
24+
25+
Use `:prop-name="value"` or `r-bind:prop-name="value"` (same single-prop binding behavior) when the prop is declared in the component `props` list.
26+
27+
Use object-form attribute binding (`r-bind="{...}"` or `:="{...}"`) for normal host attribute fallthrough, not for component context assignment.
28+
29+
## Example
30+
31+
```html
32+
<UserCard
33+
:user-id="selectedUserId"
34+
:context="{ badge: userBadge, canEdit: isAdmin }"
35+
></UserCard>
36+
```
37+
38+
```ts
39+
const UserCard = createComponent('<section>...</section>', {
40+
props: ['userId'],
41+
context: (head) => ({
42+
userId: head.props.userId,
43+
badge: head.props.badge,
44+
canEdit: head.props.canEdit,
45+
}),
46+
})
47+
```
48+
49+
In this example:
50+
51+
- `userId` comes from declared prop binding (`:user-id`)
52+
- `badge` and `canEdit` come from `:context`
53+
54+
[Back to the directives](/directives/)
Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
11
---
22
title: Directives
33
sidebar:
4-
order: 4
4+
order: 5
55
---
66

7-
In Regor, directives are special attributes that start with the "r-" prefix. They allow you to enhance the behavior and appearance of your applications. Below, you'll find a list of supported directives categorized by their functionality.
7+
Directives are Regor’s runtime template control surface.
88

9-
> **Note:** The directive prefix "r-" can be customized using `RegorConfig.getDefault().setDirectives('v-')` to align with a different naming convention, such as Vue's "v-" prefix.
9+
By default, directive names start with `r-`. You can customize the prefix with `RegorConfig`.
1010

11-
**Binding Directives:**
11+
## Core Rules
1212

13-
- [`r-bind`](/directives/r-bind) Binds an element's attribute to a component's data, allowing dynamic updates.
14-
- [`r-model`](/directives/r-model) Enables two-way data binding between form inputs.
15-
- [`r-text`](/directives/r-text) Sets the element's text content to the result of an expression.
16-
- [`r-html`](/directives/r-html) Renders the result of an expression as HTML content within the element.
17-
- [`r-on`](/directives/r-on) Attaches event listeners to the element and invokes specified component methods.
18-
- [`r-show`](/directives/r-show) Conditionally displays the element based on the truthiness of an expression.
13+
1. `r-` directives are explicit full-form syntax.
14+
2. `:` is shorthand for `r-bind`.
15+
3. `@` is shorthand for `r-on`.
16+
4. `.` shorthand binds DOM properties (equivalent to `r-bind.prop`).
1917

20-
**Control Flow Directives:**
18+
## Binding
2119

22-
- [`r-for`](/directives/r-for) Renders a set of elements based on an array and a template.
23-
- [`r-if`](/directives/r-if) Conditionally renders the element based on the truthiness of an expression.
24-
- [`r-else`](/directives/r-if) Provides an alternative rendering when used in conjunction with `r-if`.
25-
- [`r-else-if`](/directives/r-if) Conditionally renders the element as an alternative to `r-if`.
20+
1. [`r-text`](./r-text): text content binding.
21+
2. [`r-html`](./r-html): HTML content binding.
22+
3. [`r-bind`](./r-bind): attributes/properties/object binding.
23+
4. [`r-model`](./r-model): form two-way binding.
24+
5. [`r-on`](./r-on): event binding.
25+
6. [`r-show`](./r-show): conditional visibility.
26+
7. [`:class`](./class): dynamic class binding.
27+
8. [`:style`](./style): dynamic style binding.
2628

27-
**Utility Directives:**
29+
## Control Flow
2830

29-
- [`r-pre`](/directives/r-pre) Excludes HTML element from Regor bindings.
30-
- [`:class`](/directives/class) Binds one or more class names to an element based on expressions.
31-
- [`:style`](/directives/style) Binds one or more inline styles to an element based on expressions.
32-
- [`:ref`](/directives/ref) Provides a reference to an element in the template, allowing you to interact with it programmatically.
33-
- [`:key`](/directives/r-for) Provides a unique identifier for each item in a list, aiding efficient updates and rendering.
34-
- [`:is`](/directives/is) Specifies the component to dynamically render based on a value or expression.
35-
- [`r-teleport`](/directives/r-teleport): Teleports the element to anywhere in the DOM. Unlike Vue, teleport is a directive to avoid component overhead.
36-
- [`:props`](/directives/props) Vue uses `v-bind` for component property passing. However, this can conflict with `v-bind`'s attribute fall-through logic. Hence, Regor defines a dedicated directive to pass properties using object syntax. It enables passing properties without defining them in the component's props contract.
37-
- [`:props-once`](/directives/props-once) Similar to `:props` but it doesn't observe the entire reactive tree of the template expression. Tail reactivity still works.
31+
1. [`r-if`](./r-if), `r-else-if`, `r-else`: conditional branches.
32+
2. [`r-for`](./r-for): list/object iteration with keying support.
3833

39-
**Event Handling Directives:**
34+
## Component and Utility
4035

41-
- [`@`](/directives/r-on) Shorthand for `r-on` to bind event listeners.
36+
1. [`:is`](./is): dynamic component selection.
37+
2. [`:context`](./context): component prop object binding.
38+
3. [`:ref`](./ref): element/component references.
39+
4. [`r-pre`](./r-pre): skip compilation for subtree.
40+
5. [`r-teleport`](./r-teleport): move DOM subtree to another target.
4241

43-
**Attribute Binding Directives:**
42+
## Important Keying Note
4443

45-
- [`:`](/directives/r-bind) Shorthand for `r-bind` to bind element attributes.
46-
- [`.`](/directives/r-bind) Shorthand for `r-bind.prop` to set properties.
44+
In `r-for`, both `key="row.id"` and `:key="row.id"` are expression bindings in Regor templates. Both are supported. Nested paths like `a.b.c.d` are supported.
4745

48-
These directives empower you to create dynamic and interactive user interfaces, enhancing the user experience of your Regor-powered applications. Click on each directive to view its detailed documentation, including examples and usage guidelines.
46+
Use stable keys whenever list identity matters.
4947

50-
[Back to the main](/)
48+
## Recommendation
49+
50+
Read in this order:
51+
52+
1. [`r-bind`](./r-bind)
53+
2. [`r-text`](./r-text)
54+
3. [`r-if`](./r-if)
55+
4. [`r-for`](./r-for)
56+
5. [`r-model`](./r-model)

docs-site/src/content/docs/directives/props-once.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs-site/src/content/docs/directives/props.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)