mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-25 08:30:24 +00:00
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:
@@ -1,3 +1,4 @@
|
||||
export * from "./lib/array";
|
||||
export * from "./lib/assert";
|
||||
export * from "./lib/exists";
|
||||
export * from "./lib/match";
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user