1.0.28 • Published 5 months ago

@fullstackcraftllc/codevideo-virtual-file-explorer v1.0.28

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@fullstackcraft/codevideo-virtual-file-explorer

NPM Version

codevideo-virtual-file-explorer is a TypeScript class that simulates an IDE file explorer with the ability to create, delete, and modify folder and file structures. This lightweight and versatile library is ideal for building educational tools, code playgrounds, and interactive coding environments within web applications.

This library heavily relies on the types from codevideo-types

Example Usage

import { VirtualFileExplorer } from '@fullstackcraftllc/codevideo-virtual-file-explorer';
import { advancedCommandSeparator } from '@fullstackcraftllc/codevideo-types';

// Initialize a VirtualFileExplorer instance
const virtualFileExplorer = new VirtualFileExplorer();

// Apply file explorer actions
virtualFileExplorer.applyActions([
  // create a test.js file
  { name: 'create-file', value: 'test.js' },
  
  // creates a src folder
  { name: 'create-folder', value: 'src' },
  
  // create an index.js file in the src folder
  { name: 'create-file', value: 'src/index.js' },
  
  // rename test.js to main.js
  { name: 'rename-file', value: `test.js${advancedCommandSeparator}main.js` },
  
  // copy index.js
  { name: 'copy-file', value: `src/index.js${advancedCommandSeparator}src/index.backup.js` },
  
  // move main.js into src
  { name: 'move-file', value: `main.js${advancedCommandSeparator}src/main.js` },
  
  // create components folder
  { name: 'create-folder', value: 'src/components' },
  
  // copy components folder
  { name: 'copy-folder', value: `src/components${advancedCommandSeparator}src/shared` },
  
  // move shared folder to root
  { name: 'move-folder', value: `src/shared${advancedCommandSeparator}shared` },
  
  // toggle src folder collapsed state
  { name: 'toggle-folder', value: 'src' },
  
  // delete backup file
  { name: 'delete-file', value: 'src/index.backup.js' },
  
  // delete shared folder
  { name: 'delete-folder', value: 'shared' },
]);

// Get the current state of the file explorer
const fileStructure = virtualFileExplorer.getCurrentFileStructure();
const fileTree = virtualFileExplorer.getCurrentFileTree();
const actionsApplied = virtualFileExplorer.getActionsApplied();

console.log('Current file tree:');
console.log(fileTree);
console.log('Actions applied:');
console.log(actionsApplied);

Available Actions

  • file-explorer-create-file: Create a new file
  • file-explorer-open-file: Open a file (UI handler)
  • file-explorer-rename-file: Rename a file using format "oldpath_newpath"
  • file-explorer-delete-file: Delete a file
  • file-explorer-move-file: Move a file using format "oldpath_newpath"
  • file-explorer-copy-file: Copy a file using format "sourcepath_destpath"
  • file-explorer-create-folder: Create a new folder
  • file-explorer-rename-folder: Rename a folder using format "oldpath_newpath"
  • file-explorer-delete-folder: Delete a folder
  • file-explorer-toggle-folder: Toggle folder's collapsed state
  • file-explorer-move-folder: Move a folder using format "oldpath_newpath"
  • file-explorer-copy-folder: Copy a folder using format "sourcepath_destpath"

Where "_" is a separator string used for advanced commands. The separator string can be imported using the advancedCommandSeparator exported from @fullstackcraftllc/codevideo-types.

Available Methods

applyAction(action: FileExplorerAction): void

Apply a single action to the file structure.

applyActions(actions: FileExplorerAction[]): void

Apply a series of actions to the file structure.

getCurrentFileStructure(): IFileStructure

Get the current file structure as an object.

getCurrentFileTree(): string

Get a string representation of the current file tree.

getActionsApplied(): FileExplorerAction[]

Get the list of actions that were applied.

Why?

This library is part of the CodeVideo ecosystem, working alongside other tools to create a declarative way to build, edit, and generate step-by-step educational video software courses.

The VirtualFileExplorer provides a programmatic way to simulate file explorer interactions, making it perfect for:

  • Recording and replaying file operations
  • Creating educational content
  • Testing file-system related UI components
  • Simulating IDE-like environments in the browser

See more at codevideo.io

1.0.28

5 months ago

1.0.27

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.20

7 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago