@sqlrooms/room-store 0.26.0-rc.5 → 0.26.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 CHANGED
@@ -14,10 +14,12 @@ The `RoomStore` is a Zustand store that holds the entire state of a room. It is
14
14
 
15
15
  ### RoomState
16
16
 
17
- The `RoomState` is the object that defines the shape of the store. It has two main properties:
17
+ The `RoomState` is the object that defines the shape of the store. It includes state from the base room shell slice and any additional slices you add:
18
18
 
19
- - `config`: This holds the configuration of the room that is persisted. This is defined by a `zod` schema, often extending the `BaseRoomConfig` from `@sqlrooms/room-config`.
19
+ - `room.config`: This holds the configuration of the room that is persisted. This is defined by a `zod` schema, often extending the `BaseRoomConfig` from `@sqlrooms/room-config`.
20
20
  - `room`: This holds the client-side state of the room, such as task progress, and provides actions for interacting with the room.
21
+ - `db`: DuckDB database state and methods
22
+ - `layout`: Layout configuration and panel definitions
21
23
 
22
24
  ### Slices
23
25
 
@@ -31,53 +33,49 @@ Here's an example of how to create a room store with a custom feature slice.
31
33
  import {
32
34
  createRoomStore,
33
35
  createRoomShellSlice,
34
- RoomState,
36
+ RoomShellSliceState,
35
37
  } from '@sqlrooms/room-store';
36
- import {BaseRoomConfig} from '@sqlrooms/room-config';
37
- import {z} from 'zod';
38
38
  import {StateCreator} from 'zustand';
39
39
 
40
- // 1. Define your persisted room configuration schema using Zod.
41
- // This extends the base config with a custom property.
42
- export const MyRoomConfig = BaseRoomConfig.extend({
43
- defaultChartType: z.enum(['bar', 'line', 'scatter']).default('bar'),
44
- });
45
- export type MyRoomConfig = z.infer<typeof MyRoomConfig>;
46
-
47
- // 2. Define the state and actions for your custom feature slice.
40
+ // 1. Define the state and actions for your custom feature slice.
48
41
  export interface MyFeatureSlice {
49
42
  activeChartId: string | null;
50
43
  setActiveChartId: (id: string | null) => void;
51
44
  }
52
45
 
53
- // 3. Create your custom slice.
46
+ // 2. Create your custom slice.
54
47
  export const createMyFeatureSlice: StateCreator<MyFeatureSlice> = (set) => ({
55
48
  activeChartId: null,
56
49
  setActiveChartId: (id) => set({activeChartId: id}),
57
50
  });
58
51
 
59
- // 4. Define the full state of your room, combining the base RoomState
52
+ // 3. Define the full state of your room, combining the base RoomShellSliceState
60
53
  // with your custom slice's state.
61
- export type MyRoomState = RoomState<MyRoomConfig> & MyFeatureSlice;
62
-
63
- // 5. Create the room store by composing the base slice and your custom slice.
64
- export const {roomStore, useRoomStore} = createRoomStore<
65
- MyRoomConfig,
66
- MyRoomState
67
- >((set, get, store) => ({
68
- ...createRoomShellSlice<MyRoomConfig>({
69
- config: {
70
- // You can provide initial values for your config here
71
- title: 'My First Room',
72
- defaultChartType: 'line',
73
- // other properties from BaseRoomConfig will have defaults
74
- },
75
- room: {},
76
- })(set, get, store),
77
-
78
- // Add your custom slice to the store
79
- ...createMyFeatureSlice(set, get, store),
80
- }));
54
+ export type MyRoomState = RoomShellSliceState & MyFeatureSlice;
55
+
56
+ // 4. Create the room store by composing the base slice and your custom slice.
57
+ export const {roomStore, useRoomStore} = createRoomStore<MyRoomState>(
58
+ (set, get, store) => ({
59
+ ...createRoomShellSlice({
60
+ config: {
61
+ // You can provide initial values for your config here
62
+ title: 'My First Room',
63
+ dataSources: [],
64
+ },
65
+ layout: {
66
+ config: {
67
+ // Layout configuration
68
+ },
69
+ panels: {
70
+ // Panel definitions
71
+ },
72
+ },
73
+ })(set, get, store),
74
+
75
+ // Add your custom slice to the store
76
+ ...createMyFeatureSlice(set, get, store),
77
+ }),
78
+ );
81
79
 
82
80
  export {roomStore, useRoomStore};
83
81
  ```
@@ -107,7 +105,7 @@ You can use the `useRoomStore` hook returned by `createRoomStore` to access the
107
105
  import {useRoomStore} from './my-room-store';
108
106
 
109
107
  function RoomTitle() {
110
- const title = useRoomStore((state) => state.config.title);
108
+ const title = useRoomStore((state) => state.room.config.title);
111
109
  const activeChartId = useRoomStore((state) => state.activeChartId);
112
110
  const setActiveChartId = useRoomStore((state) => state.setActiveChartId);
113
111
 
@@ -11,7 +11,7 @@ export type BaseRoomStoreState = {
11
11
  captureException: (exception: unknown, captureContext?: unknown) => void;
12
12
  };
13
13
  };
14
- export type RoomStore<RS extends BaseRoomStoreState> = StoreApi<RS>;
14
+ export type BaseRoomStore<RS extends BaseRoomStoreState> = StoreApi<RS>;
15
15
  export type CreateBaseRoomSliceProps = {
16
16
  captureException?: BaseRoomStoreState['room']['captureException'];
17
17
  };
@@ -45,4 +45,4 @@ export declare function createRoomStoreCreator<RS extends BaseRoomStoreState>():
45
45
  };
46
46
  export declare function isRoomSliceWithInitialize(slice: unknown): slice is Required<Pick<SliceFunctions, 'initialize'>>;
47
47
  export declare function isRoomSliceWithDestroy(slice: unknown): slice is Required<Pick<SliceFunctions, 'destroy'>>;
48
- //# sourceMappingURL=RoomStore.d.ts.map
48
+ //# sourceMappingURL=BaseRoomStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseRoomStore.d.ts","sourceRoot":"","sources":["../src/BaseRoomStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAwB,MAAM,SAAS,CAAC;AAEtE,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO,CAAC;QACrB,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,gBAAgB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;KAC1E,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,kBAAkB,IAAI,QAAQ,CAA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AC,cAAc,EAAE,YAAY,CAAC,CAAC,CAOvD;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAOpD"}
@@ -94,4 +94,4 @@ export function isRoomSliceWithDestroy(slice) {
94
94
  'destroy' in slice &&
95
95
  typeof slice.destroy === 'function');
96
96
  }
97
- //# sourceMappingURL=RoomStore.js.map
97
+ //# sourceMappingURL=BaseRoomStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseRoomStore.js","sourceRoot":"","sources":["../src/BaseRoomStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAyB,WAAW,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAsBtE,MAAM,UAAU,mBAAmB,CACjC,KAAgC;IAEhC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7B,IAAI,EAAE;YACJ,WAAW,EAAE,KAAK;YAClB,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;qBAC5B,MAAM,CAAC,yBAAyB,CAAC;qBACjC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CACpC,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;qBAC5B,MAAM,CAAC,sBAAsB,CAAC;qBAC9B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CACjC,CAAC;YACJ,CAAC;YACD,gBAAgB,EACd,K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,+CAA+C;wBAC/C,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CACvB,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;4BACvB,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;wBAChC,CAAC,CAAC,CACH,CAAC;oBACJ,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;oBAChD,CAAC;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CACV,uFAAuF,CACxF,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,SAAS,YAAY,CAAI,QAA0B;YACjD,IAAI,CAAC,KAAK;gBACR,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;YACJ,OAAO,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,EAAC,eAAe,EAAE,YAAY,EAAC,CAAC;IACzC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAO,KAAK,CAAC,UAAU,KAAK,UAAU,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC","sourcesContent":["import {produce} from 'immer';\nimport {StateCreator, StoreApi, createStore, useStore} from 'zustand';\n\nexport interface SliceFunctions {\n initialize?: () => Promise<void>;\n destroy?: () => Promise<void>;\n}\n\nexport type BaseRoomStoreState = {\n room: {\n initialized: boolean;\n initialize: () => Promise<void>;\n destroy: () => Promise<void>;\n captureException: (exception: unknown, captureContext?: unknown) => void;\n };\n};\n\nexport type BaseRoomStore<RS extends BaseRoomStoreState> = StoreApi<RS>;\n\nexport type CreateBaseRoomSliceProps = {\n captureException?: BaseRoomStoreState['room']['captureException'];\n};\n\nexport function createBaseRoomSlice(\n props?: CreateBaseRoomSliceProps,\n): StateCreator<BaseRoomStoreState> {\n return (_set, _get, store) => ({\n room: {\n initialized: false,\n initialize: async () => {\n await Promise.all(\n Object.values(store.getState())\n .filter(isRoomSliceWithInitialize)\n .map((slice) => slice.initialize),\n );\n },\n destroy: async () => {\n await Promise.all(\n Object.values(store.getState())\n .filter(isRoomSliceWithDestroy)\n .map((slice) => slice.destroy),\n );\n },\n captureException:\n props?.captureException ??\n ((exception: unknown) => console.error(exception)),\n },\n });\n}\n/** @deprecated Use createBaseRoomSlice instead */\nexport const createRoomSlice = createBaseRoomSlice;\n\nexport function createSlice<\n SliceState,\n StoreState extends SliceState = BaseRoomStoreState & SliceState,\n>(\n sliceCreator: (...args: Parameters<StateCreator<StoreState>>) => SliceState,\n): StateCreator<SliceState> {\n return (set, get, store) =>\n sliceCreator(set, get as () => StoreState, store as StoreApi<StoreState>);\n}\n\n/** @deprecated Use createSlice instead */\nexport const createBaseSlice = createSlice;\n\n/**\n * Create a room store with custom fields and methods\n * @param initialState - The initial state and config for the room\n * @param sliceCreators - The slices to add to the room store\n * @returns The room store and a hook for accessing the room store\n */\nexport function createRoomStore<RS extends BaseRoomStoreState>(\n stateCreator: StateCreator<RS>,\n) {\n const factory = createRoomStoreCreator<BaseRoomStoreState & RS>();\n const storeCreator = factory(() => stateCreator);\n const roomStore = storeCreator.createRoomStore();\n\n function useRoomStore<T>(selector: (state: RS) => T): T {\n return storeCreator.useRoomStore(selector);\n }\n\n return {roomStore, useRoomStore};\n}\n\n/**\n * Factory to create a room store creator with custom params.\n *\n * @template RS - Room state type\n * @param stateCreatorFactory - A function that takes params and returns a Zustand state creator\n * @returns An object with createRoomStore(params) and useRoomStore(selector)\n *\n */\nexport function createRoomStoreCreator<RS extends BaseRoomStoreState>() {\n return function <TFactory extends (...args: any[]) => StateCreator<RS>>(\n stateCreatorFactory: TFactory,\n ): {\n createRoomStore: (...args: Parameters<TFactory>) => StoreApi<RS>;\n useRoomStore: <T>(selector: (state: RS) => T) => T;\n } {\n let store: StoreApi<RS> | undefined;\n\n function createRoomStore(...args: Parameters<TFactory>): StoreApi<RS> {\n store = createStore(stateCreatorFactory(...args));\n if (typeof window !== 'undefined') {\n (async () => {\n try {\n // Initialize the room\n await store.getState().room.initialize();\n // Set initialized to true after initialization\n store.setState((state) =>\n produce(state, (draft) => {\n draft.room.initialized = true;\n }),\n );\n } catch (error) {\n store.getState().room.captureException(error);\n }\n })();\n } else {\n console.warn(\n 'Skipping room store initialization. The room store should only be used on the client.',\n );\n }\n return store;\n }\n\n function useRoomStore<T>(selector: (state: RS) => T): T {\n if (!store)\n throw new Error(\n 'Room store not initialized. Call createRoomStore first.',\n );\n return useStore(store, selector);\n }\n\n return {createRoomStore, useRoomStore};\n };\n}\n\nexport function isRoomSliceWithInitialize(\n slice: unknown,\n): slice is Required<Pick<SliceFunctions, 'initialize'>> {\n return (\n typeof slice === 'object' &&\n slice !== null &&\n 'initialize' in slice &&\n typeof slice.initialize === 'function'\n );\n}\n\nexport function isRoomSliceWithDestroy(\n slice: unknown,\n): slice is Required<Pick<SliceFunctions, 'destroy'>> {\n return (\n typeof slice === 'object' &&\n slice !== null &&\n 'destroy' in slice &&\n typeof slice.destroy === 'function'\n );\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { BaseRoomStoreState, RoomStore } from './RoomStore';
3
- export declare const RoomStateContext: React.Context<RoomStore<BaseRoomStoreState> | null>;
2
+ import { BaseRoomStoreState, BaseRoomStore } from './BaseRoomStore';
3
+ export declare const RoomStateContext: React.Context<BaseRoomStore<BaseRoomStoreState> | null>;
4
4
  export type RoomStateProviderProps<RS extends BaseRoomStoreState> = React.PropsWithChildren<{
5
- roomStore?: RoomStore<RS>;
5
+ roomStore?: BaseRoomStore<RS>;
6
6
  }>;
7
7
  export declare function RoomStateProvider<RS extends BaseRoomStoreState>({ children, roomStore, }: RoomStateProviderProps<RS>): ReactNode;
8
8
  export declare function useBaseRoomStore<RS extends object, T>(selector: (state: RS & BaseRoomStoreState) => T): T;
@@ -1 +1 @@
1
- {"version":3,"file":"RoomStateProvider.d.ts","sourceRoot":"","sources":["../src/RoomStateProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAgB,SAAS,EAAa,MAAM,OAAO,CAAC;AAElE,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAI1D,eAAO,MAAM,gBAAgB,qDAC8B,CAAC;AAE5D,MAAM,MAAM,sBAAsB,CAAC,EAAE,SAAS,kBAAkB,IAC9D,KAAK,CAAC,iBAAiB,CAAC;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;CAC3B,CAAC,CAAC;AAEL,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,kBAAkB,EAAE,EAC/D,QAAQ,EACR,SAAS,GACV,EAAE,sBAAsB,CAAC,EAAE,CAAC,GAAG,SAAS,CAMxC;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,EACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,kBAAkB,KAAK,CAAC,GAC9C,CAAC,CASH"}
1
+ {"version":3,"file":"RoomStateProvider.d.ts","sourceRoot":"","sources":["../src/RoomStateProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAgB,SAAS,EAAa,MAAM,OAAO,CAAC;AAElE,OAAO,EAAC,kBAAkB,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AA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ourcesContent":["import React, {createContext, ReactNode, useContext} from 'react';\nimport {StoreApi, useStore} from 'zustand';\nimport {BaseRoomStoreState, RoomStore} from './RoomStore';\n\n// See https://docs.pmnd.rs/zustand/guides/initialize-state-with-props\n\nexport const RoomStateContext =\n createContext<RoomStore<BaseRoomStoreState> | null>(null);\n\nexport type RoomStateProviderProps<RS extends BaseRoomStoreState> =\n React.PropsWithChildren<{\n roomStore?: RoomStore<RS>;\n }>;\n\nexport function RoomStateProvider<RS extends BaseRoomStoreState>({\n children,\n roomStore,\n}: RoomStateProviderProps<RS>): ReactNode {\n return (\n <RoomStateContext.Provider value={roomStore ?? null}>\n {children}\n </RoomStateContext.Provider>\n );\n}\n\nexport function useBaseRoomStore<RS extends object, T>(\n selector: (state: RS & BaseRoomStoreState) => T,\n): T {\n const store = useContext(RoomStateContext);\n if (!store) {\n throw new Error('Missing RoomStateProvider in the tree');\n }\n return useStore(\n store as unknown as StoreApi<RS & BaseRoomStoreState>,\n selector,\n );\n}\n"]}
1
+ {"version":3,"file":"RoomStateProvider.js","sourceRoot":"","sources":["../src/RoomStateProvider.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAC,aAAa,EAAa,UAAU,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,EAAW,QAAQ,EAAC,MAAM,SAAS,CAAC;AAG3C,sEAAsE;AAEtE,MAAM,CAAC,MAAM,gBAAgB,GAC3B,aAAa,CAA2C,IAAI,CAAC,CAAC;AAOhE,MAAM,UAAU,iBAAiB,CAAgC,EAC/D,QAAQ,EACR,SAAS,GACkB;IAC3B,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAAI,IAAI,YAChD,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,QAA+C;IAE/C,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,QAAQ,CACb,KAAqD,EACrD,QAAQ,CACT,CAAC;AACJ,CAAC","sourcesContent":["import React, {createContext, ReactNode, useContext} from 'react';\nimport {StoreApi, useStore} from 'zustand';\nimport {BaseRoomStoreState, BaseRoomStore} from './BaseRoomStore';\n\n// See https://docs.pmnd.rs/zustand/guides/initialize-state-with-props\n\nexport const RoomStateContext =\n createContext<BaseRoomStore<BaseRoomStoreState> | null>(null);\n\nexport type RoomStateProviderProps<RS extends BaseRoomStoreState> =\n React.PropsWithChildren<{\n roomStore?: BaseRoomStore<RS>;\n }>;\n\nexport function RoomStateProvider<RS extends BaseRoomStoreState>({\n children,\n roomStore,\n}: RoomStateProviderProps<RS>): ReactNode {\n return (\n <RoomStateContext.Provider value={roomStore ?? null}>\n {children}\n </RoomStateContext.Provider>\n );\n}\n\nexport function useBaseRoomStore<RS extends object, T>(\n selector: (state: RS & BaseRoomStoreState) => T,\n): T {\n const store = useContext(RoomStateContext);\n if (!store) {\n throw new Error('Missing RoomStateProvider in the tree');\n }\n return useStore(\n store as unknown as StoreApi<RS & BaseRoomStoreState>,\n selector,\n );\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
  export { RoomStateContext, RoomStateProvider, useBaseRoomStore, type RoomStateProviderProps, } from './RoomStateProvider';
6
- export { createBaseRoomSlice, createBaseSlice, createSlice, createRoomSlice, createRoomStore, createRoomStoreCreator, isRoomSliceWithDestroy, isRoomSliceWithInitialize, type BaseRoomStoreState, type CreateBaseRoomSliceProps, type RoomStore, } from './RoomStore';
6
+ export { createBaseRoomSlice, createBaseSlice, createSlice, createRoomSlice, createRoomStore, createRoomStoreCreator, isRoomSliceWithDestroy, isRoomSliceWithInitialize, type BaseRoomStoreState, type CreateBaseRoomSliceProps, type BaseRoomStore, } from './BaseRoomStore';
7
7
  export { createPersistHelpers } from './createPersistHelpers';
8
8
  export type { StateCreator, StoreApi } from 'zustand';
9
9
  export * from '@sqlrooms/room-config';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEpD,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEpD,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
  export { RoomStateContext, RoomStateProvider, useBaseRoomStore, } from './RoomStateProvider';
6
- export { createBaseRoomSlice, createBaseSlice, createSlice, createRoomSlice, createRoomStore, createRoomStoreCreator, isRoomSliceWithDestroy, isRoomSliceWithInitialize, } from './RoomStore';
6
+ export { createBaseRoomSlice, createBaseSlice, createSlice, createRoomSlice, createRoomStore, createRoomStoreCreator, isRoomSliceWithDestroy, isRoomSliceWithInitialize, } from './BaseRoomStore';
7
7
  export { createPersistHelpers } from './createPersistHelpers';
8
8
  export * from '@sqlrooms/room-config';
9
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAI1B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAG5D,cAAc,uBAAuB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {\n RoomStateContext,\n RoomStateProvider,\n useBaseRoomStore,\n type RoomStateProviderProps,\n} from './RoomStateProvider';\n\nexport {\n createBaseRoomSlice,\n createBaseSlice,\n createSlice,\n createRoomSlice,\n createRoomStore,\n createRoomStoreCreator,\n isRoomSliceWithDestroy,\n isRoomSliceWithInitialize,\n type BaseRoomStoreState,\n type CreateBaseRoomSliceProps,\n type RoomStore,\n} from './RoomStore';\n\nexport {createPersistHelpers} from './createPersistHelpers';\nexport type {StateCreator, StoreApi} from 'zustand';\n\nexport * from '@sqlrooms/room-config';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAI1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAG5D,cAAc,uBAAuB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {\n RoomStateContext,\n RoomStateProvider,\n useBaseRoomStore,\n type RoomStateProviderProps,\n} from './RoomStateProvider';\n\nexport {\n createBaseRoomSlice,\n createBaseSlice,\n createSlice,\n createRoomSlice,\n createRoomStore,\n createRoomStoreCreator,\n isRoomSliceWithDestroy,\n isRoomSliceWithInitialize,\n type BaseRoomStoreState,\n type CreateBaseRoomSliceProps,\n type BaseRoomStore,\n} from './BaseRoomStore';\n\nexport {createPersistHelpers} from './createPersistHelpers';\nexport type {StateCreator, StoreApi} from 'zustand';\n\nexport * from '@sqlrooms/room-config';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlrooms/room-store",
3
- "version": "0.26.0-rc.5",
3
+ "version": "0.26.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@sqlrooms/room-config": "0.26.0-rc.5",
21
+ "@sqlrooms/room-config": "0.26.0",
22
22
  "immer": "^10.1.3",
23
23
  "zod": "^4.1.8",
24
24
  "zustand": "^5.0.8"
@@ -33,5 +33,5 @@
33
33
  "typecheck": "tsc --noEmit",
34
34
  "typedoc": "typedoc"
35
35
  },
36
- "gitHead": "dc1c3b765718c8748aa11cce3cc83f907d3e5963"
36
+ "gitHead": "3376e76ddfa3c54097b79a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AE,YAAY,EAAC,CAAC;IACzC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAO,KAAK,CAAC,UAAU,KAAK,UAAU,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC","sourcesContent":["import {produce} from 'immer';\nimport {StateCreator, StoreApi, createStore, useStore} from 'zustand';\n\nexport interface SliceFunctions {\n initialize?: () => Promise<void>;\n destroy?: () => Promise<void>;\n}\n\nexport type BaseRoomStoreState = {\n room: {\n initialized: boolean;\n initialize: () => Promise<void>;\n destroy: () => Promise<void>;\n captureException: (exception: unknown, captureContext?: unknown) => void;\n };\n};\n\nexport type RoomStore<RS extends BaseRoomStoreState> = StoreApi<RS>;\n\nexport type CreateBaseRoomSliceProps = {\n captureException?: BaseRoomStoreState['room']['captureException'];\n};\n\nexport function createBaseRoomSlice(\n props?: CreateBaseRoomSliceProps,\n): StateCreator<BaseRoomStoreState> {\n return (_set, _get, store) => ({\n room: {\n initialized: false,\n initialize: async () => {\n await Promise.all(\n Object.values(store.getState())\n .filter(isRoomSliceWithInitialize)\n .map((slice) => slice.initialize),\n );\n },\n destroy: async () => {\n await Promise.all(\n Object.values(store.getState())\n .filter(isRoomSliceWithDestroy)\n .map((slice) => slice.destroy),\n );\n },\n captureException:\n props?.captureException ??\n ((exception: unknown) => console.error(exception)),\n },\n });\n}\n/** @deprecated Use createBaseRoomSlice instead */\nexport const createRoomSlice = createBaseRoomSlice;\n\nexport function createSlice<\n SliceState,\n StoreState extends SliceState = BaseRoomStoreState & SliceState,\n>(\n sliceCreator: (...args: Parameters<StateCreator<StoreState>>) => SliceState,\n): StateCreator<SliceState> {\n return (set, get, store) =>\n sliceCreator(set, get as () => StoreState, store as StoreApi<StoreState>);\n}\n\n/** @deprecated Use createSlice instead */\nexport const createBaseSlice = createSlice;\n\n/**\n * Create a room store with custom fields and methods\n * @param initialState - The initial state and config for the room\n * @param sliceCreators - The slices to add to the room store\n * @returns The room store and a hook for accessing the room store\n */\nexport function createRoomStore<RS extends BaseRoomStoreState>(\n stateCreator: StateCreator<RS>,\n) {\n const factory = createRoomStoreCreator<BaseRoomStoreState & RS>();\n const storeCreator = factory(() => stateCreator);\n const roomStore = storeCreator.createRoomStore();\n\n function useRoomStore<T>(selector: (state: RS) => T): T {\n return storeCreator.useRoomStore(selector);\n }\n\n return {roomStore, useRoomStore};\n}\n\n/**\n * Factory to create a room store creator with custom params.\n *\n * @template RS - Room state type\n * @param stateCreatorFactory - A function that takes params and returns a Zustand state creator\n * @returns An object with createRoomStore(params) and useRoomStore(selector)\n *\n */\nexport function createRoomStoreCreator<RS extends BaseRoomStoreState>() {\n return function <TFactory extends (...args: any[]) => StateCreator<RS>>(\n stateCreatorFactory: TFactory,\n ): {\n createRoomStore: (...args: Parameters<TFactory>) => StoreApi<RS>;\n useRoomStore: <T>(selector: (state: RS) => T) => T;\n } {\n let store: StoreApi<RS> | undefined;\n\n function createRoomStore(...args: Parameters<TFactory>): StoreApi<RS> {\n store = createStore(stateCreatorFactory(...args));\n if (typeof window !== 'undefined') {\n (async () => {\n try {\n // Initialize the room\n await store.getState().room.initialize();\n // Set initialized to true after initialization\n store.setState((state) =>\n produce(state, (draft) => {\n draft.room.initialized = true;\n }),\n );\n } catch (error) {\n store.getState().room.captureException(error);\n }\n })();\n } else {\n console.warn(\n 'Skipping room store initialization. The room store should only be used on the client.',\n );\n }\n return store;\n }\n\n function useRoomStore<T>(selector: (state: RS) => T): T {\n if (!store)\n throw new Error(\n 'Room store not initialized. Call createRoomStore first.',\n );\n return useStore(store, selector);\n }\n\n return {createRoomStore, useRoomStore};\n };\n}\n\nexport function isRoomSliceWithInitialize(\n slice: unknown,\n): slice is Required<Pick<SliceFunctions, 'initialize'>> {\n return (\n typeof slice === 'object' &&\n slice !== null &&\n 'initialize' in slice &&\n typeof slice.initialize === 'function'\n );\n}\n\nexport function isRoomSliceWithDestroy(\n slice: unknown,\n): slice is Required<Pick<SliceFunctions, 'destroy'>> {\n return (\n typeof slice === 'object' &&\n slice !== null &&\n 'destroy' in slice &&\n typeof slice.destroy === 'function'\n );\n}\n"]}