-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lr-upload-ctx-provider): improve event types
- Loading branch information
Showing
13 changed files
with
189 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expectType } from 'tsd'; | ||
import { GlobalEventPayload } from '../index.js'; | ||
|
||
window.addEventListener( | ||
'LR_DATA_OUTPUT', | ||
(e) => { | ||
expectType<CustomEvent<GlobalEventPayload['LR_DATA_OUTPUT']>>(e); | ||
}, | ||
{ once: true } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @ts-expect-error - no props | ||
() => <lr-cloud-image-editor />; | ||
|
||
// @ts-expect-error - no css-url | ||
() => <lr-cloud-image-editor ctx-name="my-uploader" />; | ||
|
||
// @ts-expect-error - no css-src | ||
() => <lr-cloud-image-editor css-src="url" />; | ||
|
||
() => <lr-cloud-image-editor ctx-name="my-editor" css-src="url" uuid="123124" />; | ||
() => <lr-cloud-image-editor ctx-name="my-editor" css-src="url" uuid="123124" tabs="tab" crop-preset="preset" />; | ||
() => <lr-cloud-image-editor ctx-name="my-editor" css-src="url" cdn-url="url" />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expectType } from 'tsd'; | ||
import { DataOutput } from '../../index.js'; | ||
import { Output } from '../../blocks/DataOutput/DataOutput.js'; | ||
|
||
() => <lr-data-output ctx-name="my-uploader" />; | ||
|
||
const dataOutput = new DataOutput(); | ||
dataOutput.addEventListener('lr-data-output', (e) => { | ||
expectType< | ||
CustomEvent<{ | ||
timestamp: number; | ||
ctxName: string; | ||
data: Output; | ||
}> | ||
>(e); | ||
}); | ||
|
||
dataOutput.validationInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expectType } from 'tsd'; | ||
import { EventMap, UploadCtxProvider } from '../../index.js'; | ||
import { useRef } from 'react'; | ||
|
||
const instance = new UploadCtxProvider(); | ||
|
||
instance.addFileFromUrl('https://example.com/image.png'); | ||
instance.uploadCollection.size; | ||
instance.setOrAddState('fileId', 'uploading'); | ||
|
||
instance.addEventListener('data-output', (e) => { | ||
expectType<EventMap['data-output']>(e); | ||
|
||
// @ts-expect-error - wrong event type | ||
expectType<EventMap['init-flow']>(e); | ||
}); | ||
|
||
const onDataOutput = (e: EventMap['data-output']) => { | ||
// noop | ||
}; | ||
|
||
instance.addEventListener('data-output', onDataOutput); | ||
|
||
() => { | ||
const ref = useRef<InstanceType<UploadCtxProvider>>(null); | ||
return <lr-upload-ctx-provider ctx-name="ctx" ref={ref}></lr-upload-ctx-provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @template T | ||
* @typedef {new (...args: any[]) => T} GConstructor | ||
*/ | ||
|
||
/** | ||
* This is a helper to create a class type extended with the provided set of instance properties. It's useful when there | ||
* are some dynamic generated properties or native overrides in the class. We're use it to define dynamic access | ||
* properties and events to subscribe to. | ||
* | ||
* @template {GConstructor<HTMLElement>} Base | ||
* @template {Record<string, any>} [InstanceProperties={}] Default is `{}` | ||
* @typedef {{ | ||
* new (...args: ConstructorParameters<Base>): InstanceProperties & InstanceType<Base>; | ||
* } & Omit<Base, 'new'>} MixinClass | ||
*/ | ||
|
||
export {}; |