file-upload-with-preview icon indicating copy to clipboard operation
file-upload-with-preview copied to clipboard

Unable to import Events and ImageAddedEvent

Open AshwinNema opened this issue 6 months ago • 6 comments

While reading documentation I found that we can add event listener to the window object for the events happening. Here is one of the snippet given in documentation

import { Events, ImageAddedEvent } from 'file-upload-with-preview';

window.addEventListener(Events.IMAGE_ADDED, (e: Event) => {
  const { detail } = e as unknown as ImageAddedEvent;

  console.log('detail', detail);
});

The issue I am facing is that I am unable to import Events as they are not exported from package.json.

Proposed Solution

We can add it in exports in package.json like

"./dist/index":"./dist/index.d.ts”

exports after adding above code will look like

"exports": {
    ".": {
      "import": "./dist/file-upload-with-preview.js",
      "require": "./dist/file-upload-with-preview.cjs",
      "types": "./dist/index.d.ts"
    },
    "./dist/style.css": "./dist/style.css",
    "./dist/index":"./dist/index.d.ts"
  }

and if we want to import we can import like

import { Events, ImageAddedEvent } from 'file-upload-with-preview/dist/index';

AshwinNema avatar Aug 24 '24 15:08 AshwinNema