@creact-labs/creact 0.1.8 → 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.
Files changed (146) hide show
  1. package/README.md +73 -22
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +88 -0
  4. package/dist/index.d.ts +19 -44
  5. package/dist/index.js +20 -68
  6. package/dist/jsx/index.d.ts +2 -0
  7. package/dist/jsx/index.js +1 -0
  8. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  9. package/dist/jsx/jsx-dev-runtime.js +4 -0
  10. package/dist/jsx/jsx-runtime.d.ts +38 -0
  11. package/dist/jsx/jsx-runtime.js +38 -0
  12. package/dist/jsx/types.d.ts +12 -0
  13. package/dist/jsx/types.js +4 -0
  14. package/dist/primitives/context.d.ts +34 -0
  15. package/dist/primitives/context.js +63 -0
  16. package/dist/primitives/index.d.ts +3 -0
  17. package/dist/primitives/index.js +3 -0
  18. package/dist/primitives/instance.d.ts +72 -0
  19. package/dist/primitives/instance.js +235 -0
  20. package/dist/primitives/store.d.ts +22 -0
  21. package/dist/primitives/store.js +97 -0
  22. package/dist/provider/backend.d.ts +110 -0
  23. package/dist/provider/backend.js +37 -0
  24. package/dist/provider/interface.d.ts +48 -0
  25. package/dist/provider/interface.js +39 -0
  26. package/dist/reactive/effect.d.ts +11 -0
  27. package/dist/reactive/effect.js +42 -0
  28. package/dist/reactive/index.d.ts +3 -0
  29. package/dist/reactive/index.js +3 -0
  30. package/dist/reactive/signal.d.ts +32 -0
  31. package/dist/reactive/signal.js +60 -0
  32. package/dist/reactive/tracking.d.ts +41 -0
  33. package/dist/reactive/tracking.js +161 -0
  34. package/dist/runtime/fiber.d.ts +21 -0
  35. package/dist/runtime/fiber.js +16 -0
  36. package/dist/runtime/index.d.ts +4 -0
  37. package/dist/runtime/index.js +4 -0
  38. package/dist/runtime/reconcile.d.ts +66 -0
  39. package/dist/runtime/reconcile.js +210 -0
  40. package/dist/runtime/render.d.ts +42 -0
  41. package/dist/runtime/render.js +231 -0
  42. package/dist/runtime/run.d.ts +119 -0
  43. package/dist/runtime/run.js +334 -0
  44. package/dist/runtime/state-machine.d.ts +95 -0
  45. package/dist/runtime/state-machine.js +209 -0
  46. package/dist/types.d.ts +13 -0
  47. package/dist/types.js +4 -0
  48. package/package.json +11 -24
  49. package/dist/cli/commands/BuildCommand.d.ts +0 -40
  50. package/dist/cli/commands/BuildCommand.js +0 -151
  51. package/dist/cli/commands/DeployCommand.d.ts +0 -38
  52. package/dist/cli/commands/DeployCommand.js +0 -194
  53. package/dist/cli/commands/DevCommand.d.ts +0 -52
  54. package/dist/cli/commands/DevCommand.js +0 -394
  55. package/dist/cli/commands/PlanCommand.d.ts +0 -39
  56. package/dist/cli/commands/PlanCommand.js +0 -164
  57. package/dist/cli/commands/index.d.ts +0 -36
  58. package/dist/cli/commands/index.js +0 -43
  59. package/dist/cli/core/ArgumentParser.d.ts +0 -46
  60. package/dist/cli/core/ArgumentParser.js +0 -127
  61. package/dist/cli/core/BaseCommand.d.ts +0 -75
  62. package/dist/cli/core/BaseCommand.js +0 -95
  63. package/dist/cli/core/CLIContext.d.ts +0 -68
  64. package/dist/cli/core/CLIContext.js +0 -183
  65. package/dist/cli/core/CommandRegistry.d.ts +0 -64
  66. package/dist/cli/core/CommandRegistry.js +0 -89
  67. package/dist/cli/core/index.d.ts +0 -36
  68. package/dist/cli/core/index.js +0 -43
  69. package/dist/cli/index.d.ts +0 -35
  70. package/dist/cli/index.js +0 -100
  71. package/dist/cli/output.d.ts +0 -204
  72. package/dist/cli/output.js +0 -437
  73. package/dist/cli/utils.d.ts +0 -59
  74. package/dist/cli/utils.js +0 -76
  75. package/dist/context/createContext.d.ts +0 -90
  76. package/dist/context/createContext.js +0 -113
  77. package/dist/context/index.d.ts +0 -30
  78. package/dist/context/index.js +0 -35
  79. package/dist/core/CReact.d.ts +0 -409
  80. package/dist/core/CReact.js +0 -1151
  81. package/dist/core/CloudDOMBuilder.d.ts +0 -447
  82. package/dist/core/CloudDOMBuilder.js +0 -1234
  83. package/dist/core/ContextDependencyTracker.d.ts +0 -165
  84. package/dist/core/ContextDependencyTracker.js +0 -448
  85. package/dist/core/ErrorRecoveryManager.d.ts +0 -145
  86. package/dist/core/ErrorRecoveryManager.js +0 -443
  87. package/dist/core/EventBus.d.ts +0 -91
  88. package/dist/core/EventBus.js +0 -185
  89. package/dist/core/ProviderOutputTracker.d.ts +0 -211
  90. package/dist/core/ProviderOutputTracker.js +0 -476
  91. package/dist/core/ReactiveUpdateQueue.d.ts +0 -76
  92. package/dist/core/ReactiveUpdateQueue.js +0 -121
  93. package/dist/core/Reconciler.d.ts +0 -415
  94. package/dist/core/Reconciler.js +0 -1044
  95. package/dist/core/RenderScheduler.d.ts +0 -153
  96. package/dist/core/RenderScheduler.js +0 -519
  97. package/dist/core/Renderer.d.ts +0 -336
  98. package/dist/core/Renderer.js +0 -944
  99. package/dist/core/Runtime.d.ts +0 -246
  100. package/dist/core/Runtime.js +0 -640
  101. package/dist/core/StateBindingManager.d.ts +0 -121
  102. package/dist/core/StateBindingManager.js +0 -309
  103. package/dist/core/StateMachine.d.ts +0 -441
  104. package/dist/core/StateMachine.js +0 -883
  105. package/dist/core/StructuralChangeDetector.d.ts +0 -140
  106. package/dist/core/StructuralChangeDetector.js +0 -363
  107. package/dist/core/Validator.d.ts +0 -127
  108. package/dist/core/Validator.js +0 -279
  109. package/dist/core/errors.d.ts +0 -153
  110. package/dist/core/errors.js +0 -202
  111. package/dist/core/index.d.ts +0 -38
  112. package/dist/core/index.js +0 -64
  113. package/dist/core/types.d.ts +0 -265
  114. package/dist/core/types.js +0 -48
  115. package/dist/hooks/context.d.ts +0 -147
  116. package/dist/hooks/context.js +0 -334
  117. package/dist/hooks/useContext.d.ts +0 -113
  118. package/dist/hooks/useContext.js +0 -169
  119. package/dist/hooks/useEffect.d.ts +0 -105
  120. package/dist/hooks/useEffect.js +0 -540
  121. package/dist/hooks/useInstance.d.ts +0 -139
  122. package/dist/hooks/useInstance.js +0 -455
  123. package/dist/hooks/useState.d.ts +0 -120
  124. package/dist/hooks/useState.js +0 -298
  125. package/dist/jsx.d.ts +0 -143
  126. package/dist/jsx.js +0 -76
  127. package/dist/providers/DummyBackendProvider.d.ts +0 -193
  128. package/dist/providers/DummyBackendProvider.js +0 -189
  129. package/dist/providers/DummyCloudProvider.d.ts +0 -128
  130. package/dist/providers/DummyCloudProvider.js +0 -157
  131. package/dist/providers/IBackendProvider.d.ts +0 -177
  132. package/dist/providers/IBackendProvider.js +0 -31
  133. package/dist/providers/ICloudProvider.d.ts +0 -230
  134. package/dist/providers/ICloudProvider.js +0 -31
  135. package/dist/providers/index.d.ts +0 -31
  136. package/dist/providers/index.js +0 -31
  137. package/dist/test-event-callbacks.d.ts +0 -0
  138. package/dist/test-event-callbacks.js +0 -1
  139. package/dist/utils/Logger.d.ts +0 -144
  140. package/dist/utils/Logger.js +0 -220
  141. package/dist/utils/Output.d.ts +0 -161
  142. package/dist/utils/Output.js +0 -401
  143. package/dist/utils/deepEqual.d.ts +0 -71
  144. package/dist/utils/deepEqual.js +0 -276
  145. package/dist/utils/naming.d.ts +0 -241
  146. package/dist/utils/naming.js +0 -376
@@ -1,120 +0,0 @@
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
-
29
- */
30
- import { StateBindingManager } from '../core/StateBindingManager';
31
- import { FiberNode } from '../core/types';
32
- /**
33
- * Set the StateBindingManager instance (for testing/injection)
34
- * @internal
35
- */
36
- export declare function setStateBindingManager(manager: StateBindingManager): void;
37
- /**
38
- * Get the StateBindingManager instance (for external access)
39
- * @internal
40
- */
41
- export declare function getStateBindingManagerInstance(): StateBindingManager;
42
- /**
43
- * Set the current rendering context for useState
44
- * Called by Renderer before executing a component
45
- *
46
- * @internal
47
- */
48
- export declare function setStateRenderContext(fiber: FiberNode, path?: string[]): void;
49
- /**
50
- * Clear the current rendering context for useState
51
- * Called by Renderer after component execution
52
- *
53
- * @internal
54
- */
55
- export declare function clearStateRenderContext(): void;
56
- /**
57
- * useState hook - Declare component outputs (NOT reactive state)
58
- *
59
- * This hook declares outputs that will be persisted across build/deploy cycles.
60
- * Unlike React's useState, this does NOT trigger re-renders.
61
- *
62
- * Mimics React's useState API with hooks array pattern for multiple calls.
63
- *
64
- * REQ-02: Stack Context (declarative outputs)
65
- *
66
- * Semantics:
67
- * - `useState(initialValue)` - Declares a single output value
68
- * - `setState(value)` during build - Updates the output value for build-time enrichment
69
- * - `setState(value)` during deploy - Updates persisted output after provider materialization
70
- * - NOT a render trigger - it's a persistent output update mechanism
71
- * - Supports multiple useState calls per component (like React)
72
- *
73
- * Key difference from React:
74
- * - React: `setState()` causes re-render in memory
75
- * - CReact: `setState()` updates persisted outputs for next cycle
76
- *
77
- * @param initialValue - Initial output value to declare
78
- * @returns Tuple of [state, setState] where setState updates the output value
79
- *
80
- * @example
81
- * ```tsx
82
- * function CDNStack({ children }) {
83
- * const distribution = useInstance('cdn', CloudFrontDistribution, { ... });
84
- *
85
- * // Multiple useState calls (like React)
86
- * const [distributionId, setDistributionId] = useState<string>();
87
- * const [distributionDomain, setDistributionDomain] = useState<string>();
88
- * const [distributionArn, setDistributionArn] = useState<string>();
89
- *
90
- * // Optional: Enrich outputs after async materialization
91
- * useEffect(async () => {
92
- * const actualDomain = await distribution.getDomain();
93
- * setDistributionDomain(actualDomain);
94
- * }, [distribution]);
95
- *
96
- * // Aggregate outputs for StackContext
97
- * const outputs = {
98
- * distributionId,
99
- * distributionDomain,
100
- * distributionArn,
101
- * };
102
- *
103
- * return <StackContext.Provider value={outputs}>{children}</StackContext.Provider>;
104
- * }
105
- * ```
106
- */
107
- export declare function useState<T = undefined>(initialValue?: T): [T, (value: T | ((prev: T) => T)) => void];
108
- /**
109
- * Check if useState context is available
110
- * Useful for validation and testing
111
- *
112
- * @internal
113
- */
114
- export declare function hasStateContext(): boolean;
115
- /**
116
- * Get the current state from Fiber (for testing)
117
- *
118
- * @internal
119
- */
120
- export declare function getCurrentState(): Record<string, any> | undefined;
@@ -1,298 +0,0 @@
1
- "use strict";
2
- /**
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
-
30
- */
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.setStateBindingManager = setStateBindingManager;
33
- exports.getStateBindingManagerInstance = getStateBindingManagerInstance;
34
- exports.setStateRenderContext = setStateRenderContext;
35
- exports.clearStateRenderContext = clearStateRenderContext;
36
- exports.useState = useState;
37
- exports.hasStateContext = hasStateContext;
38
- exports.getCurrentState = getCurrentState;
39
- // REQ-02: useState hook for declarative output binding
40
- // This hook declares component outputs that persist across build/deploy cycles
41
- const context_1 = require("./context");
42
- const StateBindingManager_1 = require("../core/StateBindingManager");
43
- const naming_1 = require("../utils/naming");
44
- const ReactiveUpdateQueue_1 = require("../core/ReactiveUpdateQueue");
45
- const Logger_1 = require("../utils/Logger");
46
- const logger = Logger_1.LoggerFactory.getLogger('hooks');
47
- const CReact_1 = require("../core/CReact");
48
- // Global StateBindingManager instance
49
- let stateBindingManager = null;
50
- /**
51
- * Get or create the global StateBindingManager instance
52
- * @internal
53
- */
54
- function getStateBindingManager() {
55
- if (!stateBindingManager) {
56
- stateBindingManager = new StateBindingManager_1.StateBindingManager();
57
- }
58
- return stateBindingManager;
59
- }
60
- /**
61
- * Set the StateBindingManager instance (for testing/injection)
62
- * @internal
63
- */
64
- function setStateBindingManager(manager) {
65
- stateBindingManager = manager;
66
- }
67
- /**
68
- * Get the StateBindingManager instance (for external access)
69
- * @internal
70
- */
71
- function getStateBindingManagerInstance() {
72
- return getStateBindingManager();
73
- }
74
- /**
75
- * Set the current rendering context for useState
76
- * Called by Renderer before executing a component
77
- *
78
- * @internal
79
- */
80
- function setStateRenderContext(fiber, path) {
81
- (0, context_1.setRenderContext)(fiber, path);
82
- }
83
- /**
84
- * Clear the current rendering context for useState
85
- * Called by Renderer after component execution
86
- *
87
- * @internal
88
- */
89
- function clearStateRenderContext() {
90
- (0, context_1.clearRenderContext)();
91
- }
92
- /**
93
- * useState hook - Declare component outputs (NOT reactive state)
94
- *
95
- * This hook declares outputs that will be persisted across build/deploy cycles.
96
- * Unlike React's useState, this does NOT trigger re-renders.
97
- *
98
- * Mimics React's useState API with hooks array pattern for multiple calls.
99
- *
100
- * REQ-02: Stack Context (declarative outputs)
101
- *
102
- * Semantics:
103
- * - `useState(initialValue)` - Declares a single output value
104
- * - `setState(value)` during build - Updates the output value for build-time enrichment
105
- * - `setState(value)` during deploy - Updates persisted output after provider materialization
106
- * - NOT a render trigger - it's a persistent output update mechanism
107
- * - Supports multiple useState calls per component (like React)
108
- *
109
- * Key difference from React:
110
- * - React: `setState()` causes re-render in memory
111
- * - CReact: `setState()` updates persisted outputs for next cycle
112
- *
113
- * @param initialValue - Initial output value to declare
114
- * @returns Tuple of [state, setState] where setState updates the output value
115
- *
116
- * @example
117
- * ```tsx
118
- * function CDNStack({ children }) {
119
- * const distribution = useInstance('cdn', CloudFrontDistribution, { ... });
120
- *
121
- * // Multiple useState calls (like React)
122
- * const [distributionId, setDistributionId] = useState<string>();
123
- * const [distributionDomain, setDistributionDomain] = useState<string>();
124
- * const [distributionArn, setDistributionArn] = useState<string>();
125
- *
126
- * // Optional: Enrich outputs after async materialization
127
- * useEffect(async () => {
128
- * const actualDomain = await distribution.getDomain();
129
- * setDistributionDomain(actualDomain);
130
- * }, [distribution]);
131
- *
132
- * // Aggregate outputs for StackContext
133
- * const outputs = {
134
- * distributionId,
135
- * distributionDomain,
136
- * distributionArn,
137
- * };
138
- *
139
- * return <StackContext.Provider value={outputs}>{children}</StackContext.Provider>;
140
- * }
141
- * ```
142
- */
143
- function useState(initialValue) {
144
- // Use consolidated hook context
145
- const context = (0, context_1.requireHookContext)();
146
- const currentFiber = context.currentFiber; // Non-null assertion safe due to requireHookContext validation
147
- // Initialize hooks array in Fiber node if not already present
148
- if (!currentFiber.hooks) {
149
- currentFiber.hooks = [];
150
- }
151
- // Get current hook index and increment for next call (state-specific)
152
- const currentHookIndex = (0, context_1.incrementHookIndex)('state');
153
- // Initialize this hook's state if first render
154
- if (currentFiber.hooks[currentHookIndex] === undefined) {
155
- // CRITICAL: Check for hydrated value first (hot reload state restoration)
156
- // This allows useState to restore persisted state instead of using initial value
157
- let hydratedValue = undefined;
158
- // Try to get CReact instance to check for hydration data
159
- try {
160
- const creactInstance = (0, CReact_1.getCReactInstance)?.();
161
- if (creactInstance && creactInstance.hasHydrationData()) {
162
- // CRITICAL: The fiber path is the component path (e.g., 'web-app-stack')
163
- const fiberPath = currentFiber.path?.join('.') || '';
164
- logger.debug(`🔍 Looking for hydration: component="${fiberPath}", hookIndex=${currentHookIndex}`);
165
- // Try to get hydration from component path
166
- hydratedValue = creactInstance.getHydratedValueForComponent(fiberPath, currentHookIndex);
167
- if (hydratedValue !== undefined) {
168
- logger.debug(`✅ HYDRATION SUCCESS for ${fiberPath}[${currentHookIndex}]:`, hydratedValue);
169
- }
170
- else {
171
- logger.debug(`❌ HYDRATION FAILED for ${fiberPath}[${currentHookIndex}]`);
172
- logger.debug(` Available hydration keys:`, creactInstance.getHydrationMapKeys?.() || 'N/A');
173
- }
174
- }
175
- else {
176
- logger.debug(`⚠️ No hydration data available (instance=${!!creactInstance}, hasData=${creactInstance?.hasHydrationData()})`);
177
- }
178
- }
179
- catch (error) {
180
- // Hydration is optional, continue with initial value if it fails
181
- logger.warn('⚠️ Hydration check failed:', error);
182
- logger.debug('Stack:', error.stack);
183
- }
184
- // Use hydrated value if available, otherwise use initial value
185
- const finalValue = hydratedValue !== undefined ? hydratedValue : initialValue;
186
- currentFiber.hooks[currentHookIndex] = finalValue;
187
- logger.debug(`📝 Initialized hook[${currentHookIndex}] = ${JSON.stringify(finalValue)} (hydrated=${hydratedValue !== undefined})`);
188
- }
189
- // Store the fiber and hook index for later access
190
- const fiber = currentFiber;
191
- const hookIdx = currentHookIndex;
192
- /**
193
- * setState function - Updates the output value with reactive capabilities
194
- *
195
- * This function updates the persisted output in the Fiber node's hooks array.
196
- * It now includes:
197
- * - Change detection to avoid unnecessary updates
198
- * - Automatic binding detection for provider outputs
199
- * - Integration with StateBindingManager for reactive updates
200
- * - REQ-4.1, 4.2, 4.3: Internal update mechanism to prevent circular dependencies
201
- *
202
- * During build: Collects values known at build-time
203
- * During deploy: Patches in async resources (queue URLs, ARNs)
204
- *
205
- * @param value - New value or updater function
206
- * @param isInternalUpdate - If true, skip binding creation (prevents loops)
207
- */
208
- const setState = (value, isInternalUpdate = false) => {
209
- // Resolve value (handle both direct value and function forms)
210
- const newValue = typeof value === 'function' ? value(fiber.hooks?.[hookIdx]) : value;
211
- const oldValue = fiber.hooks?.[hookIdx];
212
- // Debug logging (before change check for better visibility)
213
- if (process.env.CREACT_DEBUG === 'true') {
214
- const safeStringify = (value) => {
215
- try {
216
- return JSON.stringify(value);
217
- }
218
- catch {
219
- return String(value);
220
- }
221
- };
222
- logger.debug(`setState called: hookIdx=${hookIdx}, oldValue=${safeStringify(oldValue)}, newValue=${safeStringify(newValue)}, isInternal=${isInternalUpdate}, fiber.id=${fiber.path?.join('.')}`);
223
- }
224
- // Only proceed if value actually changed
225
- if (oldValue === newValue) {
226
- logger.debug(`No change detected, skipping update`);
227
- return; // No change, skip update
228
- }
229
- // Update this hook's state
230
- if (fiber.hooks) {
231
- fiber.hooks[hookIdx] = newValue;
232
- }
233
- // REQ-4.2: Only create bindings for user updates, not internal ones
234
- // This prevents infinite binding loops when StateBindingManager updates state
235
- if (!isInternalUpdate) {
236
- // Check if the new value is a provider output and create automatic binding
237
- const bindingManager = getStateBindingManager();
238
- const outputInfo = bindingManager.isProviderOutput(newValue);
239
- if (outputInfo) {
240
- // REQ-4.1, 4.3: Prevent infinite binding loops during reactivity
241
- // Only bind if this state is not already bound to this output
242
- if (!bindingManager.isStateBoundToOutput(fiber, hookIdx)) {
243
- // Automatically bind this state to the provider output
244
- bindingManager.bindStateToOutput(fiber, hookIdx, outputInfo.nodeId, outputInfo.outputKey, newValue);
245
- const bindingKey = (0, naming_1.generateBindingKey)(outputInfo.nodeId, outputInfo.outputKey);
246
- logger.debug(`Auto-bound state to output: ${bindingKey}`);
247
- }
248
- else {
249
- const bindingKey = (0, naming_1.generateBindingKey)(outputInfo.nodeId, outputInfo.outputKey);
250
- logger.debug(`Skipped re-binding already bound state: ${bindingKey}`);
251
- }
252
- }
253
- }
254
- else {
255
- logger.debug(`Skipped binding check for internal update`);
256
- }
257
- // REQ-4.4: Mark fiber as dirty and enqueue for re-render
258
- // This is critical for initial deployment where outputs go from undefined → value
259
- // The fiber will be collected by the reactivity phase and re-rendered
260
- if (!isInternalUpdate && oldValue !== newValue) {
261
- // Mark this fiber as having state changes
262
- if (!fiber.__stateChanged) {
263
- fiber.__stateChanged = true;
264
- }
265
- // Enqueue fiber for re-rendering in reactivity phase
266
- const queue = (0, ReactiveUpdateQueue_1.getReactiveUpdateQueue)();
267
- queue.enqueue(fiber);
268
- logger.debug(`Enqueued fiber ${fiber.path?.join('.')} for re-render (queue size: ${queue.size()})`);
269
- }
270
- };
271
- // REQ-4.1, 4.2: Store setState callback in fiber for internal updates
272
- // This allows StateBindingManager to update state without creating new bindings
273
- if (!fiber.setStateCallbacks) {
274
- fiber.setStateCallbacks = [];
275
- }
276
- fiber.setStateCallbacks[hookIdx] = setState;
277
- // Get current state for this hook - read it fresh each time
278
- // This ensures synchronous setState calls during render are reflected
279
- const state = (fiber.hooks && fiber.hooks[hookIdx]);
280
- return [state, setState];
281
- }
282
- /**
283
- * Check if useState context is available
284
- * Useful for validation and testing
285
- *
286
- * @internal
287
- */
288
- function hasStateContext() {
289
- return (0, context_1.hasRenderContext)();
290
- }
291
- /**
292
- * Get the current state from Fiber (for testing)
293
- *
294
- * @internal
295
- */
296
- function getCurrentState() {
297
- return (0, context_1.getCurrentState)();
298
- }
package/dist/jsx.d.ts DELETED
@@ -1,143 +0,0 @@
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
-
29
- */
30
- /**
31
- * JSX factory for CReact
32
- *
33
- * This module provides the createElement factory function that TypeScript
34
- * uses to transform JSX syntax into function calls.
35
- *
36
- * Example transformation:
37
- * <Component prop="value" />
38
- * → CReact.createElement(Component, { prop: "value" })
39
- */
40
- export interface JSXElement {
41
- type: any;
42
- props: Record<string, any>;
43
- key?: string | number;
44
- }
45
- export declare namespace CReact {
46
- /**
47
- * JSX factory function called by TypeScript when transforming JSX
48
- *
49
- * @param type - Component function or string (for intrinsic elements)
50
- * @param props - Props object (may include key and children)
51
- * @param children - Child elements (variadic)
52
- * @returns JSXElement object with normalized props
53
- */
54
- function createElement(type: any, props: Record<string, any> | null, ...children: any[]): JSXElement;
55
- /**
56
- * Fragment symbol for <>...</> syntax
57
- * Fragments allow grouping multiple children without adding extra nodes
58
- *
59
- * Note: Fragment is a Symbol at runtime, but typed as a function for JSX compatibility
60
- */
61
- const Fragment: (props: {
62
- children?: any;
63
- }) => JSXElement;
64
- }
65
- /**
66
- * Global JSX namespace declarations
67
- *
68
- * These declarations tell TypeScript how to validate JSX syntax and component props.
69
- * By including them in this file (not a separate .d.ts), they are automatically
70
- * included in the compiled output and available to package consumers.
71
- */
72
- declare global {
73
- namespace JSX {
74
- /**
75
- * The type returned by JSX expressions
76
- */
77
- interface Element extends JSXElement {
78
- }
79
- /**
80
- * Intrinsic elements (HTML-like elements)
81
- * Empty for CReact - we only support component elements
82
- */
83
- interface IntrinsicElements {
84
- }
85
- /**
86
- * Defines which prop contains children
87
- * This allows TypeScript to understand the children prop
88
- */
89
- interface ElementChildrenAttribute {
90
- children: {};
91
- }
92
- /**
93
- * Base attributes available on all elements (including key)
94
- * This applies to all JSX elements, both intrinsic and component-based
95
- *
96
- * IMPORTANT: This makes 'key' available on ALL JSX elements,
97
- * including function components, without needing to add it to props
98
- */
99
- interface IntrinsicAttributes {
100
- key?: string | number;
101
- }
102
- /**
103
- * Attributes available on class components
104
- */
105
- interface IntrinsicClassAttributes<T> {
106
- key?: string | number;
107
- }
108
- /**
109
- * Tell TypeScript how to extract props from a component type
110
- * This is critical for making LibraryManagedAttributes work
111
- */
112
- interface ElementAttributesProperty {
113
- props: {};
114
- }
115
- /**
116
- * Augment LibraryManagedAttributes to properly handle key prop
117
- *
118
- * This tells TypeScript that when checking JSX element props:
119
- * 1. Take the component's declared props (P)
120
- * 2. Make key optional (it's in IntrinsicAttributes but shouldn't be required)
121
- * 3. Allow key to be passed even if not in component props
122
- *
123
- * We use Omit to remove 'key' from P if it exists, then add it back as optional
124
- */
125
- type LibraryManagedAttributes<C, P> = Omit<P, 'key'> & IntrinsicAttributes;
126
- }
127
- }
128
- /**
129
- * Type helper for component props with children
130
- */
131
- export interface PropsWithChildren {
132
- children?: JSX.Element | JSX.Element[];
133
- }
134
- /**
135
- * Type helper for functional components
136
- * Note: key is handled by JSX.IntrinsicAttributes and doesn't need to be in props
137
- */
138
- export type FC<P = Record<string, unknown>> = (props: P & PropsWithChildren) => JSX.Element | null;
139
- /**
140
- * Type helper for component props that includes JSX attributes (like key)
141
- * Use this when defining component prop types to allow key prop
142
- */
143
- export type ComponentProps<P = Record<string, unknown>> = P & JSX.IntrinsicAttributes;
package/dist/jsx.js DELETED
@@ -1,76 +0,0 @@
1
- "use strict";
2
- /**
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
-
30
- */
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.CReact = void 0;
33
- var CReact;
34
- (function (CReact) {
35
- /**
36
- * JSX factory function called by TypeScript when transforming JSX
37
- *
38
- * @param type - Component function or string (for intrinsic elements)
39
- * @param props - Props object (may include key and children)
40
- * @param children - Child elements (variadic)
41
- * @returns JSXElement object with normalized props
42
- */
43
- function createElement(type, props, ...children) {
44
- // Normalize props (handle null case)
45
- const normalizedProps = props ? { ...props } : {};
46
- // Extract key from props if present
47
- const key = normalizedProps.key;
48
- delete normalizedProps.key;
49
- // Handle children normalization
50
- if (children.length > 0) {
51
- // Flatten children array and filter out null/undefined
52
- const flattenedChildren = children.flat().filter((child) => child != null);
53
- // Single child: store as-is
54
- // Multiple children: store as array
55
- if (flattenedChildren.length === 1) {
56
- normalizedProps.children = flattenedChildren[0];
57
- }
58
- else if (flattenedChildren.length > 1) {
59
- normalizedProps.children = flattenedChildren;
60
- }
61
- }
62
- return {
63
- type,
64
- props: normalizedProps,
65
- key,
66
- };
67
- }
68
- CReact.createElement = createElement;
69
- /**
70
- * Fragment symbol for <>...</> syntax
71
- * Fragments allow grouping multiple children without adding extra nodes
72
- *
73
- * Note: Fragment is a Symbol at runtime, but typed as a function for JSX compatibility
74
- */
75
- CReact.Fragment = Symbol.for('CReact.Fragment');
76
- })(CReact || (exports.CReact = CReact = {}));