ngx-json-render 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/fesm2022/ngx-json-render.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-json-render.d.ts +1 -1
package/README.md
CHANGED
|
@@ -161,7 +161,12 @@ export const catalog = schema.createCatalog({
|
|
|
161
161
|
|
|
162
162
|
```ts
|
|
163
163
|
import { Component } from '@angular/core';
|
|
164
|
-
import {
|
|
164
|
+
import {
|
|
165
|
+
type InferComponentProps,
|
|
166
|
+
JrChildren,
|
|
167
|
+
injectRenderContext,
|
|
168
|
+
} from 'ngx-json-render';
|
|
169
|
+
import type { catalog } from './catalog';
|
|
165
170
|
|
|
166
171
|
@Component({
|
|
167
172
|
selector: 'app-card',
|
|
@@ -174,7 +179,8 @@ import { JrChildren, injectRenderContext } from 'ngx-json-render';
|
|
|
174
179
|
`,
|
|
175
180
|
})
|
|
176
181
|
export class CardComponent {
|
|
177
|
-
readonly ctx =
|
|
182
|
+
readonly ctx =
|
|
183
|
+
injectRenderContext<InferComponentProps<typeof catalog, 'Card'>>();
|
|
178
184
|
}
|
|
179
185
|
|
|
180
186
|
@Component({
|
|
@@ -182,10 +188,13 @@ export class CardComponent {
|
|
|
182
188
|
template: `<button (click)="ctx.emit('press')">{{ ctx.props().label }}</button>`,
|
|
183
189
|
})
|
|
184
190
|
export class ButtonComponent {
|
|
185
|
-
readonly ctx =
|
|
191
|
+
readonly ctx =
|
|
192
|
+
injectRenderContext<InferComponentProps<typeof catalog, 'Button'>>();
|
|
186
193
|
}
|
|
187
194
|
```
|
|
188
195
|
|
|
196
|
+
`InferComponentProps` reads a component's props type off its Zod schema in the catalog, so the component and the catalog cannot drift apart; a hand-written type such as `injectRenderContext<{ label: string }>()` works too. One mismatch to know: a `.default()` field comes out required, but the renderer passes props as the spec wrote them and applies no Zod defaults, so keep such a field optional or fall back in the template.
|
|
197
|
+
|
|
189
198
|
`<jr-children />` renders the element's children where you place it — like a `router-outlet` for the spec tree. Use `<jr-children slot="header" />` for named slots.
|
|
190
199
|
|
|
191
200
|
**3. Build the registry and render:**
|
|
@@ -859,7 +868,7 @@ is how you tell the two apart. One dialog is open at a time: an action with a
|
|
|
859
868
|
`confirm` dispatched while another is waiting cancels the waiting one, so its
|
|
860
869
|
`execute()` rejects the same way.
|
|
861
870
|
|
|
862
|
-
Registry & schema: `defineRegistry`, `createStoreSetState`, `schema
|
|
871
|
+
Registry & schema: `defineRegistry`, `createStoreSetState`, `schema`, and the catalog types `InferComponentProps`, `InferCatalogComponents`, `InferActionParams` (re-exported from core).
|
|
863
872
|
|
|
864
873
|
Testing (`ngx-json-render/testing`): `renderSpec`, `renderComponent`, `recordedTransport`, `specStream`, `usageLine`.
|
|
865
874
|
|