@componentonce/react 0.1.0-beta.0 → 0.1.0-beta.1
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 +55 -9
- package/dist/index.d.ts +30 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/examples/host-bound.tsx +38 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,20 +4,66 @@ React adapter for trusted ComponentOnce modules.
|
|
|
4
4
|
|
|
5
5
|
React is a peer dependency. Dynamically compiled modules must use the host application's actual React and JSX-runtime instances rather than bundling another React copy.
|
|
6
6
|
|
|
7
|
-
## Define
|
|
7
|
+
## Define a component
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```tsx
|
|
10
|
+
import {
|
|
11
|
+
createReactRequirement,
|
|
12
|
+
defineReactComponent,
|
|
13
|
+
} from "@componentonce/react";
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
export const definition = defineReactComponent<
|
|
16
|
+
{ readonly label: string },
|
|
17
|
+
{ readonly format: (value: string) => string },
|
|
18
|
+
{ readonly count: number }
|
|
19
|
+
>({
|
|
20
|
+
manifest: {
|
|
21
|
+
id: "example/counter-label",
|
|
22
|
+
version: "1.0.0",
|
|
23
|
+
requirements: [createReactRequirement("19.3.0")],
|
|
24
|
+
},
|
|
25
|
+
component({ props, context, payload }) {
|
|
26
|
+
return <strong>{context.format(props.label)}: {payload.count}</strong>;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
12
30
|
|
|
13
|
-
|
|
31
|
+
React requirements are intentionally explicit. A dynamic module must not derive its requirement from the runtime host React, because that would let old code silently claim compatibility with a newer runtime.
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
## Bind a host once
|
|
16
34
|
|
|
17
|
-
|
|
35
|
+
For application integrations, `createReactHost<HostContext>()` is the normal ergonomic entry point. It binds only the host context/runtime policy; each component still chooses its own Props and Payload types:
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
```ts
|
|
38
|
+
const components = createReactHost<HostContext>({
|
|
39
|
+
capabilities: [
|
|
40
|
+
{ name: "example-api", version: "2" },
|
|
41
|
+
],
|
|
42
|
+
capabilityCompatibility,
|
|
43
|
+
});
|
|
20
44
|
|
|
21
|
-
|
|
45
|
+
const definition = components.define<Props, Payload>({ ... });
|
|
22
46
|
|
|
23
|
-
|
|
47
|
+
const element = components.render({
|
|
48
|
+
definition,
|
|
49
|
+
props,
|
|
50
|
+
context,
|
|
51
|
+
payload,
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The helper binds application capabilities and compatibility policy once. The actual React capability is supplied automatically from the peer React singleton and cannot be spoofed by a repeated per-render value.
|
|
56
|
+
|
|
57
|
+
The lower-level `defineReactComponent`, `renderReactComponent`, boundary helpers, and `createReactHostHelpers` remain available when a host wants to manage those inputs manually.
|
|
58
|
+
|
|
59
|
+
## Validation boundaries
|
|
60
|
+
|
|
61
|
+
Typed rendering does not revalidate values by default. Raw JSON/editor/storage boundaries can use `validateReactComponentBoundary`, `renderReactComponentBoundary`, or the equivalent methods on a bound host.
|
|
62
|
+
|
|
63
|
+
Props and Payload validators are optional and only run when a boundary or explicit validation request needs them.
|
|
64
|
+
|
|
65
|
+
## Runtime compatibility
|
|
66
|
+
|
|
67
|
+
A component can declare any number of generic requirements. React requirements use the stable capability name `react`.
|
|
68
|
+
|
|
69
|
+
Exact version matching is the core default. A host that intentionally supports a version range can supply a capability compatibility predicate. Sharing the React singleton solves duplicate-React hook problems; capability matching solves API-version compatibility.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ComponentType, type ReactElement } from "react";
|
|
|
2
2
|
import { type ComponentOnceCapability, type ComponentOnceCapabilityCompatibility, type ComponentOnceDefinition, type ComponentOnceManifest, type ComponentOnceRequirement, type ComponentOnceValidator } from "@componentonce/core";
|
|
3
3
|
/** Stable core capability name used for the host React runtime. */
|
|
4
4
|
export declare const REACT_CAPABILITY_NAME = "react";
|
|
5
|
-
/** Create
|
|
5
|
+
/** Create an explicit React runtime requirement recorded in the component manifest. */
|
|
6
6
|
export declare function createReactRequirement(version: string): ComponentOnceRequirement;
|
|
7
7
|
/** Props passed to one trusted React implementation by its host. */
|
|
8
8
|
export interface ComponentOnceReactRenderInput<TProps, THostContext, TPayload> {
|
|
@@ -69,6 +69,28 @@ export interface ComponentOnceReactHostHelpers<THostContext, TPayload> {
|
|
|
69
69
|
/** Validate and render values received from an untyped boundary. */
|
|
70
70
|
renderBoundary<TProps>(input: ComponentOnceReactBoundaryRenderInput<TProps, THostContext, TPayload>): ReactElement;
|
|
71
71
|
}
|
|
72
|
+
/** Host-wide runtime policy bound once by createReactHost. */
|
|
73
|
+
export interface ComponentOnceReactHostOptions {
|
|
74
|
+
/** Additional application/runtime capabilities; the actual peer React version is added automatically. */
|
|
75
|
+
readonly capabilities?: readonly ComponentOnceCapability[];
|
|
76
|
+
/** Optional compatibility rule shared by every render from this host helper. */
|
|
77
|
+
readonly capabilityCompatibility?: ComponentOnceCapabilityCompatibility;
|
|
78
|
+
}
|
|
79
|
+
/** Render input for a host whose capability policy has already been bound. */
|
|
80
|
+
export type ComponentOnceBoundReactRendererInput<TProps, THostContext, TPayload> = Omit<ComponentOnceReactRendererInput<TProps, THostContext, TPayload>, "hostCapabilities" | "capabilityCompatibility">;
|
|
81
|
+
/** Boundary render input for a host whose capability policy has already been bound. */
|
|
82
|
+
export type ComponentOnceBoundReactBoundaryRenderInput<TProps, THostContext, TPayload> = Omit<ComponentOnceReactBoundaryRenderInput<TProps, THostContext, TPayload>, "hostCapabilities" | "capabilityCompatibility">;
|
|
83
|
+
/** Concise React host facade with application types and runtime compatibility policy fixed once. */
|
|
84
|
+
export interface ComponentOnceReactHost<THostContext> {
|
|
85
|
+
/** Define a component while choosing its own persisted Props and per-render Payload types. */
|
|
86
|
+
define<TProps, TPayload>(input: DefineReactComponentInput<TProps, THostContext, TPayload>): ComponentOnceReactDefinition<TProps, THostContext, TPayload>;
|
|
87
|
+
/** Render typed values using the host-wide capability policy. */
|
|
88
|
+
render<TProps, TPayload>(input: ComponentOnceBoundReactRendererInput<TProps, THostContext, TPayload>): ReactElement;
|
|
89
|
+
/** Validate unknown props/payload without changing the trusted host context. */
|
|
90
|
+
validateBoundary<TProps, TPayload>(definition: ComponentOnceReactDefinition<TProps, THostContext, TPayload>, input: ComponentOnceReactBoundaryInput<THostContext>): ComponentOnceReactRenderInput<TProps, THostContext, TPayload>;
|
|
91
|
+
/** Validate and render unknown boundary values using the host-wide capability policy. */
|
|
92
|
+
renderBoundary<TProps, TPayload>(input: ComponentOnceBoundReactBoundaryRenderInput<TProps, THostContext, TPayload>): ReactElement;
|
|
93
|
+
}
|
|
72
94
|
/** Define one typed React component without teaching core anything about React. */
|
|
73
95
|
export declare function defineReactComponent<TProps, THostContext, TPayload>(input: DefineReactComponentInput<TProps, THostContext, TPayload>): ComponentOnceReactDefinition<TProps, THostContext, TPayload>;
|
|
74
96
|
/** Render an exact React definition, with optional validation requested by the host. */
|
|
@@ -79,4 +101,11 @@ export declare function validateReactComponentBoundary<TProps, THostContext, TPa
|
|
|
79
101
|
export declare function renderReactComponentBoundary<TProps, THostContext, TPayload>(input: ComponentOnceReactBoundaryRenderInput<TProps, THostContext, TPayload>): ReactElement;
|
|
80
102
|
/** Create concise definition and rendering helpers pinned to one host's own types. */
|
|
81
103
|
export declare function createReactHostHelpers<THostContext, TPayload>(): ComponentOnceReactHostHelpers<THostContext, TPayload>;
|
|
104
|
+
/**
|
|
105
|
+
* Create the normal application-facing React facade.
|
|
106
|
+
*
|
|
107
|
+
* The React capability comes from this package's peer React singleton, so callers only provide
|
|
108
|
+
* additional host capabilities once instead of repeating them on every render.
|
|
109
|
+
*/
|
|
110
|
+
export declare function createReactHost<THostContext>(options?: ComponentOnceReactHostOptions): ComponentOnceReactHost<THostContext>;
|
|
82
111
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AACtG,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,oCAAoC,EACzC,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,mEAAmE;AACnE,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAE7C,uFAAuF;AACvF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB,CAEhF;AAED,oEAAoE;AACpE,MAAM,WAAW,6BAA6B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ;IAC3E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC5B;AAED,gEAAgE;AAChE,MAAM,MAAM,2BAA2B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,IACpE,aAAa,CAAC,6BAA6B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE/E,yEAAyE;AACzE,MAAM,MAAM,4BAA4B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,IACrE,uBAAuB,CACrB,2BAA2B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,EAC3D,MAAM,EACN,YAAY,EACZ,QAAQ,CACT,CAAC;AAEJ,sDAAsD;AACtD,MAAM,WAAW,yBAAyB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ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AE,0CAA0C,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,GAChF,YAAY,CAAC;CACjB;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EACjE,KAAK,EAAE,yBAAyB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,GAC/D,4BAA4B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAO9D;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EACjE,KAAK,EAAE,+BAA+B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,GACrE,YAAY,CAmBd;AAED,kEAAkE;AAClE,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAC3E,UAAU,EAAE,4BAA4B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,EACxE,KAAK,EAAE,+BAA+B,CAAC,YAAY,CAAC,GACnD,6BAA6B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAM/D;AAED,mFAAmF;AACnF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EACzE,KAAK,EAAE,qCAAqC,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,GAC3E,YAAY,CAYd;AAED,sFAAsF;AACtF,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,QAAQ,KAAK,6BAA6B,CAC7F,YAAY,EACZ,QAAQ,CACT,CAcA;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAC1C,OAAO,GAAE,6BAAkC,GAC1C,sBAAsB,CAAC,YAAY,CAAC,CA4BtC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
1
|
+
import { createElement, version as reactVersion } from "react";
|
|
2
2
|
import { assertComponentOnceCompatible, } from "@componentonce/core";
|
|
3
3
|
/** Stable core capability name used for the host React runtime. */
|
|
4
4
|
export const REACT_CAPABILITY_NAME = "react";
|
|
5
|
-
/** Create
|
|
5
|
+
/** Create an explicit React runtime requirement recorded in the component manifest. */
|
|
6
6
|
export function createReactRequirement(version) {
|
|
7
7
|
return { name: REACT_CAPABILITY_NAME, version };
|
|
8
8
|
}
|
|
@@ -28,7 +28,7 @@ export function defineReactComponent(input) {
|
|
|
28
28
|
}
|
|
29
29
|
/** Render an exact React definition, with optional validation requested by the host. */
|
|
30
30
|
export function renderReactComponent(input) {
|
|
31
|
-
assertComponentOnceCompatible(input.definition.manifest, input.hostCapabilities
|
|
31
|
+
assertComponentOnceCompatible(input.definition.manifest, withReactCapability(input.hostCapabilities), input.capabilityCompatibility);
|
|
32
32
|
const validation = normalizeValidation(input.validation);
|
|
33
33
|
const props = validation.props
|
|
34
34
|
? validateField(input.definition, "props", input.props)
|
|
@@ -73,6 +73,34 @@ export function createReactHostHelpers() {
|
|
|
73
73
|
renderBoundary: (input) => renderReactComponentBoundary(input),
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Create the normal application-facing React facade.
|
|
78
|
+
*
|
|
79
|
+
* The React capability comes from this package's peer React singleton, so callers only provide
|
|
80
|
+
* additional host capabilities once instead of repeating them on every render.
|
|
81
|
+
*/
|
|
82
|
+
export function createReactHost(options = {}) {
|
|
83
|
+
const hostCapabilities = options.capabilities;
|
|
84
|
+
const capabilityCompatibility = options.capabilityCompatibility;
|
|
85
|
+
return {
|
|
86
|
+
define: (input) => defineReactComponent(input),
|
|
87
|
+
render: (input) => renderReactComponent({
|
|
88
|
+
...input,
|
|
89
|
+
...(hostCapabilities === undefined ? {} : { hostCapabilities }),
|
|
90
|
+
...(capabilityCompatibility === undefined ? {} : { capabilityCompatibility }),
|
|
91
|
+
}),
|
|
92
|
+
validateBoundary: (definition, input) => validateReactComponentBoundary(definition, input),
|
|
93
|
+
renderBoundary: (input) => renderReactComponentBoundary({
|
|
94
|
+
...input,
|
|
95
|
+
...(hostCapabilities === undefined ? {} : { hostCapabilities }),
|
|
96
|
+
...(capabilityCompatibility === undefined ? {} : { capabilityCompatibility }),
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function withReactCapability(available) {
|
|
101
|
+
const extra = (available ?? []).filter((capability) => capability.name !== REACT_CAPABILITY_NAME);
|
|
102
|
+
return [{ name: REACT_CAPABILITY_NAME, version: reactVersion }, ...extra];
|
|
103
|
+
}
|
|
76
104
|
function normalizeValidation(validation) {
|
|
77
105
|
if (validation === true)
|
|
78
106
|
return { props: true, payload: true };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAyC,MAAM,OAAO,CAAC;AACtG,OAAO,EACL,6BAA6B,GAO9B,MAAM,qBAAqB,CAAC;AAE7B,mEAAmE;AACnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAE7C,uFAAuF;AACvF,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,OAAO,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,CAAC;AAClD,CAAC;AAoED,4FAA4F;AAC5F,MAAM,OAAO,uCAAwC,SAAQ,KAAK;IAChD,KAAK,CAAoC;IACzC,QAAQ,CAAwB;IAEhD,YACE,KAAwC,EACxC,QAA+B;QAE/B,KAAK,CACH,cAAc,QAAQ,CAAC,EAAE,cAAc,QAAQ,CAAC,OAAO,YAAY,KAAK,aAAa,CACtF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,GAAG,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AAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;IAClG,OAAO,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,mBAAmB,CAC1B,UAAqE;IAErE,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QACrD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO;QACL,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,KAAK;QAChC,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,KAAK;KACrC,CAAC;AACJ,CAAC;AAYD,SAAS,aAAa,CACpB,UAAwE,EACxE,KAAwC,EACxC,KAAc;IAEd,MAAM,SAAS,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;IAC5F,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,uCAAuC,CAAC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createReactHost, createReactRequirement } from "@componentonce/react";
|
|
2
|
+
|
|
3
|
+
interface HostContext {
|
|
4
|
+
readonly format: (value: string) => string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface Payload {
|
|
8
|
+
readonly recordId: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Application integrations bind their context/payload types and runtime capabilities once.
|
|
13
|
+
* Individual components only choose their own persisted Props type.
|
|
14
|
+
*/
|
|
15
|
+
export const components = createReactHost<HostContext>({
|
|
16
|
+
capabilities: [{ name: "example-api", version: "1" }],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const card = components.define<{ readonly title: string }, Payload>({
|
|
20
|
+
manifest: {
|
|
21
|
+
id: "example/host-bound-card",
|
|
22
|
+
version: "1.0.0",
|
|
23
|
+
requirements: [
|
|
24
|
+
createReactRequirement("19.3.0"),
|
|
25
|
+
{ name: "example-api", version: "1" },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
component({ props, context, payload }) {
|
|
29
|
+
return <article data-record={payload.recordId}>{context.format(props.title)}</article>;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const element = components.render({
|
|
34
|
+
definition: card,
|
|
35
|
+
props: { title: "Status" },
|
|
36
|
+
context: { format: (value) => value.toUpperCase() },
|
|
37
|
+
payload: { recordId: 42 },
|
|
38
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@componentonce/react",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@componentonce/core": "0.1.0-beta.
|
|
17
|
+
"@componentonce/core": "0.1.0-beta.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": ">=18"
|