atoms.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { atom, selector } from "recoil";
  2. export const AvailableItemListAtom = atom({
  3. key: "availableItemList",
  4. default: [],
  5. });
  6. export const BoardConfigAtom = atom({
  7. key: "boardConfig",
  8. default: {},
  9. });
  10. export const BoardStateAtom = atom({
  11. key: "boardState",
  12. default: {
  13. movingItems: false,
  14. selecting: false,
  15. zooming: false,
  16. panning: false,
  17. },
  18. });
  19. export const ItemListAtom = atom({
  20. key: "itemList",
  21. default: [],
  22. });
  23. export const ItemMapAtom = atom({
  24. key: "ItemMap",
  25. default: {},
  26. });
  27. export const AllItemsSelector = selector({
  28. key: "AllItemsSelector",
  29. get: ({ get }) => {
  30. const itemMap = get(ItemMapAtom);
  31. return get(ItemListAtom)
  32. .map((id) => itemMap[id])
  33. .filter((item) => item); // This filter clean the selection of missing items
  34. },
  35. });
  36. export const PanZoomRotateAtom = atom({
  37. key: "PanZoomRotate",
  38. default: {
  39. translateX: 0,
  40. translateY: 0,
  41. scale: 1,
  42. rotate: 0,
  43. centerX: 0,
  44. centerY: 0,
  45. },
  46. });
  47. export default {
  48. ItemListAtom,
  49. BoardConfigAtom,
  50. AvailableItemListAtom,
  51. AllItemsSelector,
  52. ItemMapAtom,
  53. PanZoomRotateAtom,
  54. };