2
0

🐛 (editor) Share groups clipboard state across tabs

This commit is contained in:
Baptiste Arnaud
2024-03-20 17:29:05 +01:00
parent 97107d4121
commit 5b9176708c
3 changed files with 87 additions and 80 deletions

View File

@ -84,6 +84,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "^9.0.1",
"shared-zustand": "2.0.0",
"sonner": "1.3.1",
"stripe": "12.13.0",
"svg-round-corners": "0.4.1",
@ -97,12 +98,17 @@
"devDependencies": {
"@chakra-ui/styled-system": "2.9.1",
"@playwright/test": "1.41.2",
"@typebot.io/billing": "workspace:*",
"@typebot.io/forge": "workspace:*",
"@typebot.io/forge-repository": "workspace:*",
"@typebot.io/lib": "workspace:*",
"@typebot.io/migrations": "workspace:*",
"@typebot.io/playwright": "workspace:*",
"@typebot.io/prisma": "workspace:*",
"@typebot.io/radar": "workspace:*",
"@typebot.io/results": "workspace:*",
"@typebot.io/schemas": "workspace:*",
"@typebot.io/telemetry": "workspace:*",
"@typebot.io/tsconfig": "workspace:*",
"@types/canvas-confetti": "1.6.0",
"@types/jsonwebtoken": "9.0.2",
@ -121,11 +127,6 @@
"next-runtime-env": "1.6.2",
"superjson": "1.12.4",
"typescript": "5.3.2",
"zod": "3.22.4",
"@typebot.io/playwright": "workspace:*",
"@typebot.io/billing": "workspace:*",
"@typebot.io/results": "workspace:*",
"@typebot.io/migrations": "workspace:*",
"@typebot.io/telemetry": "workspace:*"
"zod": "3.22.4"
}
}

View File

@ -1,7 +1,8 @@
import { createWithEqualityFn } from 'zustand/traditional'
import { Coordinates, CoordinatesMap } from '../types'
import { Edge, Group, GroupV6 } from '@typebot.io/schemas'
import { persist } from 'zustand/middleware'
import { subscribeWithSelector } from 'zustand/middleware'
import { share } from 'shared-zustand'
type Store = {
focusedGroups: string[]
@ -21,8 +22,7 @@ type Store = {
}
export const useGroupsStore = createWithEqualityFn<Store>()(
persist(
(set, get) => ({
subscribeWithSelector((set, get) => ({
focusedGroups: [],
groupsCoordinates: undefined,
groupsInClipboard: undefined,
@ -91,10 +91,9 @@ export const useGroupsStore = createWithEqualityFn<Store>()(
},
}),
setIsDraggingGraph: (isDragging) => set({ isDraggingGraph: isDragging }),
}),
{
name: 'store',
partialize: (state) => ({ groupsInClipboard: state.groupsInClipboard }),
}))
)
if ('BroadcastChannel' in globalThis) {
share('groupsInClipboard', useGroupsStore)
}
)
)

7
pnpm-lock.yaml generated
View File

@ -242,6 +242,9 @@ importers:
react-markdown:
specifier: ^9.0.1
version: 9.0.1(@types/react@18.2.15)(react@18.2.0)
shared-zustand:
specifier: 2.0.0
version: 2.0.0
sonner:
specifier: 1.3.1
version: 1.3.1(react-dom@18.2.0)(react@18.2.0)
@ -20658,6 +20661,10 @@ packages:
/setprototypeof@1.2.0:
resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==}
/shared-zustand@2.0.0:
resolution: {integrity: sha512-DKBWe2w62wZif79XcUXStBBQ47T4y3XEApueseZ1O3wEsMbamDK01ac0zQNVj4MOH9Z5jesM2oLuug/79LPM1A==}
dev: false
/sharp@0.33.2:
resolution: {integrity: sha512-WlYOPyyPDiiM07j/UO+E720ju6gtNtHjEGg5vovUk1Lgxyjm2LFO+37Nt/UI3MMh2l6hxTWQWi7qk3cXJTutcQ==}
engines: {libvips: '>=8.15.1', node: ^18.17.0 || ^20.3.0 || >=21.0.0}