Skip to content

refactor(core): standardize Widget API with EditorWidget base class#147

Open
bunbun79 wants to merge 1 commit into
floatboatai:mainfrom
bunbun79:feat/core/widget-api-standardization
Open

refactor(core): standardize Widget API with EditorWidget base class#147
bunbun79 wants to merge 1 commit into
floatboatai:mainfrom
bunbun79:feat/core/widget-api-standardization

Conversation

@bunbun79

Copy link
Copy Markdown

Summary

Unify the two separate widget systems under a shared EditorWidget base class. Replace the bare tableEditingCount global with isWidgetEditing(). Add lifecycle hooks and WidgetContext.

Motivation

Before this PR, Nexus had two independent widget systems with zero shared infrastructure. The bare tableEditingCount global was untestable. Plugin widgets had no lifecycle hooks or lock management.

Changes

File Change
packages/core/src/widget-base.ts NewEditorWidget abstract base class
packages/core/src/widget-state.ts NewisWidgetEditing() / lock management
packages/core/src/widget-context.ts NewWidgetContext interface
packages/core/src/live-preview-table.ts EditableTableWidget extends EditorWidget
packages/core/src/widget-extension.ts NexusWidget extends EditorWidget + lifecycle
packages/core/src/types.ts Added WidgetLifecycleHooks, deprecated destroy
packages/core/test/live-preview.test.ts 6 new table clipboard/selection tests

Architecture

Before: WidgetType (bare CM6)       After: EditorWidget (locks + lifecycle)
        ├─ EditableTableWidget             ├─ EditableTableWidget
        └─ NexusWidget                     └─ NexusWidget
        tableEditingCount (global)         isWidgetEditing()

Testing

  • pnpm test521 tests, 34 files, 0 failures
  • TypeScript — zero errors
  • OpenSpec proposal at openspec/changes/add-widget-api-standardization/

- Add EditorWidget abstract base class (extends WidgetType) with:
  editing lock management, lifecycle hooks, WidgetContext, estimatedHeight contract
- Add WidgetInteractionState / isWidgetEditing() to replace bare tableEditingCount
- Add WidgetContext interface for safe CM6 view access from widgets
- Migrate EditableTableWidget to extend EditorWidget
- Migrate NexusWidget to extend EditorWidget with lifecycle hook support
- Add WidgetLifecycleHooks to WidgetDefinition (backward-compatible)
- Deprecate WidgetDefinition.destroy in favor of lifecycle.willDestroy
- Add 6 table clipboard/native-selection tests
- Add OpenSpec proposal for widget-api standardization

Closes: P1 roadmap item 'Widget API standardization'
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants