Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akram-r committed Dec 19, 2023
1 parent 246b984 commit 5c663f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { SmartObject } from './modules/reflection/helpers';
import { useModalStyles } from './styles/modal';
import SectionTitle from './components/SectionTitle';
import { FABRIC_JSON_ALLOWED_KEYS } from './constants';
import { createSnappingLines, snapToObject } from './modules/snapping';
import { createSnappingLines, filterSnappingLines, snapToObject } from './modules/snapping';

store.dispatch(appStart());

Expand Down Expand Up @@ -147,7 +147,7 @@ function App() {
const target = options.target as fabric.Object;
snapToObject(
target as snappingObjectType,
canvasRef.current?.getObjects().filter(x => !x?.data?.isSnappingLine) as snappingObjectType[],
filterSnappingLines(canvasRef.current?.getObjects()) as snappingObjectType[],
guidesRef,
canvasRef,
Number(snapDistance),
Expand Down Expand Up @@ -279,7 +279,7 @@ function App() {
...newArtboard,
state: {
...json,
objects: json?.objects.filter((item: any) => !item?.data?.isSnappingLine),
objects: filterSnappingLines(json?.objects),
},
},
];
Expand Down Expand Up @@ -482,7 +482,7 @@ function App() {
...item,
state: {
...json,
objects: json?.objects.filter((item: any) => !item?.data?.isSnappingLine),
objects: filterSnappingLines(json?.objects),
},
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/layers/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useTreeOpenHandler from './Folders/useTreeOpenHandler';
import { convertFabricObjectsToLayers, convertLayersToFabricObjects } from './helpers';
import { fabric } from 'fabric';
import SectionTitle from '../../components/SectionTitle';
import { filterSnappingLines } from '../snapping';

const reorderArray = (array: NodeModel[], sourceIndex: number, targetIndex: number) => {
const newArray = [...array];
Expand Down Expand Up @@ -113,7 +114,7 @@ export default function LayerList({ canvas }: LayerListProp) {

useEffect(() => {
if (layers.length === 0) return;
const newTreeData = convertFabricObjectsToLayers(layers) as NodeModel[];
const newTreeData = convertFabricObjectsToLayers(filterSnappingLines(layers)) as NodeModel[];
setTreeData(prev => {
if (JSON.stringify(prev) === JSON.stringify(newTreeData)) return prev;
return newTreeData;
Expand Down
5 changes: 5 additions & 0 deletions src/modules/snapping/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,8 @@ export function createSnappingLines(
);
return guidesRef;
}

export const filterSnappingLines = (arr: fabric.Object[] | undefined) => {
if (!arr) return [];
return arr.filter(obj => !obj?.data?.isSnappingLine);
};

0 comments on commit 5c663f0

Please sign in to comment.