-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [1.1.3](v1.1.2...v1.1.3) (2022-04-18) ### Bug Fixes * remove subpath from package.json ([#11](#11)) ([dd87773](dd87773))
- Loading branch information
1 parent
dd87773
commit 969164e
Showing
28 changed files
with
1,059 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "exploration", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "", | ||
"license": "MIT", | ||
"author": "Jared Lunde <[email protected]> (https://jaredlunde.com/)", | ||
|
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,203 @@ | ||
import { Branch } from "./tree/branch"; | ||
import { Leaf } from "./tree/leaf"; | ||
import type { GetNodes as GetNodesBase } from "./tree/tree"; | ||
import { Tree } from "./tree/tree"; | ||
/** | ||
* Create a file tree that can be used with the React API. | ||
* | ||
* @param getNodes - A function that returns the nodes of the file tree. | ||
* @param config - Configuration options for the file tree. | ||
* @param config.comparator - A function that compares two nodes for sorting. | ||
* @param config.root - The root node data of the file tree. | ||
*/ | ||
export declare function createFileTree<Meta = {}>(getNodes: GetNodes<Meta>, config?: FileTreeConfig<Meta>): FileTree<Meta>; | ||
export declare class FileTree<Meta = {}> extends Tree<FileTreeData<Meta>> { | ||
/** | ||
* The root directory of the file tree | ||
*/ | ||
root: Dir<Meta>; | ||
protected treeNodeMap: Map<number, File<Meta> | Dir<Meta>>; | ||
nodesById: FileTreeNode<Meta>[]; | ||
/** | ||
* Get a node by its ID. | ||
* | ||
* @param id - The ID of the node | ||
*/ | ||
getById: (id: number) => FileTreeNode<Meta> | undefined; | ||
/** | ||
* Expand a directory in the tree. | ||
* | ||
* @param dir - The directory to expand | ||
* @param options - Options for expanding the directory | ||
*/ | ||
expand: (dir: Dir<Meta>, options?: { | ||
/** | ||
* Ensure that the directory's parents are visible in the tree, as well. | ||
*/ | ||
ensureVisible?: boolean; | ||
/** | ||
* Expand all of the directory's child directories. | ||
*/ | ||
recursive?: boolean; | ||
}) => Promise<void>; | ||
/** | ||
* Collapse a directory in the tree. | ||
* | ||
* @param dir - The directory to collapse | ||
*/ | ||
collapse: (dir: Dir<Meta>) => void; | ||
/** | ||
* Remove a node and its descendants from the tree. | ||
*/ | ||
remove: (node: FileTreeNode<Meta>) => void; | ||
/** | ||
* You can use this method to manually trigger a reload of a directory in the tree. | ||
* | ||
* @param dir - The branch to load nodes for | ||
*/ | ||
loadNodes: (dir: Dir<Meta>) => Promise<void>; | ||
constructor({ getNodes, comparator, root, }: { | ||
getNodes: GetNodesBase<FileTreeData<Meta>>; | ||
comparator: (a: FileTreeNode<Meta>, b: FileTreeNode<Meta>) => number; | ||
root: Dir<Meta>; | ||
}); | ||
/** | ||
* Produce a new tree with the given function applied to the given node. | ||
* This is similar to `immer`'s produce function as you're working on a draft | ||
* and can freely mutate the object. | ||
* | ||
* @param dir - The directory to produce the tree for | ||
* @param produceFn - The function to produce the tree with | ||
*/ | ||
produce(dir: Dir<Meta>, produceFn: (context: FileTreeFactory<Meta> & { | ||
/** | ||
* The draft of the directory. | ||
*/ | ||
get draft(): FileTreeNode<Meta>[]; | ||
/** | ||
* Insert a node into the draft. | ||
* | ||
* @param node - The node to insert | ||
*/ | ||
insert<NodeType extends FileTreeNode<Meta>>(node: NodeType): NodeType; | ||
/** | ||
* Revert the draft back to its original state. | ||
*/ | ||
revert(): void; | ||
}) => void | (Dir<Meta> | File<Meta>)[]): void; | ||
/** | ||
* Move a node to a new parent. | ||
* | ||
* @param node - The node to move | ||
* @param to - The new parent | ||
*/ | ||
move(node: FileTreeNode<Meta>, to: Dir<Meta>): Promise<void>; | ||
/** | ||
* Create a new file in a given directory. | ||
* | ||
* @param inDir - The directory to create the file in | ||
* @param withData - The data for the file | ||
*/ | ||
newFile(inDir: Dir<Meta>, withData: FileTreeData<Meta>): void; | ||
/** | ||
* Create a new directory in a given directory. | ||
* | ||
* @param inDir - The directory to create the directory in | ||
* @param withData - The data for the directory | ||
* @param expanded - Whether the directory should be expanded by default | ||
*/ | ||
newDir(inDir: Dir<Meta>, withData: FileTreeData<Meta>, expanded?: boolean): void; | ||
/** | ||
* Rename a node. | ||
* | ||
* @param node - The node to rename | ||
* @param newName - The new name for the node | ||
*/ | ||
rename(node: FileTreeNode<Meta>, newName: string): void; | ||
} | ||
export declare class File<Meta = {}> extends Leaf<FileTreeData<Meta>> { | ||
/** | ||
* The parent directory of the file | ||
*/ | ||
get parent(): Dir<Meta> | null; | ||
/** | ||
* The basename of the file | ||
*/ | ||
get basename(): string; | ||
/** | ||
* The full path of the file | ||
*/ | ||
get path(): string; | ||
} | ||
export declare class Dir<Meta = {}> extends Branch<FileTreeData<Meta>> { | ||
/** | ||
* The parent directory of this directory | ||
*/ | ||
get parent(): Dir<Meta> | null; | ||
/** | ||
* The basename of the directory | ||
*/ | ||
get basename(): string; | ||
/** | ||
* The full path of the directory | ||
*/ | ||
get path(): string; | ||
} | ||
/** | ||
* A sort comparator for sorting path names | ||
* | ||
* @param a - A tree node | ||
* @param b - A tree node to compare against `a` | ||
*/ | ||
export declare function defaultComparator(a: FileTreeNode, b: FileTreeNode): number; | ||
/** | ||
* Returns `true` if the given node is a file | ||
* | ||
* @param treeNode - A tree node | ||
*/ | ||
export declare function isFile<T>(treeNode: FileTreeNode<T>): treeNode is File<T>; | ||
/** | ||
* Returns `true` if the given node is a directory | ||
* | ||
* @param treeNode - A tree node | ||
*/ | ||
export declare function isDir<T>(treeNode: FileTreeNode<T>): treeNode is Dir<T>; | ||
export declare type FileTreeNode<Meta = {}> = File<Meta> | Dir<Meta>; | ||
export declare type FileTreeData<Meta = {}> = { | ||
name: string; | ||
meta?: Meta; | ||
}; | ||
export declare type FileTreeFactory<Meta = {}> = { | ||
/** | ||
* Create a file node that can be inserted into the tree. | ||
* | ||
* @param data - The data to create a file with | ||
*/ | ||
createFile(data: FileTreeData<Meta>): File<Meta>; | ||
/** | ||
* Create a directory node that can be inserted into the tree. | ||
* | ||
* @param data - The data to create a directory with | ||
* @param expanded - Should the directory be expanded by default? | ||
*/ | ||
createDir(data: FileTreeData<Meta>, expanded?: boolean): Dir<Meta>; | ||
}; | ||
export declare type GetNodes<Meta> = { | ||
/** | ||
* Get the nodes for a given directory | ||
* | ||
* @param parent - The parent directory to get the nodes for | ||
* @param factory - A factory to create nodes (file/dir) with | ||
*/ | ||
(parent: Dir<Meta>, factory: FileTreeFactory<Meta>): Promise<FileTreeNode<Meta>[]> | FileTreeNode<Meta>[]; | ||
}; | ||
export declare type FileTreeConfig<Meta> = { | ||
/** | ||
* A function that compares two nodes for sorting. | ||
*/ | ||
comparator?: FileTree["comparator"]; | ||
/** | ||
* The root node data | ||
*/ | ||
root?: Omit<FileTreeData<Meta>, "type">; | ||
}; |
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,24 @@ | ||
export { createFileTree, defaultComparator, isDir, isFile, FileTree, Dir, File, } from "./file-tree"; | ||
export type { FileTreeNode, FileTreeData, FileTreeFactory } from "./file-tree"; | ||
export { Node } from "./node"; | ||
export { ObservableMap, ObservableSet } from "./observable-data"; | ||
export * as pathFx from "./path-fx"; | ||
export { observable } from "./tree/observable"; | ||
export type { Observable } from "./tree/observable"; | ||
export { useDnd } from "./use-dnd"; | ||
export type { DndEvent, DndProps, UseDndPlugin, UseDndConfig } from "./use-dnd"; | ||
export { useFilter } from "./use-filter"; | ||
export { useHotkeys } from "./use-hotkeys"; | ||
export { useNodePlugins } from "./use-node-plugins"; | ||
export type { NodePlugin } from "./use-node-plugins"; | ||
export { useObservable } from "./use-observable"; | ||
export { useTraits } from "./use-traits"; | ||
export type { TraitsProps, UseTraitsPlugin } from "./use-traits"; | ||
export { useRovingFocus } from "./use-roving-focus"; | ||
export type { RovingFocusProps, UseRovingFocusPlugin, } from "./use-roving-focus"; | ||
export { useSelections } from "./use-selections"; | ||
export type { SelectionsProps, UseSelectionsPlugin } from "./use-selections"; | ||
export { useVirtualize } from "./use-virtualize"; | ||
export type { UseVirtualizeConfig, UseVirtualizeResult, } from "./use-virtualize"; | ||
export { useVisibleNodes } from "./use-visible-nodes"; | ||
export { mergeProps } from "./utils"; |
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,36 @@ | ||
import * as React from "react"; | ||
import type { FileTree, FileTreeNode } from "./file-tree"; | ||
import type { NodePlugin } from "./use-node-plugins"; | ||
/** | ||
* A React component that renders a node in a file tree with plugins. The | ||
* `<Node>` component uses this under the hood. | ||
* | ||
* @param props - Node props | ||
*/ | ||
export declare function Node<Meta>(props: NodeProps<Meta>): React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>; | ||
export interface NodeProps<Meta> { | ||
/** | ||
* A file tree node | ||
*/ | ||
node: FileTreeNode<Meta>; | ||
/** | ||
* The index of the node within the file tree list of visible nodes | ||
*/ | ||
index: number; | ||
/** | ||
* The file tree that contains the node | ||
*/ | ||
tree: FileTree<Meta>; | ||
/** | ||
* A list of plugins to apply to the node. For example `useTraits()`. | ||
*/ | ||
plugins?: NodePlugin[]; | ||
/** | ||
* Styles to apply to the `<div>` element | ||
*/ | ||
style: React.CSSProperties; | ||
/** | ||
* Children to render within the node | ||
*/ | ||
children: React.ReactNode; | ||
} |
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,15 @@ | ||
import type { Observable } from "./tree/observable"; | ||
export declare class ObservableSet<T> extends Set<T> { | ||
didChange: Observable<Set<T>>; | ||
constructor(initialValue?: T[]); | ||
add(value: T): this; | ||
delete(value: T): boolean; | ||
clear(): this; | ||
} | ||
export declare class ObservableMap<K, V> extends Map<K, V> { | ||
didChange: Observable<Map<K, V>>; | ||
constructor(initialValue?: [K, V][]); | ||
set(key: K, value: V): this; | ||
delete(key: K): boolean; | ||
clear(): this; | ||
} |
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,65 @@ | ||
export { default as isRelative } from "is-relative"; | ||
/** | ||
* Join all arguments together and normalize the resulting path. | ||
* | ||
* @param paths - The paths to join | ||
*/ | ||
export declare function join(...paths: string[]): string; | ||
/** | ||
* Solve the relative path from `from` to `to`. Paths must be absolute. | ||
* | ||
* @param from - The absolute path to start from | ||
* @param to - The absolute path to solve to | ||
*/ | ||
export declare function relative(from: string, to: string): string; | ||
/** | ||
* Splits a path into an array of path segments. | ||
* | ||
* @param path - The path to split. | ||
*/ | ||
export declare function split(path: string): string[]; | ||
/** | ||
* Normalize a path, taking care of `..` and `.`, and removing redundant slashes. | ||
* Unlike Node's `path`, this removes any trailing slashes. | ||
* | ||
* @param path - The path to normalize. | ||
*/ | ||
export declare function normalize(path: string): string; | ||
/** | ||
* Returns `true` if `path` is inside `dir`. | ||
* | ||
* @param path - The path to check | ||
* @param dir - The directory to check if the path is inside of. | ||
*/ | ||
export declare function isPathInside(path: string, dir: string): boolean; | ||
/** | ||
* Get the depth of a path. | ||
* | ||
* @param path - The path to split. | ||
*/ | ||
export declare function depth(path: string): number; | ||
/** | ||
* Return the last fragment of a path. | ||
* | ||
* @param path - The path to get the basename of. | ||
*/ | ||
export declare function basename(path: string): string; | ||
/** | ||
* Returns the extension of a file path, which is the part of the path after the last `.`. | ||
* If the path has no extension, returns an empty string. | ||
* | ||
* @param path - The path to get the extension of. | ||
*/ | ||
export declare function extname(path: string): string; | ||
/** | ||
* Return the directory name of a path. | ||
* | ||
* @param path - The path to get the directory name of. | ||
*/ | ||
export declare function dirname(path: string): string; | ||
/** | ||
* Remove any trailing slashes from a path. | ||
* | ||
* @param path - The path to remove trailing slashes from. | ||
*/ | ||
export declare function removeTrailingSlashes(path: string): string; |
Oops, something went wrong.