@creact-labs/creact 0.1.7 → 0.2.0
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 +72 -21
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +88 -0
- package/dist/index.d.ts +19 -44
- package/dist/index.js +20 -68
- package/dist/jsx/index.d.ts +2 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +4 -0
- package/dist/jsx/jsx-runtime.d.ts +38 -0
- package/dist/jsx/jsx-runtime.js +38 -0
- package/dist/jsx/types.d.ts +12 -0
- package/dist/jsx/types.js +4 -0
- package/dist/primitives/context.d.ts +34 -0
- package/dist/primitives/context.js +63 -0
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.js +3 -0
- package/dist/primitives/instance.d.ts +72 -0
- package/dist/primitives/instance.js +235 -0
- package/dist/primitives/store.d.ts +22 -0
- package/dist/primitives/store.js +97 -0
- package/dist/provider/backend.d.ts +110 -0
- package/dist/provider/backend.js +37 -0
- package/dist/provider/interface.d.ts +48 -0
- package/dist/provider/interface.js +39 -0
- package/dist/reactive/effect.d.ts +11 -0
- package/dist/reactive/effect.js +42 -0
- package/dist/reactive/index.d.ts +3 -0
- package/dist/reactive/index.js +3 -0
- package/dist/reactive/signal.d.ts +32 -0
- package/dist/reactive/signal.js +60 -0
- package/dist/reactive/tracking.d.ts +41 -0
- package/dist/reactive/tracking.js +161 -0
- package/dist/runtime/fiber.d.ts +21 -0
- package/dist/runtime/fiber.js +16 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/reconcile.d.ts +66 -0
- package/dist/runtime/reconcile.js +210 -0
- package/dist/runtime/render.d.ts +42 -0
- package/dist/runtime/render.js +231 -0
- package/dist/runtime/run.d.ts +119 -0
- package/dist/runtime/run.js +334 -0
- package/dist/runtime/state-machine.d.ts +95 -0
- package/dist/runtime/state-machine.js +209 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +4 -0
- package/package.json +11 -27
- package/dist/cli/commands/BuildCommand.d.ts +0 -40
- package/dist/cli/commands/BuildCommand.js +0 -151
- package/dist/cli/commands/DeployCommand.d.ts +0 -38
- package/dist/cli/commands/DeployCommand.js +0 -194
- package/dist/cli/commands/DevCommand.d.ts +0 -52
- package/dist/cli/commands/DevCommand.js +0 -394
- package/dist/cli/commands/PlanCommand.d.ts +0 -39
- package/dist/cli/commands/PlanCommand.js +0 -164
- package/dist/cli/commands/index.d.ts +0 -36
- package/dist/cli/commands/index.js +0 -43
- package/dist/cli/core/ArgumentParser.d.ts +0 -46
- package/dist/cli/core/ArgumentParser.js +0 -127
- package/dist/cli/core/BaseCommand.d.ts +0 -75
- package/dist/cli/core/BaseCommand.js +0 -95
- package/dist/cli/core/CLIContext.d.ts +0 -68
- package/dist/cli/core/CLIContext.js +0 -183
- package/dist/cli/core/CommandRegistry.d.ts +0 -64
- package/dist/cli/core/CommandRegistry.js +0 -89
- package/dist/cli/core/index.d.ts +0 -36
- package/dist/cli/core/index.js +0 -43
- package/dist/cli/index.d.ts +0 -35
- package/dist/cli/index.js +0 -100
- package/dist/cli/output.d.ts +0 -204
- package/dist/cli/output.js +0 -437
- package/dist/cli/utils.d.ts +0 -59
- package/dist/cli/utils.js +0 -76
- package/dist/context/createContext.d.ts +0 -90
- package/dist/context/createContext.js +0 -113
- package/dist/context/index.d.ts +0 -30
- package/dist/context/index.js +0 -35
- package/dist/core/CReact.d.ts +0 -409
- package/dist/core/CReact.js +0 -1151
- package/dist/core/CloudDOMBuilder.d.ts +0 -447
- package/dist/core/CloudDOMBuilder.js +0 -1234
- package/dist/core/ContextDependencyTracker.d.ts +0 -165
- package/dist/core/ContextDependencyTracker.js +0 -448
- package/dist/core/ErrorRecoveryManager.d.ts +0 -145
- package/dist/core/ErrorRecoveryManager.js +0 -443
- package/dist/core/EventBus.d.ts +0 -91
- package/dist/core/EventBus.js +0 -185
- package/dist/core/ProviderOutputTracker.d.ts +0 -211
- package/dist/core/ProviderOutputTracker.js +0 -476
- package/dist/core/ReactiveUpdateQueue.d.ts +0 -76
- package/dist/core/ReactiveUpdateQueue.js +0 -121
- package/dist/core/Reconciler.d.ts +0 -415
- package/dist/core/Reconciler.js +0 -1044
- package/dist/core/RenderScheduler.d.ts +0 -153
- package/dist/core/RenderScheduler.js +0 -519
- package/dist/core/Renderer.d.ts +0 -336
- package/dist/core/Renderer.js +0 -944
- package/dist/core/Runtime.d.ts +0 -246
- package/dist/core/Runtime.js +0 -640
- package/dist/core/StateBindingManager.d.ts +0 -121
- package/dist/core/StateBindingManager.js +0 -309
- package/dist/core/StateMachine.d.ts +0 -441
- package/dist/core/StateMachine.js +0 -883
- package/dist/core/StructuralChangeDetector.d.ts +0 -140
- package/dist/core/StructuralChangeDetector.js +0 -363
- package/dist/core/Validator.d.ts +0 -127
- package/dist/core/Validator.js +0 -279
- package/dist/core/errors.d.ts +0 -153
- package/dist/core/errors.js +0 -202
- package/dist/core/index.d.ts +0 -38
- package/dist/core/index.js +0 -64
- package/dist/core/types.d.ts +0 -265
- package/dist/core/types.js +0 -48
- package/dist/hooks/context.d.ts +0 -147
- package/dist/hooks/context.js +0 -334
- package/dist/hooks/useContext.d.ts +0 -113
- package/dist/hooks/useContext.js +0 -169
- package/dist/hooks/useEffect.d.ts +0 -105
- package/dist/hooks/useEffect.js +0 -540
- package/dist/hooks/useInstance.d.ts +0 -139
- package/dist/hooks/useInstance.js +0 -455
- package/dist/hooks/useState.d.ts +0 -120
- package/dist/hooks/useState.js +0 -298
- package/dist/jsx.d.ts +0 -143
- package/dist/jsx.js +0 -76
- package/dist/providers/DummyBackendProvider.d.ts +0 -193
- package/dist/providers/DummyBackendProvider.js +0 -189
- package/dist/providers/DummyCloudProvider.d.ts +0 -128
- package/dist/providers/DummyCloudProvider.js +0 -157
- package/dist/providers/IBackendProvider.d.ts +0 -177
- package/dist/providers/IBackendProvider.js +0 -31
- package/dist/providers/ICloudProvider.d.ts +0 -230
- package/dist/providers/ICloudProvider.js +0 -31
- package/dist/providers/index.d.ts +0 -31
- package/dist/providers/index.js +0 -31
- package/dist/test-event-callbacks.d.ts +0 -0
- package/dist/test-event-callbacks.js +0 -1
- package/dist/utils/Logger.d.ts +0 -144
- package/dist/utils/Logger.js +0 -220
- package/dist/utils/Output.d.ts +0 -161
- package/dist/utils/Output.js +0 -401
- package/dist/utils/deepEqual.d.ts +0 -71
- package/dist/utils/deepEqual.js +0 -276
- package/dist/utils/naming.d.ts +0 -241
- package/dist/utils/naming.js +0 -376
package/README.md
CHANGED
|
@@ -1,38 +1,89 @@
|
|
|
1
|
+
# CReact
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
**Declarative universal reactive runtime.**
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
## Install
|
|
5
6
|
|
|
7
|
+
```bash
|
|
8
|
+
npm install creact
|
|
9
|
+
```
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
## Quick Example
|
|
8
12
|
|
|
9
13
|
```tsx
|
|
10
|
-
|
|
14
|
+
// tsconfig.json: "jsxImportSource": "creact"
|
|
15
|
+
|
|
16
|
+
import { CReact, renderCloudDOM, useInstance } from 'creact';
|
|
17
|
+
|
|
18
|
+
// Define constructs
|
|
19
|
+
class ChatModel {
|
|
20
|
+
constructor(public props: { model: string }) {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class Memory {
|
|
24
|
+
constructor(public props: {}) {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Define components
|
|
28
|
+
function Model({ model, children }) {
|
|
29
|
+
const out = useInstance(ChatModel, { model });
|
|
30
|
+
return children(out);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Mem({ children }) {
|
|
34
|
+
const out = useInstance(Memory, {});
|
|
35
|
+
return children(out);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function App({ prompt }) {
|
|
11
39
|
return (
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
<Model model="gpt-4">
|
|
41
|
+
{(model) => (
|
|
42
|
+
<Mem>
|
|
43
|
+
{(memory) => (
|
|
44
|
+
<Agent
|
|
45
|
+
prompt={prompt}
|
|
46
|
+
modelId={model.id()}
|
|
47
|
+
messages={memory.messages()}
|
|
48
|
+
/>
|
|
49
|
+
)}
|
|
50
|
+
</Mem>
|
|
51
|
+
)}
|
|
52
|
+
</Model>
|
|
19
53
|
);
|
|
20
54
|
}
|
|
55
|
+
|
|
56
|
+
// Run
|
|
57
|
+
CReact.provider = new AgentProvider();
|
|
58
|
+
CReact.backend = new FileBackend({ directory: '.state' });
|
|
59
|
+
|
|
60
|
+
await renderCloudDOM(<App prompt="Hello" />, 'agent');
|
|
21
61
|
```
|
|
22
62
|
|
|
23
|
-
##
|
|
63
|
+
## The Four Pillars
|
|
24
64
|
|
|
65
|
+
**Declarative** — Describe what you want, not how to get it.
|
|
25
66
|
|
|
26
|
-
|
|
67
|
+
**Universal** — Works for AI agents, cloud infrastructure, APIs, anything.
|
|
27
68
|
|
|
28
|
-
|
|
29
|
-
# Deploy your infrastructure
|
|
30
|
-
creact deploy --entry my-app.tsx
|
|
69
|
+
**Reactive** — Automatically responds when things change.
|
|
31
70
|
|
|
32
|
-
|
|
33
|
-
creact dev --entry my-app.tsx --auto-approve
|
|
71
|
+
**Runtime** — Keeps running continuously, handles events, recovers from crashes.
|
|
34
72
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
### Getting Started
|
|
76
|
+
|
|
77
|
+
- [Tutorial: Build an AI Agent](./docs/getting-started/1-setup.md)
|
|
78
|
+
|
|
79
|
+
### Concepts
|
|
80
|
+
|
|
81
|
+
- [Thinking in CReact](./docs/concepts/thinking-in-creact.md) — The mental model
|
|
82
|
+
- [Constructs](./docs/concepts/constructs.md) — Your building blocks
|
|
83
|
+
- [Components](./docs/concepts/components.md) — Composing with JSX
|
|
84
|
+
- [Reactivity](./docs/concepts/reactivity.md) — When things change
|
|
85
|
+
- [Providers](./docs/concepts/providers.md) — Connecting to the real world
|
|
86
|
+
|
|
87
|
+
## License
|
|
38
88
|
|
|
89
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CReact CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage: creact ./app.tsx
|
|
6
|
+
* creact --watch ./app.tsx
|
|
7
|
+
*
|
|
8
|
+
* Runs a CReact application with the configured provider.
|
|
9
|
+
* Uses tsx under the hood to execute TypeScript/TSX files.
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
function showHelp() {
|
|
14
|
+
console.log(`
|
|
15
|
+
CReact CLI
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
creact <entrypoint> Run a CReact application
|
|
19
|
+
creact --watch <entrypoint> Run with hot reload on file changes
|
|
20
|
+
creact -w <entrypoint> Short form of --watch
|
|
21
|
+
creact --help Show this help message
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
creact ./app.tsx Run app.tsx
|
|
25
|
+
creact -w ./app.tsx Run with hot reload
|
|
26
|
+
creact --watch src/index.tsx Run src/index.tsx with hot reload
|
|
27
|
+
|
|
28
|
+
The entrypoint file should:
|
|
29
|
+
1. Set CReact.provider to your provider
|
|
30
|
+
2. Export a default async function that calls renderCloudDOM()
|
|
31
|
+
|
|
32
|
+
Example entrypoint:
|
|
33
|
+
import { CReact, renderCloudDOM } from 'creact';
|
|
34
|
+
import { App } from './components/App.js';
|
|
35
|
+
import { MyProvider } from './providers/MyProvider.js';
|
|
36
|
+
|
|
37
|
+
CReact.provider = await MyProvider.create();
|
|
38
|
+
|
|
39
|
+
export default async function() {
|
|
40
|
+
return await renderCloudDOM(<App />, 'my-stack');
|
|
41
|
+
}
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
async function main() {
|
|
45
|
+
const args = process.argv.slice(2);
|
|
46
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
47
|
+
showHelp();
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
// Parse --watch / -w flag and get entrypoint
|
|
51
|
+
let watch = false;
|
|
52
|
+
let entrypointArg;
|
|
53
|
+
const firstArg = args[0];
|
|
54
|
+
if (firstArg === '--watch' || firstArg === '-w') {
|
|
55
|
+
watch = true;
|
|
56
|
+
const arg = args[1];
|
|
57
|
+
if (!arg) {
|
|
58
|
+
console.error('Error: --watch requires an entrypoint');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
entrypointArg = arg;
|
|
62
|
+
}
|
|
63
|
+
else if (firstArg) {
|
|
64
|
+
entrypointArg = firstArg;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
showHelp();
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
const entrypoint = resolve(process.cwd(), entrypointArg);
|
|
71
|
+
// Build tsx command
|
|
72
|
+
const tsxArgs = watch ? ['tsx', 'watch', entrypoint] : ['tsx', entrypoint];
|
|
73
|
+
// Spawn tsx to run the entrypoint
|
|
74
|
+
const child = spawn('npx', tsxArgs, {
|
|
75
|
+
stdio: 'inherit',
|
|
76
|
+
cwd: process.cwd(),
|
|
77
|
+
shell: true,
|
|
78
|
+
});
|
|
79
|
+
child.on('error', (error) => {
|
|
80
|
+
console.error('Error running CReact application:');
|
|
81
|
+
console.error(error.message);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
child.on('exit', (code) => {
|
|
85
|
+
process.exit(code ?? 0);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
main();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
|
|
23
|
-
* limitations under the License.
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
* Copyright 2025 Daniel Coutinho Ribeiro
|
|
28
|
-
|
|
2
|
+
* CReact - Universal Reactive Runtime
|
|
29
3
|
*/
|
|
30
|
-
export {
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
export
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
46
|
-
export {
|
|
4
|
+
export { createElement, Fragment, jsx, jsxs } from './jsx/jsx-runtime';
|
|
5
|
+
export { createContext, useContext } from './primitives/context';
|
|
6
|
+
export { useInstance } from './primitives/instance';
|
|
7
|
+
export { createStore } from './primitives/store';
|
|
8
|
+
export type { AuditLogEntry, Backend, ChangeSet, DeploymentState, DeploymentStatus, ResourceState, SerializedNode, } from './provider/backend';
|
|
9
|
+
export { serializeNode, serializeNodes } from './provider/backend';
|
|
10
|
+
export type { OutputChangeEvent, Provider } from './provider/interface';
|
|
11
|
+
export { createMockProvider } from './provider/interface';
|
|
12
|
+
export { createEffect, onCleanup } from './reactive/effect';
|
|
13
|
+
export { createSignal } from './reactive/signal';
|
|
14
|
+
export { batch, untrack } from './reactive/tracking';
|
|
15
|
+
export type { DependencyGraph } from './runtime/reconcile';
|
|
16
|
+
export { buildDependencyGraph, computeParallelBatches, hasNewNodes, reconcile, topologicalSort, } from './runtime/reconcile';
|
|
17
|
+
export type { CReactOptions } from './runtime/run';
|
|
18
|
+
export { CReact, renderCloudDOM, resetRuntime, run, runWithBackend } from './runtime/run';
|
|
19
|
+
export type { StateMachineOptions } from './runtime/state-machine';
|
|
20
|
+
export { StateMachine } from './runtime/state-machine';
|
|
21
|
+
export type { Accessor, Context, Fiber, InstanceNode, JSXElement, OutputAccessors, SetStoreFunction, Setter, } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
|
-
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
|
|
22
|
-
* See the License for the specific language governing permissions and
|
|
23
|
-
|
|
24
|
-
* limitations under the License.
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
* Copyright 2025 Daniel Coutinho Ribeiro
|
|
29
|
-
|
|
2
|
+
* CReact - Universal Reactive Runtime
|
|
30
3
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var useInstance_1 = require("./hooks/useInstance");
|
|
51
|
-
Object.defineProperty(exports, "useInstance", { enumerable: true, get: function () { return useInstance_1.useInstance; } });
|
|
52
|
-
var useState_1 = require("./hooks/useState");
|
|
53
|
-
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return useState_1.useState; } });
|
|
54
|
-
var useContext_1 = require("./hooks/useContext");
|
|
55
|
-
Object.defineProperty(exports, "useContext", { enumerable: true, get: function () { return useContext_1.useContext; } });
|
|
56
|
-
var useEffect_1 = require("./hooks/useEffect");
|
|
57
|
-
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return useEffect_1.useEffect; } });
|
|
58
|
-
// Context API
|
|
59
|
-
var context_1 = require("./context");
|
|
60
|
-
Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return context_1.createContext; } });
|
|
61
|
-
// Utilities
|
|
62
|
-
var naming_1 = require("./utils/naming");
|
|
63
|
-
Object.defineProperty(exports, "generateResourceId", { enumerable: true, get: function () { return naming_1.generateResourceId; } });
|
|
64
|
-
Object.defineProperty(exports, "toKebabCase", { enumerable: true, get: function () { return naming_1.toKebabCase; } });
|
|
65
|
-
Object.defineProperty(exports, "getNodeName", { enumerable: true, get: function () { return naming_1.getNodeName; } });
|
|
66
|
-
Object.defineProperty(exports, "validateIdUniqueness", { enumerable: true, get: function () { return naming_1.validateIdUniqueness; } });
|
|
67
|
-
Object.defineProperty(exports, "normalizePathSegment", { enumerable: true, get: function () { return naming_1.normalizePathSegment; } });
|
|
68
|
-
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return naming_1.normalizePath; } });
|
|
69
|
-
Object.defineProperty(exports, "formatPath", { enumerable: true, get: function () { return naming_1.formatPath; } });
|
|
70
|
-
Object.defineProperty(exports, "parseResourceId", { enumerable: true, get: function () { return naming_1.parseResourceId; } });
|
|
4
|
+
// JSX
|
|
5
|
+
export { createElement, Fragment, jsx, jsxs } from './jsx/jsx-runtime';
|
|
6
|
+
export { createContext, useContext } from './primitives/context';
|
|
7
|
+
// Primitives
|
|
8
|
+
export { useInstance } from './primitives/instance';
|
|
9
|
+
export { createStore } from './primitives/store';
|
|
10
|
+
// Backend
|
|
11
|
+
export { serializeNode, serializeNodes } from './provider/backend';
|
|
12
|
+
// Provider
|
|
13
|
+
export { createMockProvider } from './provider/interface';
|
|
14
|
+
// Reactive
|
|
15
|
+
export { createEffect, onCleanup } from './reactive/effect';
|
|
16
|
+
export { createSignal } from './reactive/signal';
|
|
17
|
+
export { batch, untrack } from './reactive/tracking';
|
|
18
|
+
// Reconciler
|
|
19
|
+
export { buildDependencyGraph, computeParallelBatches, hasNewNodes, reconcile, topologicalSort, } from './runtime/reconcile';
|
|
20
|
+
// Runtime
|
|
21
|
+
export { CReact, renderCloudDOM, resetRuntime, run, runWithBackend } from './runtime/run';
|
|
22
|
+
export { StateMachine } from './runtime/state-machine';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createElement, Fragment, jsx, jsxDEV, jsxs } from './jsx-runtime';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX Runtime - createElement and Fragment
|
|
3
|
+
*/
|
|
4
|
+
export interface JSXElement {
|
|
5
|
+
type: any;
|
|
6
|
+
props: Record<string, any>;
|
|
7
|
+
key?: string | number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* JSX namespace for TypeScript
|
|
11
|
+
* Handles key and children automatically - no need to declare in component props
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace JSX {
|
|
14
|
+
type Element = JSXElement;
|
|
15
|
+
interface IntrinsicElements {
|
|
16
|
+
[elemName: string]: any;
|
|
17
|
+
}
|
|
18
|
+
interface IntrinsicAttributes {
|
|
19
|
+
key?: string | number;
|
|
20
|
+
}
|
|
21
|
+
interface ElementChildrenAttribute {
|
|
22
|
+
children: {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a JSX element
|
|
27
|
+
*/
|
|
28
|
+
export declare function createElement(type: any, props: Record<string, any> | null, ...children: any[]): JSXElement;
|
|
29
|
+
/**
|
|
30
|
+
* Fragment - renders children without wrapper
|
|
31
|
+
*/
|
|
32
|
+
export declare const Fragment: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* JSX runtime functions (for automatic JSX transform)
|
|
35
|
+
*/
|
|
36
|
+
export declare function jsx(type: any, props: Record<string, any>, key?: string | number): JSXElement;
|
|
37
|
+
export declare function jsxs(type: any, props: Record<string, any>, key?: string | number): JSXElement;
|
|
38
|
+
export { jsx as jsxDEV };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX Runtime - createElement and Fragment
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create a JSX element
|
|
6
|
+
*/
|
|
7
|
+
export function createElement(type, props, ...children) {
|
|
8
|
+
const normalizedProps = { ...props };
|
|
9
|
+
// Handle children
|
|
10
|
+
if (children.length === 1) {
|
|
11
|
+
normalizedProps.children = children[0];
|
|
12
|
+
}
|
|
13
|
+
else if (children.length > 1) {
|
|
14
|
+
normalizedProps.children = children;
|
|
15
|
+
}
|
|
16
|
+
// Extract key
|
|
17
|
+
const key = normalizedProps.key;
|
|
18
|
+
delete normalizedProps.key;
|
|
19
|
+
return {
|
|
20
|
+
type,
|
|
21
|
+
props: normalizedProps,
|
|
22
|
+
key,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fragment - renders children without wrapper
|
|
27
|
+
*/
|
|
28
|
+
export const Fragment = Symbol.for('creact.fragment');
|
|
29
|
+
/**
|
|
30
|
+
* JSX runtime functions (for automatic JSX transform)
|
|
31
|
+
*/
|
|
32
|
+
export function jsx(type, props, key) {
|
|
33
|
+
return { type, props, key };
|
|
34
|
+
}
|
|
35
|
+
export function jsxs(type, props, key) {
|
|
36
|
+
return { type, props, key };
|
|
37
|
+
}
|
|
38
|
+
export { jsx as jsxDEV };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context - pass values down the component tree (non-reactive)
|
|
3
|
+
*/
|
|
4
|
+
export interface Context<T> {
|
|
5
|
+
id: symbol;
|
|
6
|
+
defaultValue: T | undefined;
|
|
7
|
+
Provider: (props: {
|
|
8
|
+
value: T;
|
|
9
|
+
children: any;
|
|
10
|
+
}) => any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a context for passing values down the tree
|
|
14
|
+
*/
|
|
15
|
+
export declare function createContext<T>(defaultValue?: T): Context<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Read a context value
|
|
18
|
+
*/
|
|
19
|
+
export declare function useContext<T>(context: Context<T>): T;
|
|
20
|
+
/**
|
|
21
|
+
* Push a context value (called by renderer)
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function pushContext<T>(contextId: symbol, value: T): void;
|
|
25
|
+
/**
|
|
26
|
+
* Pop a context value (called by renderer)
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function popContext(contextId: symbol): void;
|
|
30
|
+
/**
|
|
31
|
+
* Clear all context stacks (for testing)
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export declare function clearContextStacks(): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context - pass values down the component tree (non-reactive)
|
|
3
|
+
*/
|
|
4
|
+
// Stack of values per context ID
|
|
5
|
+
// biome-ignore lint/suspicious/noExplicitAny: context values can be any type
|
|
6
|
+
const contextStacks = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Create a context for passing values down the tree
|
|
9
|
+
*/
|
|
10
|
+
export function createContext(defaultValue) {
|
|
11
|
+
const id = Symbol('context');
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: Provider accepts any JSX children
|
|
13
|
+
const Provider = (props) => {
|
|
14
|
+
return {
|
|
15
|
+
type: Provider,
|
|
16
|
+
props,
|
|
17
|
+
__context: id,
|
|
18
|
+
__isProvider: true,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
id,
|
|
23
|
+
defaultValue,
|
|
24
|
+
Provider,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Read a context value
|
|
29
|
+
*/
|
|
30
|
+
export function useContext(context) {
|
|
31
|
+
const stack = contextStacks.get(context.id);
|
|
32
|
+
if (stack?.length) {
|
|
33
|
+
return stack[stack.length - 1];
|
|
34
|
+
}
|
|
35
|
+
return context.defaultValue;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Push a context value (called by renderer)
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export function pushContext(contextId, value) {
|
|
42
|
+
let stack = contextStacks.get(contextId);
|
|
43
|
+
if (!stack) {
|
|
44
|
+
stack = [];
|
|
45
|
+
contextStacks.set(contextId, stack);
|
|
46
|
+
}
|
|
47
|
+
stack.push(value);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pop a context value (called by renderer)
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export function popContext(contextId) {
|
|
54
|
+
const stack = contextStacks.get(contextId);
|
|
55
|
+
stack?.pop();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear all context stacks (for testing)
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export function clearContextStacks() {
|
|
62
|
+
contextStacks.clear();
|
|
63
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type Context, createContext, useContext } from './context';
|
|
2
|
+
export { clearNodeRegistry, fillInstanceOutputs, getAllNodes, getNodeById, type InstanceNode, type OutputAccessors, useInstance, } from './instance';
|
|
3
|
+
export { createStore, type SetStoreFunction } from './store';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useInstance - bind to a provider and get reactive outputs
|
|
3
|
+
*/
|
|
4
|
+
import { type Accessor, type Setter } from '../reactive/signal';
|
|
5
|
+
/**
|
|
6
|
+
* Instance node - represents something materialized by provider
|
|
7
|
+
*/
|
|
8
|
+
export interface InstanceNode {
|
|
9
|
+
id: string;
|
|
10
|
+
path: string[];
|
|
11
|
+
construct: any;
|
|
12
|
+
constructType: string;
|
|
13
|
+
props: Record<string, any>;
|
|
14
|
+
outputSignals: Map<string, [Accessor<any>, Setter<any>]>;
|
|
15
|
+
children: InstanceNode[];
|
|
16
|
+
store?: any;
|
|
17
|
+
outputs?: Record<string, any>;
|
|
18
|
+
/** Update outputs reactively - triggers dependent re-renders via signals */
|
|
19
|
+
setOutputs(outputs: Record<string, any>): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Serialized node shape (from backend.ts) - only what we need for hydration
|
|
23
|
+
*/
|
|
24
|
+
interface SerializedNodeForHydration {
|
|
25
|
+
id: string;
|
|
26
|
+
outputs?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Prepare output hydration from serialized nodes
|
|
30
|
+
* Called by runtime BEFORE rendering to restore outputs
|
|
31
|
+
*/
|
|
32
|
+
export declare function prepareOutputHydration(serializedNodes: SerializedNodeForHydration[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clear output hydration map
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearOutputHydration(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Output accessor type - each property is a signal accessor
|
|
39
|
+
*/
|
|
40
|
+
export type OutputAccessors<O> = {
|
|
41
|
+
[K in keyof O]: () => O[K] | undefined;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Create an instance bound to a provider
|
|
45
|
+
*/
|
|
46
|
+
export declare function useInstance<O extends Record<string, any> = Record<string, any>>(construct: any, props: Record<string, any>): OutputAccessors<O>;
|
|
47
|
+
/**
|
|
48
|
+
* Fill instance outputs (called by runtime after provider returns)
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function fillInstanceOutputs(nodeId: string, outputs: Record<string, any>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get a node by ID
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare function getNodeById(nodeId: string): InstanceNode | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get all registered nodes
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export declare function getAllNodes(): InstanceNode[];
|
|
62
|
+
/**
|
|
63
|
+
* Clear node registry (for testing)
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare function clearNodeRegistry(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Clear node ownership (call at start of each render pass)
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export declare function clearNodeOwnership(): void;
|
|
72
|
+
export {};
|