Repository: excalidraw/excalidraw
File: packages/excalidraw/components/App.tsx (TypeScript)

Code before:
    }

    const imageFiles = fileItems
      .map((data) => data.file)
      .filter((file) => isSupportedImageFile(file));

    if (imageFiles.length > 0 && this.isToolSupported("image")) {
      return this.insertImages(imageFiles, sceneX, sceneY);
    }

    const libraryJSON = dataTransferList.getData(MIME_TYPES.excalidrawlib);
    if (libraryJSON && typeof libraryJSON === "string") {
        try {
          // Try to parse as lightweight ID-only format first
          let parsed;
          try {
            parsed = JSON.parse(libraryJSON);
          } catch (e) {
            parsed = null;
          }
          if (parsed && Array.isArray(parsed.ids)) {
            // Resolve IDs to full items from the library
            const allItems = this.library.getItems();
            const resolvedItems = parsed.ids
              .map((id: string) => allItems.find((item: LibraryItem) => item.id === id))
              .filter(Boolean);
            if (resolvedItems.length > 0) {
              this.addElementsFromPasteOrLibrary({
                elements: distributeLibraryItemsOnSquareGrid(resolvedItems),
                position: event,
                files: null,
              });
              return;
            }
          }
          // Fallback: try to parse as full library JSON
          const libraryItems = parseLibraryJSON(libraryJSON);
          this.addElementsFromPasteOrLibrary({
            elements: distributeLibraryItemsOnSquareGrid(libraryItems),
            position: event,
            files: null,
          });
        } catch (error: any) {
          this.setState({ errorMessage: error.message });
        }
        return;
    }

    if (fileItems.length > 0) {
      const { file, fileHandle } = fileItems[0];
      if (file) {

Review comment (suggestion):
let's do it the other way:

```
allItems.filter((item) => parsed.ids.includes(item.id));
```

that way it won't be untyped 

Code after:
      }
    }

    const imageFiles = fileItems
      .map((data) => data.file)
      .filter((file) => isSupportedImageFile(file));

    if (imageFiles.length > 0 && this.isToolSupported("image")) {
      return this.insertImages(imageFiles, sceneX, sceneY);
    }
    const excalidrawLibrary_ids = dataTransferList.getData(
      MIME_TYPES.excalidrawlibIds,
    );
    const excalidrawLibrary_data = dataTransferList.getData(
      MIME_TYPES.excalidrawlib,
    );
    if (excalidrawLibrary_ids || excalidrawLibrary_data) {
      try {
        let libraryItems: LibraryItems | null = null;
        if (excalidrawLibrary_ids) {
          const { itemIds } = JSON.parse(
            excalidrawLibrary_ids,
          ) as ExcalidrawLibraryIds;
          const allLibraryItems = await this.library.getLatestLibrary();
          libraryItems = allLibraryItems.filter((item) =>
            itemIds.includes(item.id),
          );
          // legacy library dataTransfer format
        } else if (excalidrawLibrary_data) {
          libraryItems = parseLibraryJSON(excalidrawLibrary_data);
        }
        if (libraryItems?.length) {
          libraryItems = libraryItems.map((item) => ({
            ...item,
            // #6465
            elements: duplicateElements({
              type: "everything",
              elements: item.elements,
              randomizeSeed: true,
            }).duplicatedElements,
          }));

          this.addElementsFromPasteOrLibrary({
            elements: distributeLibraryItemsOnSquareGrid(libraryItems),
            position: event,
            files: null,
          });
        }
      } catch (error: any) {
        this.setState({ errorMessage: error.message });
      }