@blac/react 2.0.4 → 2.0.5

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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Global configuration for @blac/react
3
+ */
4
+ export interface BlacReactConfig {
5
+ /** Enable automatic property tracking via Proxy (default: true) */
6
+ autoTrack: boolean;
7
+ }
8
+ /**
9
+ * Configure global defaults for @blac/react hooks.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { configureBlacReact } from '@blac/react';
14
+ *
15
+ * // Disable auto-tracking globally
16
+ * configureBlacReact({
17
+ * autoTrack: false
18
+ * });
19
+ * ```
20
+ *
21
+ * @param config - Partial configuration to merge with defaults
22
+ */
23
+ export declare function configureBlacReact(config: Partial<BlacReactConfig>): void;
24
+ /**
25
+ * Get the current global configuration.
26
+ * @internal
27
+ */
28
+ export declare function getBlacReactConfig(): BlacReactConfig;
29
+ /**
30
+ * Reset configuration to defaults (useful for testing).
31
+ * @internal
32
+ */
33
+ export declare function resetBlacReactConfig(): void;
package/dist/index.d.cts CHANGED
@@ -1,96 +1,11 @@
1
- import type { ExtractState } from '@blac/core';
2
- import { ExtractState as ExtractState_2 } from '@blac/adapter';
3
- import { InstanceReadonlyState } from '@blac/core';
4
- import type { RefObject } from 'react';
5
- import { StateContainerConstructor } from '@blac/adapter';
6
- import type { StateContainerConstructor as StateContainerConstructor_2 } from '@blac/core';
7
-
8
- /**
9
- * Global configuration for @blac/react
10
- */
11
- export declare interface BlacReactConfig {
12
- /** Enable automatic property tracking via Proxy (default: true) */
13
- autoTrack: boolean;
14
- }
15
-
16
- /* Excluded from this release type: ComponentRef */
17
-
18
- /**
19
- * Configure global defaults for @blac/react hooks.
20
- *
21
- * @example
22
- * ```ts
23
- * import { configureBlacReact } from '@blac/react';
24
- *
25
- * // Disable auto-tracking globally
26
- * configureBlacReact({
27
- * autoTrack: false
28
- * });
29
- * ```
30
- *
31
- * @param config - Partial configuration to merge with defaults
32
- */
33
- export declare function configureBlacReact(config: Partial<BlacReactConfig>): void;
34
-
35
- /**
36
- * React hook that connects a component to a state container with automatic re-render on state changes.
37
- *
38
- * Supports three tracking modes:
39
- * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy
40
- * - **Manual dependencies**: Explicit dependency array like useEffect
41
- * - **No tracking**: Returns full state without optimization
42
- *
43
- * @template T - The state container constructor type (inferred from BlocClass)
44
- * @param BlocClass - The state container class to connect to
45
- * @param options - Configuration options for tracking mode and instance management
46
- * @returns Tuple with [state, bloc instance, ref]
47
- *
48
- * @example Basic usage
49
- * ```ts
50
- * const [state, myBloc, ref] = useBloc(MyBloc);
51
- * ```
52
- *
53
- * @example With manual dependencies
54
- * ```ts
55
- * const [state, myBloc] = useBloc(MyBloc, {
56
- * dependencies: (state) => [state.count]
57
- * });
58
- * ```
59
- *
60
- * @example With isolated instance
61
- * ```ts
62
- * const [state, myBloc] = useBloc(MyBloc, {
63
- * instanceId: 'unique-id'
64
- * });
65
- * ```
66
- */
67
- export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState_2<T>>;
68
-
69
- /**
70
- * Configuration options for useBloc hook
71
- * @template TBloc - The state container type
72
- */
73
- export declare interface UseBlocOptions<TBloc extends StateContainerConstructor_2> {
74
- /** Custom instance identifier for shared or isolated instances */
75
- instanceId?: string | number;
76
- /** Manual dependency array like useEffect (disables autoTrack) */
77
- dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[];
78
- /** Enable automatic property tracking via Proxy (default: true) */
79
- autoTrack?: boolean;
80
- /** Callback invoked when bloc instance mounts */
81
- onMount?: (bloc: InstanceType<TBloc>) => void;
82
- /** Callback invoked when bloc instance unmounts */
83
- onUnmount?: (bloc: InstanceType<TBloc>) => void;
84
- }
85
-
86
- /**
87
- * Tuple return type from useBloc hook containing state, bloc instance, and ref
88
- * - [0] Current state value (with optional state type override)
89
- * - [1] State container instance (bloc) for calling actions
90
- * - [2] Ref object for accessing component ref (advanced use cases)
91
- *
92
- * @template TBloc - The state container type
93
- */
94
- export declare type UseBlocReturn<TBloc extends StateContainerConstructor_2, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>];
95
-
96
- export { }
1
+ /**
2
+ * React Integration
3
+ *
4
+ * Clean integration between React and StateContainer architecture.
5
+ * Constructor-based API with automatic type inference.
6
+ * Supports concurrent (useSyncExternalStore) mode for optimal performance.
7
+ */
8
+ export { useBloc } from './useBloc';
9
+ export { configureBlacReact } from './config';
10
+ export type { BlacReactConfig } from './config';
11
+ export type { UseBlocOptions, UseBlocReturn } from './types';
package/dist/index.d.ts CHANGED
@@ -1,96 +1,11 @@
1
- import type { ExtractState } from '@blac/core';
2
- import { ExtractState as ExtractState_2 } from '@blac/adapter';
3
- import { InstanceReadonlyState } from '@blac/core';
4
- import type { RefObject } from 'react';
5
- import { StateContainerConstructor } from '@blac/adapter';
6
- import type { StateContainerConstructor as StateContainerConstructor_2 } from '@blac/core';
7
-
8
- /**
9
- * Global configuration for @blac/react
10
- */
11
- export declare interface BlacReactConfig {
12
- /** Enable automatic property tracking via Proxy (default: true) */
13
- autoTrack: boolean;
14
- }
15
-
16
- /* Excluded from this release type: ComponentRef */
17
-
18
- /**
19
- * Configure global defaults for @blac/react hooks.
20
- *
21
- * @example
22
- * ```ts
23
- * import { configureBlacReact } from '@blac/react';
24
- *
25
- * // Disable auto-tracking globally
26
- * configureBlacReact({
27
- * autoTrack: false
28
- * });
29
- * ```
30
- *
31
- * @param config - Partial configuration to merge with defaults
32
- */
33
- export declare function configureBlacReact(config: Partial<BlacReactConfig>): void;
34
-
35
- /**
36
- * React hook that connects a component to a state container with automatic re-render on state changes.
37
- *
38
- * Supports three tracking modes:
39
- * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy
40
- * - **Manual dependencies**: Explicit dependency array like useEffect
41
- * - **No tracking**: Returns full state without optimization
42
- *
43
- * @template T - The state container constructor type (inferred from BlocClass)
44
- * @param BlocClass - The state container class to connect to
45
- * @param options - Configuration options for tracking mode and instance management
46
- * @returns Tuple with [state, bloc instance, ref]
47
- *
48
- * @example Basic usage
49
- * ```ts
50
- * const [state, myBloc, ref] = useBloc(MyBloc);
51
- * ```
52
- *
53
- * @example With manual dependencies
54
- * ```ts
55
- * const [state, myBloc] = useBloc(MyBloc, {
56
- * dependencies: (state) => [state.count]
57
- * });
58
- * ```
59
- *
60
- * @example With isolated instance
61
- * ```ts
62
- * const [state, myBloc] = useBloc(MyBloc, {
63
- * instanceId: 'unique-id'
64
- * });
65
- * ```
66
- */
67
- export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState_2<T>>;
68
-
69
- /**
70
- * Configuration options for useBloc hook
71
- * @template TBloc - The state container type
72
- */
73
- export declare interface UseBlocOptions<TBloc extends StateContainerConstructor_2> {
74
- /** Custom instance identifier for shared or isolated instances */
75
- instanceId?: string | number;
76
- /** Manual dependency array like useEffect (disables autoTrack) */
77
- dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[];
78
- /** Enable automatic property tracking via Proxy (default: true) */
79
- autoTrack?: boolean;
80
- /** Callback invoked when bloc instance mounts */
81
- onMount?: (bloc: InstanceType<TBloc>) => void;
82
- /** Callback invoked when bloc instance unmounts */
83
- onUnmount?: (bloc: InstanceType<TBloc>) => void;
84
- }
85
-
86
- /**
87
- * Tuple return type from useBloc hook containing state, bloc instance, and ref
88
- * - [0] Current state value (with optional state type override)
89
- * - [1] State container instance (bloc) for calling actions
90
- * - [2] Ref object for accessing component ref (advanced use cases)
91
- *
92
- * @template TBloc - The state container type
93
- */
94
- export declare type UseBlocReturn<TBloc extends StateContainerConstructor_2, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>];
95
-
96
- export { }
1
+ /**
2
+ * React Integration
3
+ *
4
+ * Clean integration between React and StateContainer architecture.
5
+ * Constructor-based API with automatic type inference.
6
+ * Supports concurrent (useSyncExternalStore) mode for optimal performance.
7
+ */
8
+ export { useBloc } from './useBloc';
9
+ export { configureBlacReact } from './config';
10
+ export type { BlacReactConfig } from './config';
11
+ export type { UseBlocOptions, UseBlocReturn } from './types';
@@ -0,0 +1,36 @@
1
+ import type { ExtractState, StateContainerConstructor } from '@blac/core';
2
+ import { InstanceReadonlyState } from '@blac/core';
3
+ import type { RefObject } from 'react';
4
+ /**
5
+ * Configuration options for useBloc hook
6
+ * @template TBloc - The state container type
7
+ */
8
+ export interface UseBlocOptions<TBloc extends StateContainerConstructor> {
9
+ /** Custom instance identifier for shared or isolated instances */
10
+ instanceId?: string | number;
11
+ /** Manual dependency array like useEffect (disables autoTrack) */
12
+ dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[];
13
+ /** Enable automatic property tracking via Proxy (default: true) */
14
+ autoTrack?: boolean;
15
+ /** Callback invoked when bloc instance mounts */
16
+ onMount?: (bloc: InstanceType<TBloc>) => void;
17
+ /** Callback invoked when bloc instance unmounts */
18
+ onUnmount?: (bloc: InstanceType<TBloc>) => void;
19
+ }
20
+ /**
21
+ * Tuple return type from useBloc hook containing state, bloc instance, and ref
22
+ * - [0] Current state value (with optional state type override)
23
+ * - [1] State container instance (bloc) for calling actions
24
+ * - [2] Ref object for accessing component ref (advanced use cases)
25
+ *
26
+ * @template TBloc - The state container type
27
+ */
28
+ export type UseBlocReturn<TBloc extends StateContainerConstructor, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>];
29
+ /**
30
+ * Internal ref structure for component-bloc binding
31
+ * @internal
32
+ */
33
+ export type ComponentRef = {
34
+ /** Cached bloc instance ID for this component */
35
+ __blocInstanceId?: string;
36
+ };
@@ -0,0 +1,35 @@
1
+ import { type ExtractState, type StateContainerConstructor } from '@blac/adapter';
2
+ import type { UseBlocOptions, UseBlocReturn } from './types';
3
+ /**
4
+ * React hook that connects a component to a state container with automatic re-render on state changes.
5
+ *
6
+ * Supports three tracking modes:
7
+ * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy
8
+ * - **Manual dependencies**: Explicit dependency array like useEffect
9
+ * - **No tracking**: Returns full state without optimization
10
+ *
11
+ * @template T - The state container constructor type (inferred from BlocClass)
12
+ * @param BlocClass - The state container class to connect to
13
+ * @param options - Configuration options for tracking mode and instance management
14
+ * @returns Tuple with [state, bloc instance, ref]
15
+ *
16
+ * @example Basic usage
17
+ * ```ts
18
+ * const [state, myBloc, ref] = useBloc(MyBloc);
19
+ * ```
20
+ *
21
+ * @example With manual dependencies
22
+ * ```ts
23
+ * const [state, myBloc] = useBloc(MyBloc, {
24
+ * dependencies: (state) => [state.count]
25
+ * });
26
+ * ```
27
+ *
28
+ * @example With isolated instance
29
+ * ```ts
30
+ * const [state, myBloc] = useBloc(MyBloc, {
31
+ * instanceId: 'unique-id'
32
+ * });
33
+ * ```
34
+ */
35
+ export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState<T>>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Instance key generation utilities for React integration
3
+ */
4
+ import type { ComponentRef } from '../types';
5
+ /**
6
+ * Generate an instance key for a bloc
7
+ *
8
+ * Logic:
9
+ * - If user provides instanceId, use it (convert number to string)
10
+ * - If isolated, generate or reuse a unique key for this component
11
+ * - Otherwise, return undefined (use default key)
12
+ *
13
+ * @param componentRef - React component reference (persists across remounts)
14
+ * @param isIsolated - Whether the bloc is isolated
15
+ * @param providedId - User-provided instance ID (from options)
16
+ * @returns Instance key string or undefined for default
17
+ */
18
+ export declare function generateInstanceKey(componentRef: ComponentRef, isIsolated: boolean, providedId?: string | number): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blac/react",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "license": "MIT",
5
5
  "author": "Brendan Mullins <jsnanigans@gmail.com>",
6
6
  "repository": {
@@ -28,11 +28,7 @@
28
28
  }
29
29
  },
30
30
  "files": [
31
- "dist/index.js",
32
- "dist/index.cjs",
33
- "dist/index.d.ts",
34
- "dist/index.d.cts",
35
- "dist/*.map",
31
+ "dist",
36
32
  "README.md",
37
33
  "LICENSE"
38
34
  ],
@@ -47,7 +43,7 @@
47
43
  "bloc-pattern"
48
44
  ],
49
45
  "dependencies": {
50
- "@blac/adapter": "2.0.4"
46
+ "@blac/adapter": "2.0.5"
51
47
  },
52
48
  "peerDependencies": {
53
49
  "@types/react": "^18.0.0 || ^19.0.0",
@@ -79,15 +75,13 @@
79
75
  "react-dom": "^19.1.1",
80
76
  "tsdown": "^0.15.7",
81
77
  "typescript": "^5.9.2",
78
+ "publint": "^0.3.12",
82
79
  "vitest": "3.2.4",
83
- "@blac/core": "2.0.4"
80
+ "@blac/core": "2.0.5"
84
81
  },
85
82
  "scripts": {
86
83
  "dev": "tsdown --watch",
87
- "build": "pnpm build:js && pnpm build:types && pnpm build:dts",
88
- "build:js": "tsdown",
89
- "build:types": "tsc -p tsconfig.build.json",
90
- "build:dts": "api-extractor run --local && cp dist/index.d.ts dist/index.d.cts && rm -rf dist/.types",
84
+ "build": "tsdown && tsc -p tsconfig.build.json && cp dist/index.d.ts dist/index.d.cts",
91
85
  "clean": "rm -rf dist",
92
86
  "format": "prettier --write \".\"",
93
87
  "lint": "eslint src --ext .ts,.tsx",
@@ -99,6 +93,7 @@
99
93
  "test:compiler": "vitest run --config vitest.config.compiler.ts",
100
94
  "test:watch:compiler": "vitest --watch --config vitest.config.compiler.ts",
101
95
  "test:both": "pnpm test && echo '\n\n=== Running tests WITH React Compiler ===\n' && pnpm test:compiler",
96
+ "verify": "publint",
102
97
  "typecheck": "tsc --noEmit",
103
98
  "deploy": "pnpm publish --access public"
104
99
  }