storion 0.2.3 → 0.3.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 (88) hide show
  1. package/README.md +705 -573
  2. package/dist/async/async.d.ts +87 -0
  3. package/dist/async/async.d.ts.map +1 -0
  4. package/dist/async/index.d.ts +13 -0
  5. package/dist/async/index.d.ts.map +1 -0
  6. package/dist/async/index.js +451 -0
  7. package/dist/async/types.d.ts +275 -0
  8. package/dist/async/types.d.ts.map +1 -0
  9. package/dist/collection.d.ts +42 -0
  10. package/dist/collection.d.ts.map +1 -0
  11. package/dist/core/container.d.ts +33 -2
  12. package/dist/core/container.d.ts.map +1 -1
  13. package/dist/core/createResolver.d.ts +47 -0
  14. package/dist/core/createResolver.d.ts.map +1 -0
  15. package/dist/core/equality.d.ts +23 -3
  16. package/dist/core/equality.d.ts.map +1 -1
  17. package/dist/core/fnWrapper.d.ts +54 -0
  18. package/dist/core/fnWrapper.d.ts.map +1 -0
  19. package/dist/core/pick.d.ts +6 -6
  20. package/dist/core/pick.d.ts.map +1 -1
  21. package/dist/core/store.d.ts +8 -8
  22. package/dist/core/store.d.ts.map +1 -1
  23. package/dist/core/storeContext.d.ts +63 -0
  24. package/dist/core/storeContext.d.ts.map +1 -0
  25. package/dist/devtools/controller.d.ts +4 -0
  26. package/dist/devtools/controller.d.ts.map +1 -0
  27. package/dist/devtools/index.d.ts +16 -0
  28. package/dist/devtools/index.d.ts.map +1 -0
  29. package/dist/devtools/index.js +229 -0
  30. package/dist/devtools/middleware.d.ts +22 -0
  31. package/dist/devtools/middleware.d.ts.map +1 -0
  32. package/dist/devtools/types.d.ts +116 -0
  33. package/dist/devtools/types.d.ts.map +1 -0
  34. package/dist/devtools-panel/DevtoolsPanel.d.ts +17 -0
  35. package/dist/devtools-panel/DevtoolsPanel.d.ts.map +1 -0
  36. package/dist/devtools-panel/components/CompareModal.d.ts +10 -0
  37. package/dist/devtools-panel/components/CompareModal.d.ts.map +1 -0
  38. package/dist/devtools-panel/components/EventEntry.d.ts +14 -0
  39. package/dist/devtools-panel/components/EventEntry.d.ts.map +1 -0
  40. package/dist/devtools-panel/components/EventFilterBar.d.ts +10 -0
  41. package/dist/devtools-panel/components/EventFilterBar.d.ts.map +1 -0
  42. package/dist/devtools-panel/components/EventsTab.d.ts +15 -0
  43. package/dist/devtools-panel/components/EventsTab.d.ts.map +1 -0
  44. package/dist/devtools-panel/components/ResizeHandle.d.ts +8 -0
  45. package/dist/devtools-panel/components/ResizeHandle.d.ts.map +1 -0
  46. package/dist/devtools-panel/components/StoreEntry.d.ts +13 -0
  47. package/dist/devtools-panel/components/StoreEntry.d.ts.map +1 -0
  48. package/dist/devtools-panel/components/StoresTab.d.ts +12 -0
  49. package/dist/devtools-panel/components/StoresTab.d.ts.map +1 -0
  50. package/dist/devtools-panel/components/TabLayout.d.ts +48 -0
  51. package/dist/devtools-panel/components/TabLayout.d.ts.map +1 -0
  52. package/dist/devtools-panel/components/icons.d.ts +27 -0
  53. package/dist/devtools-panel/components/icons.d.ts.map +1 -0
  54. package/dist/devtools-panel/components/index.d.ts +15 -0
  55. package/dist/devtools-panel/components/index.d.ts.map +1 -0
  56. package/dist/devtools-panel/hooks.d.ts +23 -0
  57. package/dist/devtools-panel/hooks.d.ts.map +1 -0
  58. package/dist/devtools-panel/index.d.ts +25 -0
  59. package/dist/devtools-panel/index.d.ts.map +1 -0
  60. package/dist/devtools-panel/index.js +3326 -0
  61. package/dist/devtools-panel/mount.d.ts +41 -0
  62. package/dist/devtools-panel/mount.d.ts.map +1 -0
  63. package/dist/devtools-panel/styles.d.ts +50 -0
  64. package/dist/devtools-panel/styles.d.ts.map +1 -0
  65. package/dist/devtools-panel/types.d.ts +15 -0
  66. package/dist/devtools-panel/types.d.ts.map +1 -0
  67. package/dist/devtools-panel/utils.d.ts +21 -0
  68. package/dist/devtools-panel/utils.d.ts.map +1 -0
  69. package/dist/index.d.ts +6 -1
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/is.d.ts +69 -0
  72. package/dist/is.d.ts.map +1 -0
  73. package/dist/react/create.d.ts +1 -1
  74. package/dist/react/index.d.ts +1 -0
  75. package/dist/react/index.d.ts.map +1 -1
  76. package/dist/react/index.js +209 -33
  77. package/dist/react/useLocalStore.d.ts.map +1 -1
  78. package/dist/react/useStore.d.ts +2 -2
  79. package/dist/react/useStore.d.ts.map +1 -1
  80. package/dist/react/withStore.d.ts +140 -0
  81. package/dist/react/withStore.d.ts.map +1 -0
  82. package/dist/{index-rLf6DusB.js → store-XP2pujaJ.js} +537 -740
  83. package/dist/storion.js +740 -9
  84. package/dist/trigger.d.ts +40 -0
  85. package/dist/trigger.d.ts.map +1 -0
  86. package/dist/types.d.ts +516 -50
  87. package/dist/types.d.ts.map +1 -1
  88. package/package.json +13 -1
@@ -0,0 +1,140 @@
1
+ import { ReactNode, FC, Ref, ForwardRefRenderFunction, ForwardRefExoticComponent, RefAttributes } from 'react';
2
+ import { Equality, SelectorContext } from '../types';
3
+
4
+ export interface WithStoreOptions<TOutput extends object> {
5
+ displayName?: string;
6
+ /**
7
+ * Custom equality function for comparing hook output.
8
+ * Controls when the memoized render function re-renders.
9
+ *
10
+ * Note: To control input props equality, wrap the final component with memo().
11
+ */
12
+ equality?: Equality<TOutput>;
13
+ }
14
+ /**
15
+ * Hook function that receives SelectorContext and props.
16
+ *
17
+ * Can use:
18
+ * - Store access via ctx.get()
19
+ * - React hooks (useState, useEffect, useMemo, etc.)
20
+ * - Return any values including functions
21
+ *
22
+ * The hook is called during render phase, so all React hooks rules apply.
23
+ *
24
+ * ⚠️ Limitation: Cannot use React hooks inside pick() callbacks:
25
+ * ```tsx
26
+ * // ❌ DON'T: React hooks inside pick callback
27
+ * const value = ctx.pick(store, state => {
28
+ * const [x] = useState(0); // ❌ Error: Invalid hook call
29
+ * return state.value + x;
30
+ * });
31
+ *
32
+ * // ✅ DO: React hooks outside pick
33
+ * const [x] = useState(0);
34
+ * const value = ctx.pick(store, state => state.value + x);
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * const Component = withStore(
40
+ * (ctx, { userId }) => {
41
+ * const [user] = ctx.get(userStore);
42
+ * const [count, setCount] = useState(0);
43
+ *
44
+ * return {
45
+ * userName: user.name,
46
+ * count,
47
+ * increment: () => setCount(c => c + 1), // ✅ Can return functions
48
+ * };
49
+ * },
50
+ * ({ userName, count, increment }) => (
51
+ * <div onClick={increment}>{userName}: {count}</div>
52
+ * )
53
+ * );
54
+ * ```
55
+ */
56
+ export type WithStoreHook<TInput extends object, TOutput extends object> = (context: SelectorContext, props: TInput) => TOutput;
57
+ /**
58
+ * Render function without ref support.
59
+ */
60
+ export type WithStoreRender<TOutput extends object> = (props: TOutput) => ReactNode;
61
+ /**
62
+ * Render function with ref support.
63
+ */
64
+ export type WithStoreRenderWithRef<TOutput extends object, TRef = unknown> = (props: TOutput, ref: Ref<TRef>) => ReactNode;
65
+ /**
66
+ * Testing utilities exposed on components created with withStore(hook, render)
67
+ */
68
+ export interface WithStoreTestUtils<TInput extends object, TOutput extends object> {
69
+ /**
70
+ * The hook function for testing.
71
+ * Call this to test the hook logic independently.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const result = MyComponent.use(mockCtx, { userId: '123' });
76
+ * expect(result.name).toBe('John');
77
+ * ```
78
+ */
79
+ use: WithStoreHook<TInput, TOutput>;
80
+ /**
81
+ * The render function for testing.
82
+ * Call this to test the render output independently.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * const element = MyComponent.render({ name: 'John' });
87
+ * // Or with testing-library:
88
+ * render(MyComponent.render({ name: 'John' }));
89
+ * ```
90
+ */
91
+ render: (props: TOutput) => ReactNode;
92
+ }
93
+ /**
94
+ * Testing utilities exposed on HOCs created with withStore(hook)
95
+ */
96
+ export interface WithStoreHOCTestUtils<TInput extends object, TOutput extends object> {
97
+ /**
98
+ * The hook function for testing.
99
+ * Call this to test the hook logic independently.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const result = withUserData.use(mockCtx, { userId: '123' });
104
+ * expect(result.name).toBe('John');
105
+ * ```
106
+ */
107
+ use: WithStoreHook<TInput, TOutput>;
108
+ }
109
+ /**
110
+ * Component type with testing utilities (no ref)
111
+ */
112
+ export type WithStoreComponent<TInput extends object, TOutput extends object> = FC<TInput> & WithStoreTestUtils<TInput, TOutput>;
113
+ /**
114
+ * Component type with testing utilities (with ref)
115
+ */
116
+ export type WithStoreComponentWithRef<TInput extends object, TOutput extends object, TRef = unknown> = ForwardRefExoticComponent<TInput & RefAttributes<TRef>> & WithStoreTestUtils<TInput, TOutput>;
117
+ /**
118
+ * HOC type with testing utilities
119
+ */
120
+ export type WithStoreHOC<TInput extends object, TOutput extends object> = {
121
+ (component: FC<TOutput>): FC<TInput>;
122
+ <TRef = unknown>(component: ForwardRefRenderFunction<TRef, TOutput>): ForwardRefExoticComponent<TInput & RefAttributes<TRef>>;
123
+ } & WithStoreHOCTestUtils<TInput, TOutput>;
124
+ /**
125
+ * Direct mode: Create component with hook and render function (no ref).
126
+ * Returns component with `use` and `render` properties for testing.
127
+ */
128
+ export declare function withStore<TInput extends object, TOutput extends object>(hook: WithStoreHook<TInput, TOutput>, render: WithStoreRender<TOutput>, options?: WithStoreOptions<TOutput>): WithStoreComponent<TInput, TOutput>;
129
+ /**
130
+ * Direct mode: Create component with hook and render function (with ref).
131
+ * Automatically detected when render function has 2 parameters.
132
+ * Returns component with `use` and `render` properties for testing.
133
+ */
134
+ export declare function withStore<TInput extends object, TOutput extends object, TRef = unknown>(hook: WithStoreHook<TInput, TOutput>, render: WithStoreRenderWithRef<TOutput, TRef>, options?: WithStoreOptions<TOutput>): WithStoreComponentWithRef<TInput, TOutput, TRef>;
135
+ /**
136
+ * HOC mode: Create HOC that transforms props using hook.
137
+ * Returns a function that accepts a component, with `use` property for testing.
138
+ */
139
+ export declare function withStore<TInput extends object, TOutput extends object>(hook: WithStoreHook<TInput, TOutput>, options?: WithStoreOptions<TOutput>): WithStoreHOC<TInput, T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