npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

maze-blockly-wrapper

v0.7.6

Published

A Blockly-based maze game wrapper with editable maze generation and programming interface

Downloads

299

Readme

@maze/blockly-wrapper

A React-based Blockly wrapper for creating interactive maze programming games. This package provides a complete maze game environment where users can program a spider to navigate through mazes using visual programming blocks.

Features

  • Interactive Maze Game: Program a spider to navigate through mazes
  • Visual Programming: Uses Google Blockly for drag-and-drop programming
  • Editable Mazes: Create and customize mazes with an intuitive editor
  • Real-time Execution: Watch your code execute step-by-step
  • Responsive Design: Works on desktop and mobile devices
  • TypeScript Support: Full TypeScript definitions included

Installation

npm install maze-blockly-wrapper

Required Dependencies

This package requires the following peer dependencies:

npm install react react-dom blockly

⚠️ Important Setup

Before using any components, you must initialize Blockly to avoid the recentlyCreatedOwnerStacks error:

import React, { useEffect } from 'react';
import { MazeGame, initializeBlockly } from 'maze-blockly-wrapper';

function App() {
  useEffect(() => {
    // CRITICAL: Initialize Blockly before using any components
    initializeBlockly();
  }, []);

  const handleRunFinish = (result) => {
    console.log('Game finished!', result);
    // result contains: steps, reachedFinish, maxMovesExceeded, finalPosition, path, executionTime
  };

  return (
    <MazeGame
      isEditable={true}
      onRunFinish={handleRunFinish}
      maxMoves={100}
    />
  );
}

Quick Start

import React, { useEffect } from 'react';
import { MazeGame, initializeBlockly } from 'maze-blockly-wrapper';

function App() {
  useEffect(() => {
    // Initialize Blockly first
    initializeBlockly();
  }, []);

  return <MazeGame />;
}

Components

MazeGame

The main component that combines the maze, programming interface, and game logic.

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | isEditable | boolean | false | Enable maze editing mode | | configuration | MazeConfig | undefined | Initial maze configuration | | onChange | (config: MazeConfig) => void | undefined | Callback when maze configuration changes | | onRunFinish | (result: RunResult) => void | undefined | Callback when game execution finishes | | maxMoves | number | 50 | Maximum moves allowed | | showControls | boolean | true | Show game control buttons | | className | string | undefined | Additional CSS classes |

EditableMazeGrid

A standalone component for editing maze configurations.

import { EditableMazeGrid } from '@maze/blockly-wrapper';

<EditableMazeGrid
  config={mazeConfig}
  onConfigChange={handleConfigChange}
/>

MazeBlocklyContainer

The Blockly programming interface component.

import { MazeBlocklyContainer } from '@maze/blockly-wrapper';

<MazeBlocklyContainer
  config={blocklyConfig}
  onCodeChange={handleCodeChange}
  onExecuteCode={handleExecuteCode}
/>

Types

MazeConfig

interface MazeConfig {
  width: number;
  height: number;
  spiderStart: Position;
  finishPosition: Position;
  walls: Position[];
  estimatedSteps?: number;
}

RunResult

interface RunResult {
  steps: number;
  reachedFinish: boolean;
  maxMovesExceeded: boolean;
  finalPosition: Position;
  path: Position[];
  executionTime: number;
  error?: string;
}

Position

interface Position {
  x: number;
  y: number;
}

Usage Examples

Basic Game

import { MazeGame } from '@maze/blockly-wrapper';

<MazeGame />

Editable Maze with Configuration

import { MazeGame } from '@maze/blockly-wrapper';

const initialConfig = {
  width: 12,
  height: 10,
  spiderStart: { x: 1, y: 1 },
  finishPosition: { x: 10, y: 8 },
  walls: [
    { x: 3, y: 2 },
    { x: 4, y: 3 },
    { x: 7, y: 5 }
  ]
};

<MazeGame
  isEditable={true}
  configuration={initialConfig}
  onChange={(config) => console.log('Maze changed:', config)}
  onRunFinish={(result) => console.log('Game result:', result)}
  maxMoves={75}
/>

Custom Blockly Configuration

import { MazeBlocklyContainer } from '@maze/blockly-wrapper';

const customConfig = {
  allowedTypes: new Set(['maze_move_forward', 'maze_turn_left']),
  limits: { maze_move_forward: 10, maze_turn_left: 5 },
  toolbox: `<xml>...</xml>`,
  initialXml: `<xml>...</xml>`
};

<MazeBlocklyContainer
  config={customConfig}
  onCodeChange={(code) => console.log('Code:', code)}
  onExecuteCode={(commands) => console.log('Commands:', commands)}
/>

Development

Building the Package

# Build library for distribution
npm run build:lib

# Build types
npm run build:types

# Build both library and app
npm run build

Development Mode

npm run dev

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Troubleshooting

Error: "Cannot read properties of undefined (reading 'recentlyCreatedOwnerStacks')"

This error occurs when Blockly is not properly initialized. Make sure to:

  1. Call initializeBlockly() before using any components
  2. Install Blockly as a peer dependency: npm install blockly
  3. Import Blockly in your project if using custom configurations:
import 'blockly/core';
import 'blockly/blocks';
import 'blockly/javascript';

Multiple Blockly Instances

If you're using multiple Blockly instances in your app:

  1. Initialize Blockly only once at the app level
  2. Properly dispose of workspaces when components unmount
  3. Avoid reinitializing Blockly unnecessarily

Build Configuration

For bundlers like Webpack or Vite, ensure Blockly is properly externalized:

// webpack.config.js
module.exports = {
  externals: {
    'blockly': 'Blockly'
  }
};
// vite.config.ts
export default defineConfig({
  build: {
    rollupOptions: {
      external: ['blockly']
    }
  }
});

API Reference

Blockly Setup Utilities

  • initializeBlockly() - Initialize Blockly for package usage
  • isBlocklyReady() - Check if Blockly is ready
  • getBlockly() - Get the initialized Blockly instance
  • getJavaScriptGenerator() - Get the JavaScript generator
  • resetBlocklyInitialization() - Reset initialization state (for testing)

Support

For issues and questions, please use the GitLab issue tracker at: https://gitlab.com/smartbooksdev/blocklysbwrapper