Skip to content

Turn the example into a reusable component package - #3

Merged
remcoder merged 3 commits into
mainfrom
feature/reusable-component
Oct 4, 2026
Merged

remcoder merged 3 commits into
mainfrom
feature/reusable-component

Conversation

@remcoder

@remcoder remcoder commented Oct 4, 2026

Copy link
Copy Markdown
Member

Turns the example into a reusable component package that can later be published to npm. The demo stays in this repo, imports the component from source and still deploys to Firebase.

What changes

  • Component: every gcode-preview option is a prop, typed from the core. Options with a live setter update the preview in place (only when they change); the rest are read once at mount. A typecheck fails if the core adds an option the component doesn't list.
  • Loading: src (fetched and streamed) or gcode (text, wins over src). A new load aborts the previous one; start/end layer are re-applied after each load.
  • Callbacks: ready, load and error. Without an error handler, errors go to console.error.
  • Instance access to the underlying GCodePreview.
  • Canvas: a single <canvas> with attributes passed through; size it with CSS. A ResizeObserver resizes it, and unmount cleans everything up. No hardcoded size, colors, build volume or camera.
  • Packaging: the library builds to dist/ with typings. gcode-preview and the framework are peer dependencies. Version 0.1.0, still "private": true until we publish. publint is added as lint:package.
  • Demo: has its own build script, and the Firebase workflows call it.
  • README: rewritten around the package.

Checks

Typecheck, unit tests (core mocked), library build, publint and npm pack --dry-run all pass. A packed tarball was installed in a separate Vite + TypeScript app, which typechecked and built. The demo was checked in a browser.

Known core issues (gcode-preview 3.0.0-alpha.6)

  • buildVolume's type requires smallGrid.
  • The core's .d.ts needs @types/three in TypeScript consumers.

Wrap gcode-preview in a component with typed option props (live or
mount-only), src/gcode loading, ready/load/error callbacks and instance
access. The library builds to dist/ for npm (still private: true); the
demo imports it from source and gets its own build script for Firebase.
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit bc710d0):

https://gcode-preview-react--pr3-feature-reusable-com-117xfxb2.web.app

(expires Sun, 11 Oct 2026 20:24:51 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: c787db3520fae43f256c13f53bbe62214d2df228

Drops the React logos, web manifest, robots.txt and the matching head tags,
trims CRA entries from .gitignore, gives the page a real title, and makes the
preview droppable with a hint, like the Svelte and Vue demos.
TypeScript stays on 6.0 (typescript-eslint supports <6.1) and ESLint on 9
(eslint-plugin-react supports up to ^9.7). @types/three stays on 0.185 to match
the three range gcode-preview accepts.
@remcoder
remcoder merged commit 9b3fdb6 into main Oct 4, 2026
2 checks passed
@remcoder
remcoder deleted the feature/reusable-component branch October 4, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant