Skip to content

Commit

Permalink
chore(release): 1.2.0
Browse files Browse the repository at this point in the history
# [1.2.0](v1.1.3...v1.2.0) (2022-04-19)

### Features

* add file tree snapshot restoration ([#12](#12)) ([ee370e9](ee370e9))
  • Loading branch information
semantic-release-bot committed Apr 19, 2022
1 parent ee370e9 commit 9e36720
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 356 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
## [1.1.3](https://github.com/jaredLunde/exploration/compare/v1.1.2...v1.1.3) (2022-04-18)
# [1.2.0](https://github.com/jaredLunde/exploration/compare/v1.1.3...v1.2.0) (2022-04-19)

### Features

- add file tree snapshot restoration ([#12](https://github.com/jaredLunde/exploration/issues/12)) ([ee370e9](https://github.com/jaredLunde/exploration/commit/ee370e900fe13ab4813831b8a53d87e60deba099))

## [1.1.3](https://github.com/jaredLunde/exploration/compare/v1.1.2...v1.1.3) (2022-04-18)

### Bug Fixes

* remove subpath from package.json ([#11](https://github.com/jaredLunde/exploration/issues/11)) ([dd87773](https://github.com/jaredLunde/exploration/commit/dd87773b3c0f7c85cb732f8a91bbbd7fc96d0366))
- remove subpath from package.json ([#11](https://github.com/jaredLunde/exploration/issues/11)) ([dd87773](https://github.com/jaredLunde/exploration/commit/dd87773b3c0f7c85cb732f8a91bbbd7fc96d0366))

## [1.1.2](https://github.com/jaredLunde/exploration/compare/v1.1.1...v1.1.2) (2022-04-13)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exploration",
"version": "1.1.3",
"version": "1.2.0",
"description": "",
"license": "MIT",
"author": "Jared Lunde <[email protected]> (https://jaredlunde.com/)",
Expand Down
320 changes: 176 additions & 144 deletions types/file-tree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Branch } from "./tree/branch";
import { Leaf } from "./tree/leaf";
import type { GetNodes as GetNodesBase } from "./tree/tree";
import { Tree } from "./tree/tree";
import type { FileTreeSnapshot } from "./types";
/**
* Create a file tree that can be used with the React API.
*
Expand All @@ -10,66 +11,80 @@ import { Tree } from "./tree/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 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
*/
/**
* The root directory of the file tree
*/
root: Dir<Meta>;
protected treeNodeMap: Map<number, File<Meta> | Dir<Meta>>;
nodesById: FileTreeNode<Meta>[];
protected loadingBranches: Map<Dir<Meta>, Promise<void>>;
/**
* 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>;
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> & {
});
/**
* 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.
*/
Expand All @@ -84,78 +99,89 @@ export declare class FileTree<Meta = {}> extends Tree<FileTreeData<Meta>> {
* 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;
}
) => 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;
/**
* 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;
/**
* 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;
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>;
export declare function isFile<T>(
treeNode: FileTreeNode<T>
): treeNode is File<T>;
/**
* Returns `true` if the given node is a directory
*
Expand All @@ -164,40 +190,46 @@ export declare function isFile<T>(treeNode: FileTreeNode<T>): treeNode is File<T
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;
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>;
/**
* 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>[];
/**
* 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">;
/**
* A function that compares two nodes for sorting.
*/
comparator?: FileTree["comparator"];
/**
* The root node data
*/
root?: Omit<FileTreeData<Meta>, "type">;
/**
* Restore the tree from a snapshot
*/
restoreFromSnapshot?: FileTreeSnapshot;
};
Loading

0 comments on commit 9e36720

Please sign in to comment.