refactor: move getSyncableElements to CollabWrapper & expose isInvisiblySmallElement helper (#3471)

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
David Luzar
2021-04-21 23:37:44 +02:00
committed by GitHub
parent 37d513ad59
commit 3a0b6fb41b
6 changed files with 27 additions and 19 deletions

View File

@ -40,6 +40,17 @@ Please add the latest change on the top under the correct section.
- When switching theme, apply it only to the active Excalidraw component. This fixes a case where the theme was getting applied to the first Excalidraw component if you had multiple Excalidraw components on the same page [#3446](https://github.com/excalidraw/excalidraw/pull/3446)
### Refactor
- #### BREAKING CHANGE
- Removed exposing `getSyncableElements` helper which was specific to excalidraw app collab implementation [#3471](https://github.com/excalidraw/excalidraw/pull/3471). If you happened to use it, you can easily reimplement it yourself using the newly exposed [isInvisiblySmallElement](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#isInvisiblySmallElement) helper:
```ts
const getSyncableElements = (elements: readonly ExcalidrawElement[]) =>
elements.filter((el) => el.isDeleted || !isInvisiblySmallElement(el));
```
## Types
- Renamed the following types in case you depend on them (via [#3427](https://github.com/excalidraw/excalidraw/pull/3427)):

View File

@ -629,21 +629,21 @@ getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blo
This function returns the current scene version.
#### `getSyncableElements`
#### `isInvisiblySmallElement`
**_Signature_**
<pre>
getSyncableElements(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>):<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>
isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement</a>): boolean
</pre>
**How to use**
```js
import { getSyncableElements } from "@excalidraw/excalidraw";
import { isInvisiblySmallElement } from "@excalidraw/excalidraw";
```
Returns all elements including deleted ones, excluding elements which are are invisibly small (e.g. width & height are zero). Useful when you want to sync elements during collaboration.
Returns `true` if element is invisibly small (e.g. width & height are zero).
#### `getElementMap`

View File

@ -115,8 +115,8 @@ const forwardedRefComp = forwardRef<
export default React.memo(forwardedRefComp, areEqual);
export {
getSceneVersion,
getSyncableElements,
getElementMap,
isInvisiblySmallElement,
} from "../../element";
export { defaultLang, languages } from "../../i18n";
export { restore, restoreAppState, restoreElements } from "../../data/restore";