Refactor Dialog abstraction (#90)

This PR overhauls the Dialog abstractions in `studio-ui` to be more
flexible for a wider variety of use cases, and adds a placeholder
"Import Asset" sub-dialog to the Media Library dialog.
This commit is contained in:
Danny McGee
2024-03-21 22:38:33 -04:00
committed by GitHub
parent 67a12e42e2
commit 701ba04765
17 changed files with 835 additions and 283 deletions
+1
View File
@@ -1,3 +1,4 @@
export * from "./lib/array";
export * from "./lib/assert";
export * from "./lib/exists";
export * from "./lib/match";
+20
View File
@@ -0,0 +1,20 @@
export type ArrayOrSingle<T> = T | T[];
export function asArray<T>(value: ArrayOrSingle<T> | Iterable<T>): T[] {
if (Array.isArray(value))
return value;
if (isIterable<T>(value))
return Array.from(value);
return [value];
}
export function isIterable<T = unknown>(value: unknown): value is Iterable<T> {
return (
value != null
&& typeof value === "object"
&& Symbol.iterator in value
&& typeof value[Symbol.iterator] === "function"
)
}