Skip to content

Conversation

@ChasLui
Copy link
Contributor

@ChasLui ChasLui commented Aug 24, 2025

Linked Issue

Motivation

Enable a first-class Web Component for simpler, framework-agnostic integration and style isolation via Shadow DOM, matching the proposed usage in the issue.

Summary of Changes

  • Add custom element <overtype-editor> with Shadow DOM
  • New build artifacts:
    • dist/overtype-webcomponent.js
    • dist/overtype-webcomponent.esm.js
    • dist/overtype-webcomponent.min.js
  • Source, demo, and tests:
    • src/overtype-webcomponent.js
    • examples/webcomponent.html
    • test/webcomponent.test.js
  • Minimal docs/examples updates to align with existing demo style

Usage

  • CDN:
<script src="https://unpkg.com/overtype/dist/overtype-webcomponent.min.js"></script>

<overtype-editor theme="solar" value="# hello"></overtype-editor>
  • ESM:
<script type="module">
  import 'overtype/dist/overtype-webcomponent.esm.js';
</script>

<overtype-editor theme="dracula" value="## Getting Started"></overtype-editor>

Attributes, Events, Methods

  • Attributes:
    • value: initial Markdown
    • theme: theme name (reuses existing themes)
    • preview: enable preview mode (optional)
    • Other editor options mapped to attributes for compatibility
  • Events:
    • change: emits { detail: { value } } on content updates
    • ready: emitted when initialized
  • Methods (via element instance):
    • getValue(), setValue(value), focus(), etc., aligned with existing API

Compatibility

  • Backward compatible: does not affect current direct Overtype usage
  • Styles: Shadow DOM prevents host page leakage; themes still driven by themes.js
  • Size: additional optional bundles; does not bloat existing bundles

Testing and Validation

  • test/webcomponent.test.js covers render, attribute sync, and event emission
  • Manual verification via examples/webcomponent.html (initial value, theme switching, change propagation)

Documentation

  • Added a minimal runnable example; can extend README with a Web Component section in this PR if desired

Follow-ups

  • Additional events (focus, blur, selectionChange)
  • More reactive attribute updates via attributeChangedCallback
  • Expose CSS custom properties for fine-grained theming

Checklist

  • Introduce <overtype-editor> with Shadow DOM
  • Ship CJS/ESM/UMD-like webcomponent builds
  • Add example and baseline tests
  • Maintain parity with existing API and theme system
  • Link and close issue #30 (reference)

Summary by cubic

Adds a first-class Web Component with Shadow DOM for clean, framework-agnostic embedding while keeping the existing OverType API intact. Implements the behavior requested in issue #30, including attribute-based config and event hooks.

  • New Features

    • Introduced custom element with Shadow DOM isolation.
    • Attribute API: value, theme, preview; plus mapped editor options.
    • Events: change (value payload), ready. Methods: getValue, setValue, focus.
    • New builds: dist/overtype-webcomponent.{js,min.js,esm.js} and package export at overtype/webcomponent.
    • Added example page and tests covering render, attribute sync, and events.
    • Docs and site updated; existing OverType usage remains unchanged.
  • Bug Fixes

    • Link tooltip: guard CSS.supports to prevent errors in non-browser/test environments.
    • Toolbar: input event is now composed to work inside Shadow DOM.
    • Parser cleanup and version bump to 1.2.3.

@panphora panphora merged commit 9e9ff70 into panphora:main Nov 3, 2025
panphora added a commit that referenced this pull request Nov 3, 2025
Changes made to prepare PR #40 for merge:

- Remove .prettierrc file (unrelated to web components, belongs in Issue #59)
- Move web component documentation to dedicated docs/WEB-COMPONENT.md file
- Update README.md with concise web component section linking to full docs
- Remove dist/overtype.d.ts (should not be in version control)

This keeps the PR focused on the web component feature and improves
documentation organization. Web component implementation and tests remain
unchanged and fully functional (100% test pass rate).
panphora added a commit that referenced this pull request Nov 3, 2025
Successfully merged web component feature from ChasLui with clean integration:

Features added:
- Native <overtype-editor> custom element with Shadow DOM
- 15 reactive HTML attributes for declarative configuration
- Complete JavaScript API (getValue, setValue, getHTML, etc.)
- 4 custom events (change, keydown, ready, error)
- Framework integration support (React, Vue, Angular)
- Separate build artifacts (overtype-webcomponent.js/min/esm)

Documentation:
- Added concise Web Component section to README
- Created comprehensive docs/WEB-COMPONENT.md
- Added webcomponent.html example

Testing:
- Added webcomponent.test.js with 100% test coverage
- All 178 tests passing (including TypeScript definitions)
- Build sizes: Web Component 93KB minified

This merge used a clean extraction strategy to avoid conflicts:
1. Extracted ChasLui changes to tmp/ files
2. Reset conflicted files to main branch state
3. Selectively applied only necessary changes
4. Rebuilt all dist files from clean source
@panphora
Copy link
Owner

panphora commented Nov 6, 2025

Thank you @ChasLui for this excellent web component implementation! This is in v2.0.

Applied with minor improvements:

  • Moved docs to docs/WEB-COMPONENT.md
  • Fixed TypeScript integration
  • All 178 tests passing including web component tests

The Shadow DOM encapsulation and declarative API are great additions. Merged!

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.

wrap in web component

2 participants