facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.95k stars 1.7k forks source link

Bug: calculateZoomLevel missing in Flow? #6823

Closed Dagur closed 4 days ago

Dagur commented 1 week ago

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

hadiham commented 1 week ago

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 commented 5 days ago

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!

etrepum commented 5 days ago

If you submit this as a PR we can review it

Dagur commented 4 days ago

Thanks!

RommyT1 commented 4 days ago

Thanks!

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

etrepum commented 4 days ago

Thank you for your contribution!