@sqlrooms/layout 0.26.0-rc.4 → 0.26.0-rc.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.
@@ -1,9 +1,7 @@
1
- import { RoomState } from '@sqlrooms/room-store';
2
- import { BaseRoomConfig } from '@sqlrooms/room-config';
3
- import { z } from 'zod';
1
+ import { LayoutConfig } from '@sqlrooms/layout-config';
4
2
  import React from 'react';
3
+ import { z } from 'zod';
5
4
  import { StateCreator } from 'zustand';
6
- import { LayoutConfig } from '@sqlrooms/layout-config';
7
5
  export type RoomPanelInfo = {
8
6
  title?: string;
9
7
  icon?: React.ComponentType<{
@@ -12,24 +10,29 @@ export type RoomPanelInfo = {
12
10
  component: React.ComponentType;
13
11
  placement: 'sidebar' | 'sidebar-bottom' | 'main' | 'top-bar';
14
12
  };
15
- export declare const LayoutSliceConfig: z.ZodObject<{
16
- layout: z.ZodDefault<z.ZodAny>;
17
- }, z.core.$strip>;
13
+ export declare const LayoutSliceConfig: z.ZodDiscriminatedUnion<[z.ZodObject<{
14
+ type: z.ZodLiteral<"mosaic">;
15
+ nodes: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodType<import("@sqlrooms/layout-config").MosaicLayoutParent, unknown, z.core.$ZodTypeInternals<import("@sqlrooms/layout-config").MosaicLayoutParent, unknown>>]>>;
16
+ pinned: z.ZodOptional<z.ZodArray<z.ZodString>>;
17
+ fixed: z.ZodOptional<z.ZodArray<z.ZodString>>;
18
+ }, z.core.$strip>], "type">;
18
19
  export type LayoutSliceConfig = z.infer<typeof LayoutSliceConfig>;
19
20
  export declare function createDefaultLayoutConfig(): LayoutSliceConfig;
20
21
  export type LayoutSliceState = {
21
22
  layout: {
23
+ config: LayoutSliceConfig;
22
24
  panels: Record<string, RoomPanelInfo>;
25
+ setConfig(layout: LayoutConfig): void;
26
+ /** @deprecated Use setConfig instead */
23
27
  setLayout(layout: LayoutConfig): void;
24
28
  togglePanel: (panel: string, show?: boolean) => void;
25
29
  togglePanelPin: (panel: string) => void;
26
30
  };
27
31
  };
28
- export declare function createLayoutSlice<PC extends BaseRoomConfig & LayoutSliceConfig>({ panels, }?: {
32
+ export type CreateLayoutSliceProps = {
33
+ config?: LayoutSliceConfig;
29
34
  panels?: Record<string, RoomPanelInfo>;
30
- }): StateCreator<LayoutSliceState>;
31
- type RoomConfigWithLayout = BaseRoomConfig & LayoutSliceConfig;
32
- type RoomStateWithLayout = RoomState<RoomConfigWithLayout> & LayoutSliceState;
33
- export declare function useStoreWithLayout<T>(selector: (state: RoomStateWithLayout) => T): T;
34
- export {};
35
+ };
36
+ export declare function createLayoutSlice({ config: initialConfig, panels, }?: CreateLayoutSliceProps): StateCreator<LayoutSliceState>;
37
+ export declare function useStoreWithLayout<T>(selector: (state: LayoutSliceState) => T): T;
35
38
  //# sourceMappingURL=LayoutSlice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutSlice.d.ts","sourceRoot":"","sources":["../src/LayoutSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAGV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,EACL,YAAY,EAIb,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IACjD,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAAC;CAC9D,CAAC;AAEF,eA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,gBAAgB,KAAK,CAAC,GACvC,CAAC,CAEH"}
@@ -1,40 +1,33 @@
1
- import { createBaseSlice, useBaseRoomStore, } from '@sqlrooms/room-store';
1
+ import { DEFAULT_MOSAIC_LAYOUT, LayoutConfig, MAIN_VIEW, isMosaicLayoutParent, } from '@sqlrooms/layout-config';
2
+ import { createSlice, useBaseRoomStore } from '@sqlrooms/room-store';
2
3
  import { produce } from 'immer';
3
- import { z } from 'zod';
4
4
  import { makeMosaicStack, removeMosaicNodeByKey } from './mosaic';
5
- import { DEFAULT_MOSAIC_LAYOUT, MAIN_VIEW, isMosaicLayoutParent, } from '@sqlrooms/layout-config';
6
- export const LayoutSliceConfig = z.object({
7
- layout: z
8
- .any()
9
- .describe('Mosaic layout configuration.')
10
- .default(DEFAULT_MOSAIC_LAYOUT),
11
- });
5
+ export const LayoutSliceConfig = LayoutConfig;
12
6
  export function createDefaultLayoutConfig() {
13
- return {
14
- layout: DEFAULT_MOSAIC_LAYOUT,
15
- };
7
+ return DEFAULT_MOSAIC_LAYOUT;
16
8
  }
17
- export function createLayoutSlice({ panels = {}, } = {}) {
18
- return createBaseSlice((set, get) => ({
9
+ export function createLayoutSlice({ config: initialConfig = createDefaultLayoutConfig(), panels = {}, } = {}) {
10
+ return createSlice((set, get) => ({
19
11
  layout: {
12
+ config: initialConfig,
20
13
  panels,
21
- setLayout: (layout) => set((state) => produce(state, (draft) => {
22
- draft.config.layout = layout;
14
+ setConfig: (config) => set((state) => produce(state, (draft) => {
15
+ draft.layout.config = config;
23
16
  })),
17
+ setLayout: (layout) => get().layout.setConfig(layout),
24
18
  togglePanel: (panel, show) => {
25
- const { config } = get();
26
- if (config.layout?.nodes === panel) {
19
+ if (get().layout.config?.nodes === panel) {
27
20
  // don't hide the view if it's the only one
28
21
  return;
29
22
  }
30
- const result = removeMosaicNodeByKey(config.layout?.nodes, panel);
23
+ const result = removeMosaicNodeByKey(get().layout.config?.nodes, panel);
31
24
  const isShown = result.success;
32
25
  if (isShown) {
33
26
  if (show || panel === MAIN_VIEW /*&& areViewsReadyToRender()*/) {
34
27
  return;
35
28
  }
36
29
  set((state) => produce(state, (draft) => {
37
- const layout = draft.config.layout;
30
+ const layout = draft.layout.config;
38
31
  layout.nodes = result.nextTree;
39
32
  if (layout.pinned?.includes(panel)) {
40
33
  layout.pinned = layout.pinned.filter((p) => p !== panel);
@@ -46,9 +39,9 @@ export function createLayoutSlice({ panels = {}, } = {}) {
46
39
  return;
47
40
  }
48
41
  set((state) => produce(state, (draft) => {
49
- const layout = draft.config.layout;
42
+ const layout = draft.layout.config;
50
43
  const root = layout.nodes;
51
- const placement = get().layout.panels[panel]?.placement;
44
+ const placement = draft.layout.panels[panel]?.placement;
52
45
  const side = placement === 'sidebar' ? 'first' : 'second';
53
46
  const toReplace = isMosaicLayoutParent(root)
54
47
  ? root[side]
@@ -65,7 +58,7 @@ export function createLayoutSlice({ panels = {}, } = {}) {
65
58
  else {
66
59
  const panelNode = { node: panel, weight: 1 };
67
60
  const restNode = {
68
- node: config.layout?.nodes,
61
+ node: draft.layout.config?.nodes,
69
62
  weight: 3,
70
63
  };
71
64
  // add to to the left
@@ -82,7 +75,7 @@ export function createLayoutSlice({ panels = {}, } = {}) {
82
75
  */
83
76
  togglePanelPin: (panel) => {
84
77
  set((state) => produce(state, (draft) => {
85
- const layout = draft.config.layout;
78
+ const layout = draft.layout.config;
86
79
  const pinned = layout.pinned ?? [];
87
80
  if (pinned.includes(panel)) {
88
81
  layout.pinned = pinned.filter((p) => p !== panel);
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutSlice.js","sourceRoot":"","sources":["../src/LayoutSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,eAAe,EAAE,qBAAqB,EAAC,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BACN,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAChC,QAA2C;IAE3C,OAAO,gBAAgB,CAIrB,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAuC,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import {\n RoomState,\n createBaseSlice,\n useBaseRoomStore,\n} from '@sqlrooms/room-store';\nimport {BaseRoomConfig} from '@sqlrooms/room-config';\nimport {produce} from 'immer';\nimport {z} from 'zod';\nimport {makeMosaicStack, removeMosaicNodeByKey} from './mosaic';\nimport React from 'react';\nimport {StateCreator} from 'zustand';\nimport {\n LayoutConfig,\n DEFAULT_MOSAIC_LAYOUT,\n MAIN_VIEW,\n isMosaicLayoutParent,\n} from '@sqlrooms/layout-config';\n\nexport type RoomPanelInfo = {\n title?: string;\n icon?: React.ComponentType<{className?: string}>;\n component: React.ComponentType;\n placement: 'sidebar' | 'sidebar-bottom' | 'main' | 'top-bar';\n};\n\nexport const LayoutSliceConfig = z.object({\n layout: z\n .any()\n .describe('Mosaic layout configuration.')\n .default(DEFAULT_MOSAIC_LAYOUT),\n});\n\nexport type LayoutSliceConfig = z.infer<typeof LayoutSliceConfig>;\n\nexport function createDefaultLayoutConfig(): LayoutSliceConfig {\n return {\n layout: DEFAULT_MOSAIC_LAYOUT,\n };\n}\n\nexport type LayoutSliceState = {\n layout: {\n panels: Record<string, RoomPanelInfo>;\n setLayout(layout: LayoutConfig): void;\n togglePanel: (panel: string, show?: boolean) => void;\n togglePanelPin: (panel: string) => void;\n };\n};\n\nexport function createLayoutSlice<\n PC extends BaseRoomConfig & LayoutSliceConfig,\n>({\n panels = {},\n}: {\n panels?: Record<string, RoomPanelInfo>;\n} = {}): StateCreator<LayoutSliceState> {\n return createBaseSlice<PC, LayoutSliceState>((set, get) => ({\n layout: {\n panels,\n setLayout: (layout) =>\n set((state) =>\n produce(state, (draft) => {\n draft.config.layout = layout;\n }),\n ),\n togglePanel: (panel, show) => {\n const {config} = get();\n if (config.layout?.nodes === panel) {\n // don't hide the view if it's the only one\n return;\n }\n const result = removeMosaicNodeByKey(config.layout?.nodes, panel);\n const isShown = result.success;\n if (isShown) {\n if (show || panel === MAIN_VIEW /*&& areViewsReadyToRender()*/) {\n return;\n }\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.config.layout;\n layout.nodes = result.nextTree;\n if (layout.pinned?.includes(panel)) {\n layout.pinned = layout.pinned.filter(\n (p: string) => p !== panel,\n );\n }\n }),\n );\n } else {\n if (show === false) {\n return;\n }\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.config.layout;\n const root = layout.nodes;\n const placement = get().layout.panels[panel]?.placement;\n const side = placement === 'sidebar' ? 'first' : 'second';\n const toReplace = isMosaicLayoutParent(root)\n ? root[side]\n : undefined;\n if (\n toReplace &&\n isMosaicLayoutParent(root) &&\n !isMosaicLayoutParent(toReplace) &&\n toReplace !== MAIN_VIEW &&\n !layout.fixed?.includes(toReplace) &&\n !layout.pinned?.includes(toReplace)\n ) {\n // replace first un-pinned leaf\n root[side] = panel;\n } else {\n const panelNode = {node: panel, weight: 1};\n const restNode = {\n node: config.layout?.nodes,\n weight: 3,\n };\n // add to to the left\n layout.nodes = makeMosaicStack(\n placement === 'sidebar-bottom' ? 'column' : 'row',\n side === 'first'\n ? [panelNode, restNode]\n : [restNode, panelNode],\n );\n }\n }),\n );\n }\n },\n\n /**\n * Toggle the pin state of a panel.\n * @param panel - The panel to toggle the pin state of.\n */\n togglePanelPin: (panel: string) => {\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.config.layout;\n const pinned = layout.pinned ?? [];\n if (pinned.includes(panel)) {\n layout.pinned = pinned.filter((p: string) => p !== panel);\n } else {\n layout.pinned = [...pinned, panel];\n }\n }),\n );\n },\n },\n }));\n}\n\ntype RoomConfigWithLayout = BaseRoomConfig & LayoutSliceConfig;\ntype RoomStateWithLayout = RoomState<RoomConfigWithLayout> & LayoutSliceState;\n\nexport function useStoreWithLayout<T>(\n selector: (state: RoomStateWithLayout) => T,\n): T {\n return useBaseRoomStore<\n BaseRoomConfig & LayoutSliceConfig,\n RoomState<RoomConfigWithLayout>,\n T\n >((state) => selector(state as unknown as RoomStateWithLayout));\n}\n"]}
1
+ {"version":3,"file":"LayoutSlice.js","sourceRoot":"","sources":["../src/LayoutSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACT,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,WAAW,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAI9B,OAAO,EAAC,eAAe,EAAE,qBAAqB,EAAC,MAAM,UAAU,CAAC;AAShE,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAI9C,MAAM,UAAU,yBAAyB;IACvC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAmBD,MAAM,UAAU,iBAAiB,CAAC,EAChC,MAAM,EAAE,aAAa,GAAG,yBAAyB,EAAE,EACnD,MAAM,GAAG,EAAE,MACe,EAAE;IAC5B,OAAO,WAAW,CAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAClD,MAAM,EAAE;YACN,MAAM,EAAE,aAAa;YACrB,MAAM;YACN,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CACpB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,CACH;YACH,SAAS,EAAE,CAAC,MAAM,EAAE,EA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AC,CACH,CAAC;gBACJ,CAAC;YACH,CAAC;YAED;;;eAGG;YACH,cAAc,EAAE,CAAC,KAAa,EAAE,EAAE;gBAChC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;oBACnC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;oBACnC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC3B,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;oBAC5D,CAAC;yBAAM,CAAC;wBACN,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,QAAwC;IAExC,OAAO,gBAAgB,CAAsB,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import {\n DEFAULT_MOSAIC_LAYOUT,\n LayoutConfig,\n MAIN_VIEW,\n isMosaicLayoutParent,\n} from '@sqlrooms/layout-config';\nimport {createSlice, useBaseRoomStore} from '@sqlrooms/room-store';\nimport {produce} from 'immer';\nimport React from 'react';\nimport {z} from 'zod';\nimport {StateCreator} from 'zustand';\nimport {makeMosaicStack, removeMosaicNodeByKey} from './mosaic';\n\nexport type RoomPanelInfo = {\n title?: string;\n icon?: React.ComponentType<{className?: string}>;\n component: React.ComponentType;\n placement: 'sidebar' | 'sidebar-bottom' | 'main' | 'top-bar';\n};\n\nexport const LayoutSliceConfig = LayoutConfig;\n\nexport type LayoutSliceConfig = z.infer<typeof LayoutSliceConfig>;\n\nexport function createDefaultLayoutConfig(): LayoutSliceConfig {\n return DEFAULT_MOSAIC_LAYOUT;\n}\n\nexport type LayoutSliceState = {\n layout: {\n config: LayoutSliceConfig;\n panels: Record<string, RoomPanelInfo>;\n setConfig(layout: LayoutConfig): void;\n /** @deprecated Use setConfig instead */\n setLayout(layout: LayoutConfig): void;\n togglePanel: (panel: string, show?: boolean) => void;\n togglePanelPin: (panel: string) => void;\n };\n};\n\nexport type CreateLayoutSliceProps = {\n config?: LayoutSliceConfig;\n panels?: Record<string, RoomPanelInfo>;\n};\n\nexport function createLayoutSlice({\n config: initialConfig = createDefaultLayoutConfig(),\n panels = {},\n}: CreateLayoutSliceProps = {}): StateCreator<LayoutSliceState> {\n return createSlice<LayoutSliceState>((set, get) => ({\n layout: {\n config: initialConfig,\n panels,\n setConfig: (config) =>\n set((state) =>\n produce(state, (draft) => {\n draft.layout.config = config;\n }),\n ),\n setLayout: (layout) => get().layout.setConfig(layout),\n togglePanel: (panel, show) => {\n if (get().layout.config?.nodes === panel) {\n // don't hide the view if it's the only one\n return;\n }\n const result = removeMosaicNodeByKey(get().layout.config?.nodes, panel);\n const isShown = result.success;\n if (isShown) {\n if (show || panel === MAIN_VIEW /*&& areViewsReadyToRender()*/) {\n return;\n }\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.layout.config;\n layout.nodes = result.nextTree;\n if (layout.pinned?.includes(panel)) {\n layout.pinned = layout.pinned.filter(\n (p: string) => p !== panel,\n );\n }\n }),\n );\n } else {\n if (show === false) {\n return;\n }\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.layout.config;\n const root = layout.nodes;\n const placement = draft.layout.panels[panel]?.placement;\n const side = placement === 'sidebar' ? 'first' : 'second';\n const toReplace = isMosaicLayoutParent(root)\n ? root[side]\n : undefined;\n if (\n toReplace &&\n isMosaicLayoutParent(root) &&\n !isMosaicLayoutParent(toReplace) &&\n toReplace !== MAIN_VIEW &&\n !layout.fixed?.includes(toReplace) &&\n !layout.pinned?.includes(toReplace)\n ) {\n // replace first un-pinned leaf\n root[side] = panel;\n } else {\n const panelNode = {node: panel, weight: 1};\n const restNode = {\n node: draft.layout.config?.nodes,\n weight: 3,\n };\n // add to to the left\n layout.nodes = makeMosaicStack(\n placement === 'sidebar-bottom' ? 'column' : 'row',\n side === 'first'\n ? [panelNode, restNode]\n : [restNode, panelNode],\n );\n }\n }),\n );\n }\n },\n\n /**\n * Toggle the pin state of a panel.\n * @param panel - The panel to toggle the pin state of.\n */\n togglePanelPin: (panel: string) => {\n set((state) =>\n produce(state, (draft) => {\n const layout = draft.layout.config;\n const pinned = layout.pinned ?? [];\n if (pinned.includes(panel)) {\n layout.pinned = pinned.filter((p: string) => p !== panel);\n } else {\n layout.pinned = [...pinned, panel];\n }\n }),\n );\n },\n },\n }));\n}\n\nexport function useStoreWithLayout<T>(\n selector: (state: LayoutSliceState) => T,\n): T {\n return useBaseRoomStore<LayoutSliceState, T>((state) => selector(state));\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlrooms/layout",
3
- "version": "0.26.0-rc.4",
3
+ "version": "0.26.0-rc.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -18,10 +18,10 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@sqlrooms/layout-config": "0.26.0-rc.4",
22
- "@sqlrooms/room-config": "0.26.0-rc.4",
23
- "@sqlrooms/room-store": "0.26.0-rc.4",
24
- "@sqlrooms/ui": "0.26.0-rc.4",
21
+ "@sqlrooms/layout-config": "0.26.0-rc.5",
22
+ "@sqlrooms/room-config": "0.26.0-rc.5",
23
+ "@sqlrooms/room-store": "0.26.0-rc.5",
24
+ "@sqlrooms/ui": "0.26.0-rc.5",
25
25
  "immer": "^10.1.3",
26
26
  "zod": "^4.1.8",
27
27
  "zustand": "^5.0.8"
@@ -29,7 +29,7 @@
29
29
  "peerDependencies": {
30
30
  "react": ">=18",
31
31
  "react-dom": ">=18",
32
- "react-mosaic-component": "5.3.0"
32
+ "react-mosaic-component": "^6.1.1"
33
33
  },
34
34
  "scripts": {
35
35
  "dev": "tsc -w",
@@ -38,5 +38,5 @@
38
38
  "typecheck": "tsc --noEmit",
39
39
  "typedoc": "typedoc"
40
40
  },
41
- "gitHead": "9e23926085d8852178792d6d98d8091e9a5f71d5"
41
+ "gitHead": "dc1c3b765718c8748aa11cce3cc83f907d3e5963"
42
42
  }