cogsbox-state 0.5.482 → 0.5.483

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.
@@ -39,6 +39,7 @@ export type ClientActivityEvent = {
39
39
  type PluginRegistryStore = {
40
40
  stateHandlers: Map<string, StateObject<any>>; // stateKey -> handler
41
41
  registerStateHandler: (stateKey: string, handler: StateObject<any>) => void;
42
+ unregisterStateHandler: (stateKey: string) => void;
42
43
  registeredPlugins: readonly CogsPlugin<any, any, any, any, any>[];
43
44
  setRegisteredPlugins: (
44
45
  plugins: readonly CogsPlugin<any, any, any, any, any>[]
@@ -78,7 +79,12 @@ export const pluginStore = create<PluginRegistryStore>((set, get) => ({
78
79
  set((state) => {
79
80
  const newMap = new Map(state.stateHandlers);
80
81
  newMap.set(stateKey, handler);
81
- console.log('addign handler', stateKey, handler);
82
+ return { stateHandlers: newMap };
83
+ }),
84
+ unregisterStateHandler: (stateKey) =>
85
+ set((state) => {
86
+ const newMap = new Map(state.stateHandlers);
87
+ newMap.delete(stateKey);
82
88
  return { stateHandlers: newMap };
83
89
  }),
84
90
  registeredPlugins: [],
package/src/plugins.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import type React from 'react';
2
+ import type { ReactNode, RefObject } from 'react';
3
3
  import { StateObject, UpdateTypeDetail } from './CogsState';
4
4
  import {
5
5
  getGlobalStore,
@@ -7,7 +7,6 @@ import {
7
7
  setAllFieldsDisabled,
8
8
  } from './store';
9
9
  import { ClientActivityEvent } from './pluginStore';
10
- import { RefObject } from 'react';
11
10
 
12
11
  type Prettify<T> = { [K in keyof T]: T[K] } & {};
13
12
 
@@ -228,7 +227,7 @@ export type FormWrapperParams<
228
227
  TFieldMetaData,
229
228
  TStateSlice = any,
230
229
  > = ScopedMetadataMethods<TFieldMetaData> & {
231
- element: React.ReactNode;
230
+ element: ReactNode;
232
231
  path: string[];
233
232
  stateKey: string;
234
233
  options: TOptions;
@@ -307,7 +306,7 @@ export type CogsPlugin<
307
306
  TFieldMetaData,
308
307
  any
309
308
  >
310
- ) => React.ReactNode;
309
+ ) => ReactNode;
311
310
 
312
311
  chainMethods?: TChainMethods;
313
312
  };
@@ -602,7 +601,7 @@ export type PluginFormWrapperFn<
602
601
  TFieldMetaData,
603
602
  any
604
603
  >
605
- ) => React.ReactNode;
604
+ ) => ReactNode;
606
605
 
607
606
  export type CogsPluginBuilder<
608
607
  TName extends string,
@@ -774,7 +773,7 @@ export type CogsPluginBuilder<
774
773
  true,
775
774
  TNewState
776
775
  >;
777
- });
776
+ });
778
777
 
779
778
  export type CreatePluginStart<
780
779
  TName extends string,