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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-forge-viewer-eu

v0.0.1

Published

A component wrapper to quickly add the Forge model viewer in your React apps. Supports EU region.

Downloads

21

Readme

React Forge Viewer Component

Motivation

Forked from https://github.com/outer-labs/react-forge-viewer

Autodesk provides a web-based viewer that can load and display a wide range of 2D and 3D models (Revit, Navisworks, AutoCAD, etc.).

The ForgeViewer component in this package makes it easy to include and interact with the viewer in your React apps by wrapping the standard Autodesk libraries in a React-friendly interface.

Note that this component is not authored by Autodesk.

Supported React Versions

This package requires React 16.4.1 and higher.

Installation

npm i react-forge-viewer --save

Example

import React, { Component } from 'react';
import ForgeViewer from 'react-forge-viewer';
import './App.css';

class App extends Component {

  constructor(props){
    super(props);

    this.state = {
      view:null
    }
  }

  handleViewerError(error){
    console.log('Error loading viewer.');
  }

  /* after the viewer loads a document, we need to select which viewable to
  display in our component */
  handleDocumentLoaded(doc, viewables){
    if (viewables.length === 0) {
      console.error('Document contains no viewables.');
    }
    else{
      //Select the first viewable in the list to use in our viewer component
      this.setState({view:viewables[0]});
    }
  }

  handleDocumentError(viewer, error){
    console.log('Error loading a document');
  }

  handleModelLoaded(viewer, model){
    console.log('Loaded model:', model);
  }

  handleModelError(viewer, error){
    console.log('Error loading the model.');
  }

  getForgeToken(){
    /* Normally, this would call an endpoint on your server to generate a public
    access token (using your client id and sercret). Doing so should yield a
    response that looks something like the following...
    */
    return {
      access_token:<<INSERT_YOUR_FORGE_ACCESS_TOKEN>>,
      expires_in: <<INSERT_TOKEN_EXPIRATION>>,
      token_type: "Bearer"
    };
  }

  /* Once the viewer has initialized, it will ask us for a forge token so it can
  access the specified document. */
  handleTokenRequested(onAccessToken){
    console.log('Token requested by the viewer.');
    if(onAccessToken){
      let token = this.getForgeToken();
      if(token)
        onAccessToken(
          token.access_token, token.expires_in);
    }
  }

  render() {
    return (
      <div className="App">
        <ForgeViewer
          version="6.0"
          urn=<<INSERT_YOUR_FORGE_DOCUMENT_URN>>
          region=<<eu_or_us>>
          view={this.state.view}
          headless={false}
          onViewerError={this.handleViewerError.bind(this)}
          onTokenRequest={this.handleTokenRequested.bind(this)}
          onDocumentLoad={this.handleDocumentLoaded.bind(this)}
          onDocumentError={this.handleDocumentError.bind(this)}
          onModelLoad={this.handleModelLoaded.bind(this)}
          onModelError={this.handleModelError.bind(this)}
        />
      </div>
    );
  }
}

export default App;

Component Parameters

  • urn: (Required) A string or array of string values for the URN(s) of the translated models you wish to load
  • view: (Required) An object or array of view objects to display in the viewer
  • headless: A boolean to display in the viewer in headless mode or not (defaults false)
  • proxy: A string that is the base url to proxy our requests through a proxy. This is useful when you don't want to pass an access token to the client. For more info...
  • onTokenRequest: (Required) Callback function triggered when the viewer requests a token to access data stored on Forge. Must be a public / viewable scoped token.
  • version: The version of the viewer you want to load. Latest tested is 6.0.
  • onViewerError: Callback function triggered when the viewer encounters an error
  • onDocumentLoad: Callback function triggered when the viewer successfully loads one of the documents (urns) provided
  • onDocumentError: Callback function triggered when the viewer fails to load one of the documents(urns) provided
  • onModelLoad: Callback function triggered when the viewer successfully loads one of the models(views) provided
  • onModelError: Callback function triggered when the viewer fails to load one of the models(views) provided

Styling the Component

The ForgeViewer component will need to be assigned width and height properties, either directly, or via layout manager (like flex layout).

.App {
  width: 100%;
  height: 100%;
  position: fixed;
}

.ForgeViewer {
  width: 500px;
  height: 500px;
}

Run a Development Build of this Component

Since this is a component, it is convenient to test it locally in an app before building and publishing a modified version to npm. Below are the steps to set this up in a development environment:

Clone this repo to your local dev environment

cd ~/Documents/code
git clone https://github.com/outer-labs/react-forge-viewer.git

Install dependencies, and establish a link to our package in npm

npm i
npm run build
sudo npm link

Install and use create-react-app to set up a boilerplate app for testing the component (targeting node version 6.10)

npm i -g create-react-app
cd ~/Documents/code
mkdir my-test-app
cd my-test-app
nvm use 6.10
create-react-app .
echo 'v6.10' > .nvmrc

Use the component link with the test app we just created

sudo npm link react-forge-viewer

Add the component to your App.js then run npm start (for both my-test-app and react-forge-viewer in separate terminal windows/tabs).

License

MIT

Made by Outer Labs, Inc.