Skip to content

Actions: Add actions API#27

Merged
andylovescode merged 5 commits intomainfrom
andytk2010/vor-29-add-actions-api
Aug 24, 2025
Merged

Actions: Add actions API#27
andylovescode merged 5 commits intomainfrom
andytk2010/vor-29-add-actions-api

Conversation

@andylovescode
Copy link
Copy Markdown
Collaborator

No description provided.

@andylovescode andylovescode requested a review from Copilot August 24, 2025 06:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive actions API to VortexJS that enables keyboard shortcuts and action management across the framework. The implementation provides a context-based action system where components can register actions with keyboard shortcuts that are automatically handled.

Key changes:

  • New actions API with context provider and hooks for action registration
  • DOM keyboard action handler that listens for key combinations and triggers registered actions
  • Configuration updates to support the new JSX import source and path mapping

Reviewed Changes

Copilot reviewed 13 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/vortex-core/src/actions/index.tsx Core actions API with types, context, and hooks
packages/vortex-dom/src/actions/DOMActions.tsx DOM keyboard event handler for action shortcuts
packages/vortex-core/src/std/abort.ts Utility hook for abort signal management
packages/vortex-core/src/render/index.tsx Integration of ActionProvider into render pipeline
packages/vortex-dom/src/index.ts Export of actions from DOM package
packages/vortex-core/package.json Build configuration update for actions module
packages/vortex-*/tsconfig.json TypeScript configuration updates
packages/example-wormhole/src/features/home/index.tsx Example usage of the actions API

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +86 to +89
const shortcut = Array.from(keys).sort().map(x => getCodeToKey(x));
keys.delete(ev.code);

let sortedShortcut = sortKeys(shortcut);
Copy link

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shortcut array is being sorted before mapping to keys, but then sorted again with sortKeys(). This creates inconsistent ordering since the first sort is alphabetical while sortKeys() uses a custom order. The mapping should happen before any sorting.

Suggested change
const shortcut = Array.from(keys).sort().map(x => getCodeToKey(x));
keys.delete(ev.code);
let sortedShortcut = sortKeys(shortcut);
const shortcut = sortKeys(Array.from(keys).map(x => getCodeToKey(x)));
keys.delete(ev.code);
let sortedShortcut = shortcut;

Copilot uses AI. Check for mistakes.
Comment on lines +93 to +94
const action = getImmediateValue(actions).find(x =>
x.shortcut && sortKeys(x.shortcut.split("+")).join("+") === shortcutString);
Copy link

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sortKeys() function is called on every action's shortcut during each keyup event. Consider pre-processing and storing normalized shortcuts when actions are registered to avoid repeated computation.

Suggested change
const action = getImmediateValue(actions).find(x =>
x.shortcut && sortKeys(x.shortcut.split("+")).join("+") === shortcutString);
const action = actionsWithNormalizedShortcuts.find(x =>
x.normalizedShortcut === shortcutString);

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +85
window.addEventListener("keydown", (ev) => {
keys.add(ev.code);
}, { signal });

window.addEventListener("keyup", (ev) => {
Copy link

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keyboard handler doesn't respect user preferences for reduced motion or accessibility settings. Consider checking if the user has disabled keyboard shortcuts or if the current element should receive keyboard events.

Suggested change
window.addEventListener("keydown", (ev) => {
keys.add(ev.code);
}, { signal });
window.addEventListener("keyup", (ev) => {
window.addEventListener("keydown", (ev) => {
// Check if user has disabled keyboard shortcuts
const shortcutsEnabled = !window.localStorage.getItem("disableKeyboardShortcuts");
// Check if the focused element should receive keyboard events
const active = document.activeElement;
const isEditable = active && (
active.tagName === "INPUT" ||
active.tagName === "TEXTAREA" ||
(active as HTMLElement).isContentEditable
);
if (!shortcutsEnabled || isEditable) return;
keys.add(ev.code);
}, { signal });
window.addEventListener("keyup", (ev) => {
// Check if user has disabled keyboard shortcuts
const shortcutsEnabled = !window.localStorage.getItem("disableKeyboardShortcuts");
// Check if the focused element should receive keyboard events
const active = document.activeElement;
const isEditable = active && (
active.tagName === "INPUT" ||
active.tagName === "TEXTAREA" ||
(active as HTMLElement).isContentEditable
);
if (!shortcutsEnabled || isEditable) return;

Copilot uses AI. Check for mistakes.
@andylovescode andylovescode merged commit ff7420a into main Aug 24, 2025
1 check passed
@andylovescode andylovescode deleted the andytk2010/vor-29-add-actions-api branch August 24, 2025 06:29
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