lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: calculateZoomLevel missing in Flow?

Open Dagur opened this issue 1 year ago • 1 comments

Lexical version: 0.20.0

Steps To Reproduce

  1. Try import { calculateZoomLevel } from "@lexical/utils";
  2. Get missing-export error from flow

Link to code example:

Just enable flow and try this import

import { calculateZoomLevel } from "@lexical/utils";

The current behavior

The function works like it should but a $FlowFixMe is needed to suppress the flow error

The expected behavior

No Flow error

Impact of fix

Low severity

Dagur avatar Nov 13 '24 15:11 Dagur

Hi @Dagur and @etrepum

My partner @RommyT1 and I are students from the University of Michigan working on a Software Engineering course project, where we contribute to open-source software. My partner and I would like to take on this issue as it aligns well with our coursework requirements, and we’re interested in helping improve lexical!

Could you please assign this issue to us? We were able to reproduce this issue locally, and we’d be happy to work on developing and testing a solution. We will make sure to maintain high code quality and follow lexical and facebook's standards.

Thank you for considering our request!

hadiham avatar Nov 14 '24 10:11 hadiham

Hi @Dagur and @etrepum

@RommyT1 and I have implemented a potential fix for this issue. We added the missing calculateZoomLevel declaration in LexicalUtils.js.flow to resolve the Flow error. Additionally, while working on this, we noticed a few other functions that were missing Flow type declarations, so we added the following declarations as well:

declare export function $getNextRightPreorderNode(
  startingNode: LexicalNode,
): LexicalNode | null;
declare export function calculateZoomLevel(element: Element | null): number;
declare export function $isEditorIsNestedEditor(editor: LexicalEditor): boolean;
declare export function objectKlassEquals<T>(
  object: mixed,
  objectClass: Class<T>,
): boolean;
declare export function $filter<T>(
  nodes: Array<LexicalNode>,
  filterFn: (node: LexicalNode) => null | T,
): Array<T>;
declare export function $insertFirst(parent: ElementNode, node: LexicalNode): void;

When testing these changes we observed that Flow now correctly recognizes these functions and can be used without $FlowFixMe comments.

Please let us know if there are any questions or further adjustments you’d like us to make. Thank you!

hadiham avatar Nov 17 '24 01:11 hadiham

If you submit this as a PR we can review it

etrepum avatar Nov 17 '24 02:11 etrepum

Thanks!

Dagur avatar Nov 18 '24 08:11 Dagur

Thanks!

No problem, this was our first time contributing to an open source, I'm glad we could help!

RommyT1 avatar Nov 18 '24 11:11 RommyT1

Thank you for your contribution!

etrepum avatar Nov 18 '24 15:11 etrepum